-
Notifications
You must be signed in to change notification settings - Fork 172
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
Make shouldRevalidate
work
#4238
Conversation
Job #8256: Bundle Size — 62.65MiB (~+0.01%).
Metrics (2 changes)
Total size by type (1 change)
View job #8256 report View fix/populate-route-modules-cache branch activity |
…to fix/populate-route-modules-cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the compromise is acceptable, because shouldRevalidate is stored on the Remix route, which is stored in DerivedState, so it would be a really involved refactor to make that non-global. Basically we would have to move back plenty of code to UtopiaRemixRootComponent hooks.
But I think it you should add a TODO comment about this, so we will take this into account when we migrate to Remix V2, and we rethink what can happen in the derivestate and what needs to happen separately for the different remix scenes.
Problem
When navigating from a rendered route module to the same route module (for example, from
/posts/0
to/posts/1
in the example project), the navigation doesn't happen and an error is thrown.Root cause
DataRouteObject.shouldRevalidate
is a way to optimize data revalidation in Remix (see https://remix.run/docs/en/main/route/should-revalidate for details). It's called after actions and on client-side navigations (this is our use case).It's optionally exported from route modules, and a factory function called
createShouldRevalidate
(utopia/editor/src/third-party/remix/client-routes.tsx
Line 143 in 37481e7
shouldRevalidate
isn't exported from the route module. ThiscreateShouldRevalidate
picks out the route to be validated fromrouteModulesCache
, which is where our code needs to be improved since we never actually fill outrouteModulesCache
, and because of this, an invariant exception is thrown.Fix
When creating the route modules in
UtopiaRemixRootComponent
, write the route module intoCreateRemixDerivedDataRefsGLOBAL.routeModulesCache.current
.Details
As of this PR, the route module cache is a global variable (somewhat modeled on RemixBrowser, where the route module cache is a global on the window,
window.__routeModules
(https://github.com/remix-run/remix/blob/d5ec2f8e01527998470c98db6d15cb489823187e/packages/remix-react/browser.tsx#L139)). This is problematic for us becausecreateShouldRevalidate
also creates a variable that it captures (utopia/editor/src/third-party/remix/client-routes.tsx
Line 148 in bdad305
shouldRevalidate
calls. This might lead to revalidation not working correctly. Still, we should accept this as a known bug so that the problem above is fixed.