@remix-run/router 0.0.0-experimental-9463fb5e → 0.0.0-experimental-8bb3ffdf

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": "0.0.0-experimental-9463fb5e",
3
+ "version": "0.0.0-experimental-8bb3ffdf",
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
  });
@@ -2823,7 +2834,6 @@ export const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
2823
2834
  */
2824
2835
  export interface StaticHandlerFutureConfig {
2825
2836
  v7_relativeSplatPath: boolean;
2826
- v7_throwAbortReason: boolean;
2827
2837
  }
2828
2838
 
2829
2839
  export interface CreateStaticHandlerOptions {
@@ -2862,7 +2872,6 @@ export function createStaticHandler(
2862
2872
  // Config driven behavior flags
2863
2873
  let future: StaticHandlerFutureConfig = {
2864
2874
  v7_relativeSplatPath: false,
2865
- v7_throwAbortReason: false,
2866
2875
  ...(opts ? opts.future : null),
2867
2876
  };
2868
2877
 
@@ -3132,7 +3141,10 @@ export function createStaticHandler(
3132
3141
  );
3133
3142
 
3134
3143
  if (request.signal.aborted) {
3135
- throwStaticHandlerAbortedError(request, isRouteRequest, future);
3144
+ let method = isRouteRequest ? "queryRoute" : "query";
3145
+ throw new Error(
3146
+ `${method}() call aborted: ${request.method} ${request.url}`
3147
+ );
3136
3148
  }
3137
3149
  }
3138
3150
 
@@ -3300,7 +3312,10 @@ export function createStaticHandler(
3300
3312
  ]);
3301
3313
 
3302
3314
  if (request.signal.aborted) {
3303
- throwStaticHandlerAbortedError(request, isRouteRequest, future);
3315
+ let method = isRouteRequest ? "queryRoute" : "query";
3316
+ throw new Error(
3317
+ `${method}() call aborted: ${request.method} ${request.url}`
3318
+ );
3304
3319
  }
3305
3320
 
3306
3321
  // Process and commit output from loaders
@@ -3365,21 +3380,6 @@ export function getStaticContextFromError(
3365
3380
  return newContext;
3366
3381
  }
3367
3382
 
3368
- function throwStaticHandlerAbortedError(
3369
- request: Request,
3370
- isRouteRequest: boolean,
3371
- future: StaticHandlerFutureConfig
3372
- ) {
3373
- let method = isRouteRequest ? "queryRoute" : "query";
3374
- if (future.v7_throwAbortReason && request.signal.reason !== undefined) {
3375
- throw request.signal.reason;
3376
- } else {
3377
- throw new Error(
3378
- `${method}() call aborted: ${request.method} ${request.url}`
3379
- );
3380
- }
3381
- }
3382
-
3383
3383
  function isSubmissionNavigation(
3384
3384
  opts: BaseNavigateOrFetchOptions
3385
3385
  ): opts is SubmissionNavigateOptions {
@@ -3655,21 +3655,27 @@ function getMatchesToLoad(
3655
3655
  let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
3656
3656
 
3657
3657
  let navigationMatches = boundaryMatches.filter((match, index) => {
3658
- if (isInitialLoad) {
3659
- // On initial hydration we don't do any shouldRevalidate stuff - we just
3660
- // call the unhydrated loaders
3661
- return isUnhydratedRoute(state, match.route);
3662
- }
3663
-
3664
- if (match.route.lazy) {
3658
+ let { route } = match;
3659
+ if (route.lazy) {
3665
3660
  // We haven't loaded this route yet so we don't know if it's got a loader!
3666
3661
  return true;
3667
3662
  }
3668
3663
 
3669
- if (match.route.loader == null) {
3664
+ if (route.loader == null) {
3670
3665
  return false;
3671
3666
  }
3672
3667
 
3668
+ if (isInitialLoad) {
3669
+ if (route.loader.hydrate) {
3670
+ return true;
3671
+ }
3672
+ return (
3673
+ state.loaderData[route.id] === undefined &&
3674
+ // Don't re-run if the loader ran and threw an error
3675
+ (!state.errors || state.errors[route.id] === undefined)
3676
+ );
3677
+ }
3678
+
3673
3679
  // Always call the loader on new route instances and pending defer cancellations
3674
3680
  if (
3675
3681
  isNewLoader(state.loaderData, state.matches[index], match) ||
@@ -3789,23 +3795,6 @@ function getMatchesToLoad(
3789
3795
  return [navigationMatches, revalidatingFetchers];
3790
3796
  }
3791
3797
 
3792
- // Is this route unhydrated (when v7_partialHydration=true) such that we need
3793
- // to call it's loader on the initial router creation
3794
- function isUnhydratedRoute(state: RouterState, route: AgnosticDataRouteObject) {
3795
- if (!route.loader) {
3796
- return false;
3797
- }
3798
- if (route.loader.hydrate) {
3799
- return true;
3800
- }
3801
- return (
3802
- state.loaderData[route.id] === undefined &&
3803
- (!state.errors ||
3804
- // Loader ran but errored - don't re-run
3805
- state.errors[route.id] === undefined)
3806
- );
3807
- }
3808
-
3809
3798
  function isNewLoader(
3810
3799
  currentLoaderData: RouteData,
3811
3800
  currentMatch: AgnosticDataRouteMatch,