[Bug]: context providers are lost during refetchRouteData
and return undefined
#972
Closed
2 tasks done
Labels
bug
Something isn't working
Duplicates
Latest version
Current behavior 😯
If you add a context provider, say around all routes in
root.tsx
tree directly, or in a layout around all routes, then you canuseContext
to get the values provided just fine.They work:
BUT, if you do something like:
Then during this refetch in the
routeData
call touseContext
returnsundefined
during the lifecycle of the refetch.Expected behavior 🤔
That if you can use
useContext
in route data at all, it should work for any time the route data function is called: first render, refetch, refetch by keySteps to reproduce 🕹
Steps:
useContext
this context in a component, and log the value returned fromuseContext
div
in that component torefetchRouteData
div
and watch the log message foruseContext
go from having a value previously to undefined during refetchContext 🔦
If we want to inject context we have to be able to trust it everywhere, otherwise your code breaks. I.e. if I inject a API class that holds the configured API end points and want to use it everywhere, I need to reliably appear.
Your environment 🌎
The text was updated successfully, but these errors were encountered: