Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: useLanguagePicker warning and fallback #12208

Merged
merged 2 commits into from
Mar 26, 2024
Merged

Conversation

wackerow
Copy link
Member

Description

  • Update useLanguagePicker.tsx to remove error throwing when a source or target locale display name is not found
  • Adds console.warn instead, and adds an empty string fallback to ensure values are never undefined

Related Issue

Copy link

netlify bot commented Feb 16, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit e5857aa
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/6602092692c3eb000748a261
😎 Deploy Preview https://deploy-preview-12208--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 111 to 113
if (progressData.length === 0) {
console.warn("Missing translation progress data; check GitHub action")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this one again, I think we can probably keep this error. It should never throw as long as there is translation progress data available... if not, we should let the build break. cc: @pettinarip Curious your thoughts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've to disagree on that. This condition is inside a useEffect. It will never be checked at build time/server side. If it is ever checked, then it will be on client side, creating bad ux since it will make the app crash (unless we are catching that error and failing gracefully).

However, I hear you, it would be nice to have that type of check at build time.

And the change to use console.warn is ok I guess but its not doing anything. Shouldn't we return something else here? given that in the next line we are accessing it progressData[0].words.total.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay yeah, that makes sense, thanks

Shouldn't we return something else here? given that in the next line we are accessing it progressData[0].words.total.

I think we should... I can update this to return early in this case, and pass everything but the approvalProgress and wordsApproved. We can also use localeOption (Lang type) as the fallback for the source or target names... this means a language that failed this for whatever reason would just show the language code instead of an empty string.

Will push a patch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes more sense 👍🏼

Comment on lines 127 to 128
sourceName: sourceName ?? "",
targetName: targetName ?? "",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip Seeing your comment here... I went with this approach to avoid using mutable variables, sticking with const... lemme know if you disagree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should fallback to default locale or something else. Not sure if "' isn't going to break something else in the chain tbh. If not, it ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't break anything, but it would just render without a name... I switched this to fallback to its language code.

@wackerow wackerow changed the title refactor: Change throw to console warn; add fallback refactor: useLanguagePicker warning and fallback Feb 18, 2024
@corwintines corwintines self-assigned this Feb 26, 2024
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wackerow left some questions. Maybe there are potential scenarios we are not considering.

Comment on lines 111 to 113
if (progressData.length === 0) {
console.warn("Missing translation progress data; check GitHub action")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've to disagree on that. This condition is inside a useEffect. It will never be checked at build time/server side. If it is ever checked, then it will be on client side, creating bad ux since it will make the app crash (unless we are catching that error and failing gracefully).

However, I hear you, it would be nice to have that type of check at build time.

And the change to use console.warn is ok I guess but its not doing anything. Shouldn't we return something else here? given that in the next line we are accessing it progressData[0].words.total.

Comment on lines 127 to 128
sourceName: sourceName ?? "",
targetName: targetName ?? "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should fallback to default locale or something else. Not sure if "' isn't going to break something else in the chain tbh. If not, it ok.

use localeOption (lang code) fallback for source or target names instead of empty string
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ!

@pettinarip pettinarip merged commit ca8edb9 into dev Mar 26, 2024
10 checks passed
@pettinarip pettinarip deleted the error-handling branch March 26, 2024 12:36
This was referenced Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants