@remix-run/router 1.14.0-pre.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.14.0-pre.0",
3
+ "version": "1.14.0",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -817,19 +817,34 @@ export function createRouter(init: RouterInit): Router {
817
817
  initialErrors = { [route.id]: error };
818
818
  }
819
819
 
820
- // "Initialized" here really means "Can `RouterProvider` render my route tree?"
821
- // Prior to `route.HydrateFallback`, we only had a root `fallbackElement` so we used
822
- // `state.initialized` to render that instead of `<DataRoutes>`. Now that we
823
- // support route level fallbacks we can always render and we'll just render
824
- // as deep as we have data for and detect the nearest ancestor HydrateFallback
825
- let initialized =
826
- future.v7_partialHydration ||
820
+ let initialized: boolean;
821
+ let hasLazyRoutes = initialMatches.some((m) => m.route.lazy);
822
+ let hasLoaders = initialMatches.some((m) => m.route.loader);
823
+ if (hasLazyRoutes) {
827
824
  // All initialMatches need to be loaded before we're ready. If we have lazy
828
825
  // functions around still then we'll need to run them in initialize()
829
- (!initialMatches.some((m) => m.route.lazy) &&
830
- // And we have to either have no loaders or have been provided hydrationData
831
- (!initialMatches.some((m) => m.route.loader) ||
832
- init.hydrationData != null));
826
+ initialized = false;
827
+ } else if (!hasLoaders) {
828
+ // If we've got no loaders to run, then we're good to go
829
+ initialized = true;
830
+ } else if (future.v7_partialHydration) {
831
+ // If partial hydration is enabled, we're initialized so long as we were
832
+ // provided with hydrationData for every route with a loader, and no loaders
833
+ // were marked for explicit hydration
834
+ let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
835
+ let errors = init.hydrationData ? init.hydrationData.errors : null;
836
+ initialized = initialMatches.every(
837
+ (m) =>
838
+ m.route.loader &&
839
+ m.route.loader.hydrate !== true &&
840
+ ((loaderData && loaderData[m.route.id] !== undefined) ||
841
+ (errors && errors[m.route.id] !== undefined))
842
+ );
843
+ } else {
844
+ // Without partial hydration - we're initialized if we were provided any
845
+ // hydrationData - which is expected to be complete
846
+ initialized = init.hydrationData != null;
847
+ }
833
848
 
834
849
  let router: Router;
835
850
  let state: RouterState = {
@@ -1010,11 +1025,7 @@ export function createRouter(init: RouterInit): Router {
1010
1025
  // in the normal navigation flow. For SSR it's expected that lazy modules are
1011
1026
  // resolved prior to router creation since we can't go into a fallbackElement
1012
1027
  // UI for SSR'd apps
1013
- if (
1014
- !state.initialized ||
1015
- (future.v7_partialHydration &&
1016
- state.matches.some((m) => isUnhydratedRoute(state, m.route)))
1017
- ) {
1028
+ if (!state.initialized) {
1018
1029
  startNavigation(HistoryAction.Pop, state.location, {
1019
1030
  initialHydration: true,
1020
1031
  });