You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot read properties of null (reading 'useContext') #10455
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
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 by useNavigation, 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.
Reacted by Tiger Abrodi, Thomas Welton, Cullen Jett, Aaron Adams, Daniel Suchan, Joshua Draper, Marc de Jong, Jack Hanford, Yashu Mittal, candidia and 13 more
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
So I don't think it's related to #10447 as that was released in a later version.
using react-router v7.1.4 and it happens to me as well on production after deployment on tabs that holds the "old" version.
for now i cant rollback to v2, ive added a logic on errorBoundary that checks for the current build version and just before presenting the crash error to the user if there is a newer version im refreshing.. better ux but i dont like it, hoping to find a better solution 🙏
Reacted by Tomer Ziv, Daniel Suchan, Jack Hanford, Michał Kuklis, Chun Shawn, Parsa and Benjamin Bourgeais
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.
@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.
Visit the website on the current deployed version and leave this tab open.
Deploy a new version of the website. In my new version the module for my root component has changed.
Once the new version has fully deployed go back to the website which is still running the old version.
Do a page transition. See that during this transition the manifest is loaded. And in the URL the version ID is still the old app version
See that when requesting the old app version manifest we actually get back the latest app manifest with new files for the root module
See that the error occurs
Collapsed section contains the manifest for the old app version 32e10548
Collapsed section contains the manifest for the new app version e20cca2b
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 routes.ts configuration in an attempt to mitigate, but that wasn't effective.
@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?
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.
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.
So if a new version is deployed any client side navigation still loads in the old assets as specified by the manifest.
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.
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.
We ended up turning off the v3_lazyRouteDiscovery which solved the issue. Bummer we are stuck in this limbo where we can't complete the migration to RR7
Experiencing this issue as well. Started seeing this issue the deploy AFTER we enabled v3_lazyRouteDiscovery and deployed on remix. Still experiencing this issue on React Router.
This is causing significant issues with deploys, many users seeing our ErrorBoundary due to this bug.
I also see this issue. It happens non-deterministically, in dev and sometimes even in prod. Disappears after page reload. Can't provide a reproduceable sandbox due to non-determinism. The thread should be reopened.
Note: version mismatch between react and react-dom is often mentioned as one of causes, but it's not the only cause as many people (myself included) observe the bug even with properly set dependencies.
Currently testing a workaround suggested by @hyusetiawan...
server: {
warmup: {
clientFiles: [
'./app/**/!(*.server|*.test)*.tsx', // Include all .tsx files except server and test files (add more patterns if required)
],
},
},
Reacted by albt-revolucao, Yuhei Kuratomi, Dennis Senn, Tim Dilenyan and Tomer Ziv
Please open a new issue with a reproduction and we can take a look
If I a manage to detect how to reliably reproduce it. It doesn't happen all the time and luckily for now I am only seeing it on dev server.
If it helps - I believe we only see it when we do things like switch between branches with different remix (or react router) package versions. So you can simulate it by changing the version manually and re-installing
Yeah make sure you don't have duplicate copies of react or react-router in your dependency tree. You need to make sure you update all react-router deps together, so if you just upgraded to 7.8.1 my hunch is that you missed one of the @react-router/* deps.
Sorry you may have been mislead by my comment. What I mean is that we see this on both remix and react-router (framework) consistently - but it seems to be when the vite cache is being built.
ah ok, yeah that's also likely the same root cause - make sure you clear node_modules/.vite when you do that to get rid of any prior cached vite deps that might have a stale RR version
@gusano I think the issue is that nobody has, as yet, been able to create a minimal reproducible example to share to either remix or react-router and without that there is not a bug example they can then fix.
I started trying to do it because we see it in our monorepo (and it is very annoying) but I could not figure out a way to create a reproduction so I’ve sort-of learnt to live with the pain.
Activity
tigerabrodi commentedon Jan 31, 2025
I've encountered this several times myself on the "first" load.
Might be related to how the server hands off the initial context value. 👍
brookslybrand commentedon Jan 31, 2025
@tigerabrodi if you can reproduce it that would be helpful
thomaswelton commentedon Feb 3, 2025
@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`
aaronadamsCA commentedon Feb 3, 2025
thomaswelton commentedon Feb 3, 2025
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
So I don't think it's related to #10447 as that was released in a later version.
bran-watcha commentedon Feb 4, 2025
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.
yoni-noma commentedon Feb 4, 2025
using react-router v7.1.4 and it happens to me as well on production after deployment on tabs that holds the "old" version.
for now i cant rollback to v2, ive added a logic on errorBoundary that checks for the current build version and just before presenting the crash error to the user if there is a newer version im refreshing.. better ux but i dont like it, hoping to find a better solution 🙏
thomaswelton commentedon Feb 4, 2025
@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
isFogOfWarEnabled. There is no way to turn this off via any config. However I've just patched the react-router module to edit this code to always return false.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
Or you can try this (which I've not used) https://www.npmjs.com/package/patch-package
camthompson commentedon Feb 4, 2025
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
routes.tsconfiguration in an attempt to mitigate, but that wasn't effective.@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?
yoni-noma commentedon Feb 4, 2025
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?
thomaswelton commentedon Feb 4, 2025
@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.
So if a new version is deployed any client side navigation still loads in the old assets as specified by the manifest.
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.
rossipedia commentedon Feb 4, 2025
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.
elledienne commentedon Feb 10, 2025
We ended up turning off the
v3_lazyRouteDiscoverywhich solved the issue. Bummer we are stuck in this limbo where we can't complete the migration to RR7draperj commentedon Feb 18, 2025
Experiencing this issue as well. Started seeing this issue the deploy AFTER we enabled
v3_lazyRouteDiscoveryand deployed on remix. Still experiencing this issue on React Router.This is causing significant issues with deploys, many users seeing our ErrorBoundary due to this bug.
18 remaining items
punkpeye commentedon May 27, 2025
I have the following overrides:
but I am still having the same issue.
ivan-kleshnin commentedon Jun 2, 2025
I also see this issue. It happens non-deterministically, in dev and sometimes even in prod. Disappears after page reload. Can't provide a reproduceable sandbox due to non-determinism. The thread should be reopened.
Note: version mismatch between
reactandreact-domis often mentioned as one of causes, but it's not the only cause as many people (myself included) observe the bug even with properly set dependencies.Currently testing a workaround suggested by @hyusetiawan...
Update: didn't help ❌
MattyBalaam commentedon Jun 3, 2025
@ivan-kleshnin I tihnk we may have mostly fixed this issue by adapting the workaround here: remix-run/react-router#12786 (comment)
In our case we are using
ivan-kleshnin commentedon Jun 3, 2025
@MattyBalaam thank you, seems to help, or it least reduce the issue 🥇
sudo-vaibhav commentedon Jul 6, 2025
@hyusetiawan's config editing worked for me, but this doesnt explain why this issue is happening
jbojcic1 commentedon Aug 24, 2025
I am also seeing this issue with react router 7.8.1
brophdawg11 commentedon Aug 25, 2025
Please open a new issue with a reproduction and we can take a look
jbojcic1 commentedon Aug 26, 2025
If I manage to detect how to reliably reproduce it. It doesn't happen all the time and luckily for now I am only seeing it on dev server.
MattyBalaam commentedon Aug 26, 2025
If it helps - I believe we only see it when we do things like switch between branches with different remix (or react router) package versions. So you can simulate it by changing the version manually and re-installing
brophdawg11 commentedon Aug 26, 2025
Yeah make sure you don't have duplicate copies of
reactorreact-routerin your dependency tree. You need to make sure you update allreact-routerdeps together, so if you just upgraded to 7.8.1 my hunch is that you missed one of the@react-router/*deps.MattyBalaam commentedon Aug 26, 2025
Sorry you may have been mislead by my comment. What I mean is that we see this on both
remixandreact-router(framework) consistently - but it seems to be when the vite cache is being built.brophdawg11 commentedon Aug 26, 2025
ah ok, yeah that's also likely the same root cause - make sure you clear
node_modules/.vitewhen you do that to get rid of any prior cached vite deps that might have a stale RR versiongusano commentedon Sep 10, 2025
So remix-run/react-router#12786 is Not Planned and this one is closed?
Are we stuck then?
MattyBalaam commentedon Sep 10, 2025
@gusano I think the issue is that nobody has, as yet, been able to create a minimal reproducible example to share to either remix or react-router and without that there is not a bug example they can then fix.
I started trying to do it because we see it in our monorepo (and it is very annoying) but I could not figure out a way to create a reproduction so I’ve sort-of learnt to live with the pain.
gusano commentedon Sep 10, 2025
@MattyBalaam I managed to get rid of it by force cleaning
npmcache, removingnode_modules/.viteandnpm iagain.