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

Log when the context does not exist instead of throwing errors #193

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

strmer15
Copy link

We were switching from react-helmet to react-helmet-async, but our production application threw errors at runtime (effectively shutting our website down) because of a misplaced <Helmet> tag outside of the <HelmetProvider>. This caused react-helmet-async to throw the error Cannot read properties of undefined (reading 'add').

While that's an obvious problem that can be addressed separately, it would help users who are switching to check for a missing context beforehand and not attempt to reference objects that are possibly undefined. This change checks to see if helmetInstances is truthy and, if not, logs a trace to the console and returns immediately. This way, users can be aware of their code not behaving correctly while still maintaining a running website.

@strmer15
Copy link
Author

@staylor Could you review this and let me know if it can make into the next release? Thanks!

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.

1 participant