Skip to content
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

Fix FOUC on subsequent client-side navigations to route.lazy routes #7576

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/route-lazy-fouc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Fix FOUC on subsequent client-side navigations to route.lazy routes
22 changes: 20 additions & 2 deletions packages/remix-react/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,26 @@ export function createClientRoutes(
id: route.id,
index: route.index,
path: route.path,
loader({ request }) {
async loader({ request }) {
// Only prefetch links if we've been loaded into the cache, route.lazy
// will handle initial loads
let routeModulePromise = routeModulesCache[route.id]
? prefetchStyleLinks(routeModulesCache[route.id])
: Promise.resolve();
try {
if (!route.hasLoader) return null;
return fetchServerHandler(request, route);
} finally {
await routeModulePromise;
}
},
action({ request }) {
async action({ request }) {
// Only prefetch links if we've been loaded into the cache, route.lazy
// will handle initial loads
let routeModulePromise = routeModulesCache[route.id]
? prefetchStyleLinks(routeModulesCache[route.id])
: Promise.resolve();
try {
if (!route.hasAction) {
let msg =
`Route "${route.id}" does not have an action, but you are trying ` +
Expand All @@ -147,6 +162,9 @@ export function createClientRoutes(
}

return fetchServerHandler(request, route);
} finally {
await routeModulePromise;
}
},
...(routeModule
? // Use critical path modules directly
Expand Down