Getting 'cannot read properties of null (Reading 'useContext') after building.
Hi I am building the frontend for a WordPress website using react and Tanstack.
Everything runs fine in development.
But after a build the app and add it to my wordpress website, I get this type error wherever I use 'getRouteApi' or 'useSuspenseQuery'
But it only happens on first load. When I reload it works fine.
What could be the issue?
3 Replies
other-emerald•7mo ago
I have the same issue as @anandhunatesh
harsh-harlequinOP•7mo ago
Hey I found the reason for it.
It's lazy load.
Only routes with lazy load gets this issue. I believe the lazy file include does not work properly in the WordPress environment.
I have removed the lazy routes and it worked.
Hopefully it will help someone.
stuck-chocolate•7mo ago
can you please share more details?
which kind of lazy are you using, manual .lazy routes or auto codesplitting?
which error messages do you get? can you please post the full stacktrace?
do you see any network errors? (e.g. 404 etc when the lazy chunks are trying to be loaded)