Skip to content

Commit 8db4099

Browse files
Increase precedence of route chunk downloads
1 parent 43ec44b commit 8db4099

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/react-router/lib/dom/ssr/routes.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ export function createClientRoutes(
444444

445445
// Load all other modules via route.lazy()
446446
dataRoute.lazy = async () => {
447+
if (route.clientLoaderModule || route.clientActionModule) {
448+
// If a client loader/action chunk is present, we push the loading of
449+
// the main route chunk to the next tick to ensure the downloading of
450+
// loader/action chunks takes precedence. This can be seen via their
451+
// order in the network tab. Also note that since this is happening
452+
// within `route.lazy`, this imperceptible delay only happens on the
453+
// first load of this route.
454+
await new Promise((resolve) => setTimeout(resolve, 0));
455+
}
456+
447457
let mod = await loadRouteModuleWithBlockingLinks(
448458
route,
449459
routeModulesCache

0 commit comments

Comments
 (0)