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

document.body can be null when setLocale is first called #4178

Merged
merged 2 commits into from
Jun 3, 2021

Conversation

rawnsley
Copy link
Contributor

A common, but non-deterministic, console error is being thrown in setLocale because document.body can be null.

Screenshot 2021-04-22 at 09 31 30

It should be safe to skip raising the event with ?. in this situation because at best it was throwing an exception before.

A common pattern elsewhere in the codebase is to hang these events off window (which is guaranteed to be non-null) rather than document.body, and that would appear to be preferable in this case as well, but there may be something special about events on the document.body that I'm missing.

@netpro2k
Copy link
Contributor

netpro2k commented May 6, 2021

Hmm a quick check of how we are using locale-updated seems like its not particularly important where the event is coming from. I think your suggestion to use window would work, and I would prefer that over silently failing which might happen with how the PR is currently implemented.

@rawnsley
Copy link
Contributor Author

rawnsley commented May 6, 2021

Reimplemented as suggested by @netpro2k

@netpro2k netpro2k merged commit e59563b into Hubs-Foundation:master Jun 3, 2021
@netpro2k
Copy link
Contributor

netpro2k commented Jun 3, 2021

Merged. Thanks for making these additional changes!

@rawnsley rawnsley deleted the i18n-null-protection branch September 2, 2021 07:38
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.

2 participants