You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/posts/split-route-modules.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -42,15 +42,15 @@ Unfortunately, because these exports are both contained within the same module,
42
42
43
43
To visualize this as a timeline:
44
44
45
-
<imgalt="Waterfall diagram showing 'Click /route' triggering 'Get route module' (split into 'clientLoader' and 'Component' segments) followed by 'Run clientLoader' before 'Render content' occurs"src="/blog-images/posts/split-route-modules/get-route-module.png"class="m-auto w-4/5 border rounded-md shadow" />
45
+
<imgalt="Waterfall diagram showing 'Click /route' triggering 'Get route module' (split into 'clientLoader' and 'Component' segments) followed by 'Run clientLoader' before 'Render content' occurs"src="/blog-images/posts/split-route-modules/get-route-module.png"class="m-auto sm:w-4/5 border rounded-md shadow" />
46
46
47
47
Note that, while the route module is a single request from the browser, in this diagram we’re showing how it’s made up of multiple logical units — in this case, `clientLoader` and `Component`.
48
48
49
49
The `clientLoader` is delayed from calling the external API since it has to wait for the hypothetical `MassiveComponent` to download. Since we can't render the component without the data from the client loader, the user has to wait for this network waterfall to complete before the page is rendered.
50
50
51
51
Ideally we’d like to be able to download the `clientLoader` export independently and run it as soon as it’s available:
52
52
53
-
<imgalt="Waterfall diagram showing 'Click /route' triggering a parallel 'Get clientLoader' and 'Get Component' followed by 'Run clientLoader' before 'Render content' occurs, now earlier than before"src="/blog-images/posts/split-route-modules/get-route-module-split.png"class="m-auto w-4/5 border rounded-md shadow" />
53
+
<imgalt="Waterfall diagram showing 'Click /route' triggering a parallel 'Get clientLoader' and 'Get Component' followed by 'Run clientLoader' before 'Render content' occurs, now earlier than before"src="/blog-images/posts/split-route-modules/get-route-module-split.png"class="m-auto sm:w-4/5 border rounded-md shadow" />
54
54
55
55
At a framework level, the easiest way for us to solve this would be to force you to author your route in multiple files (`route/clientLoader.ts`, `route/component.tsx`, etc.) — but we really didn't want to give up on the convenience of the Route Module API. The question is, how do we achieve this?
56
56
@@ -84,11 +84,11 @@ Since these exports have now been split into separate modules, the React Router
84
84
85
85
This optimization is even more pronounced when using additional parts of the Route Module API. For example, when using `clientLoader`, `clientAction` and `HydrateFallback`, the timeline for a single route module during a client-side navigation might look like this:
86
86
87
-
<imgalt="Waterfall diagram showing 'Click /route' triggering 'Get route module' (split into 'clientLoader', 'clientAction', 'Component' and 'HydrateFallback' segments) followed by 'Run clientLoader' before 'Render content' occurs"src="/blog-images/posts/split-route-modules/get-big-route-module.png"class="m-auto w-4/5 border rounded-md shadow" />
87
+
<imgalt="Waterfall diagram showing 'Click /route' triggering 'Get route module' (split into 'clientLoader', 'clientAction', 'Component' and 'HydrateFallback' segments) followed by 'Run clientLoader' before 'Render content' occurs"src="/blog-images/posts/split-route-modules/get-big-route-module.png"class="m-auto sm:w-4/5 border rounded-md shadow" />
88
88
89
89
This would instead be optimized to the following:
90
90
91
-
<imgalt="Waterfall diagram showing 'Click /route' triggering a parallel 'Get clientLoader', 'Get clientAction' and 'Get Component' (with 'HydrateFallback' being skipped) followed by 'Run clientLoader' before 'Render content' occurs, now earlier than before"src="/blog-images/posts/split-route-modules/get-big-route-module-split.png"class="m-auto w-4/5 border rounded-md shadow" />
91
+
<imgalt="Waterfall diagram showing 'Click /route' triggering a parallel 'Get clientLoader', 'Get clientAction' and 'Get Component' (with 'HydrateFallback' being skipped) followed by 'Run clientLoader' before 'Render content' occurs, now earlier than before"src="/blog-images/posts/split-route-modules/get-big-route-module-split.png"class="m-auto sm:w-4/5 border rounded-md shadow" />
92
92
93
93
This looks much better! As before, the client loader doesn't need to wait for the component to download, and now it doesn't need to wait for the `clientAction` or `HydrateFallback` exports to download either. In fact, it doesn't even need to download the `HydrateFallback` export at all during client navigations since it's only ever used on the initial page load.
0 commit comments