-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Cannot read properties of null (reading 'useContext') #10455
Comments
I've encountered this several times myself on the "first" load. Might be related to how the server hands off the initial context value. 👍 |
@tigerabrodi if you can reproduce it that would be helpful |
@tigerabrodi I'm facing the same issue. I believe I've been able to replicate the issue cc @brookslybrand This appears to happen after deployments.
Collapsed section contains the manifest for the old app version `32e10548`
Collapsed section contains the manifest for the new app version `e20cca2b`
|
Hey @brophdawg11, I'm guessing this could be an unanticipated side effect of #10447. Per @thomaswelton, this RR7 issue sounds For now we rolled back to 2.15.2 and things seem stable again. |
Bit confusing as there are issues across both remix and react router repos. But I should have mentioned I'm running react-router 7.1.3 |
I encountered the same issue and was able to reproduce it in the exact same way. Therefore, I temporarily set v3_lazyRouteDiscovery to false and deployed it to work around the issue. My Remix version is 2.15.2. So, it seems that the same issue exists in version 2.15.2 as well. |
using react-router v7.1.4 and it happens to me as well on production after deployment on tabs that holds the "old" version. |
@yoni-noma There is a function here https://github.com/remix-run/react-router/blob/3b45394fc7bd7c4aa58b802fda2558093217baca/packages/react-router/lib/dom/ssr/fog-of-war.ts#L29 called By doing this I can see my routerManifest on first page load has all of my app routes and the app no longer makes network requests to fetch the manifest. As a result I think this will stop the issue from happening completely. If you are using yarn > 2 you can patch this with https://yarnpkg.com/cli/patch |
I just want to confirm that this is caused by deployments and has affected our application using both Remix v2 with future flags enabled and React Router 7. We can reliably recreate this issue using the steps listed above and see a surge of exceptions on every deployment. We migrated our application to RR 7 and @brookslybrand It's unfortunately difficult to create a repro for this, but it feels like a serious regression from Remix v2. Is this expected behavior from the framework that we should be working around as application developers? Would an issue opened in the RR repo be helpful? |
Interesting, it basically tells it to act SPA, but it means that all of the js from the manifest are downloaded like an SPA, or that in your deployment architecture you never remove old files? |
@yoni-noma so I think this change is the equivalent of turning off the old 'future.v3_lazyRouteDiscovery' feature flag. So now on first page load the manifest variable on the window contains the manifest for all of your routes. And yes. We serve all static assets from a CDN, and old files are always available. We've now deployed this to production and will be monitoring. |
Opened a new discussion topic for possible solutions to this. I started seeing this issue crop up a few months ago but I didn't make the connection to React context and how it relates to the changed module graph until seeing this thread. |
Reproduction
Unfortunately, I can't reproduce it but can see it affecting users in production based on Sentry's reports. The first instances of the error perfectly match the day we enabled the following feature flags
unstable_optimizeDeps
v3_fetcherPersist
v3_throwAbortReason
v3_relativeSplatPath
v3_lazyRouteDiscovery
v3_routeConfig
System Info
Used Package Manager
npm
Expected Behavior
It should not throw
Actual Behavior
Without any obvious reasons, from time to time our application crashes with the error
Cannot read properties of null (reading 'useContext')
.As you can see from the screenshot below, the issue is triggered by Remix - in this specific case by
useParams
but I've seen triggered byuseNavigation
,useLoaderData
, etc. It also doesn't seem to be related to any specific route as we are seeing it happening a bit everywhere in the app.The text was updated successfully, but these errors were encountered: