@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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-9463fb5e
2
+ * @remix-run/router v0.0.0-experimental-8bb3ffdf
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1717,18 +1717,28 @@
1717
1717
  [route.id]: error
1718
1718
  };
1719
1719
  }
1720
-
1721
- // "Initialized" here really means "Can `RouterProvider` render my route tree?"
1722
- // Prior to `route.HydrateFallback`, we only had a root `fallbackElement` so we used
1723
- // `state.initialized` to render that instead of `<DataRoutes>`. Now that we
1724
- // support route level fallbacks we can always render and we'll just render
1725
- // as deep as we have data for and detect the nearest ancestor HydrateFallback
1726
- let initialized = future.v7_partialHydration ||
1727
- // All initialMatches need to be loaded before we're ready. If we have lazy
1728
- // functions around still then we'll need to run them in initialize()
1729
- !initialMatches.some(m => m.route.lazy) && (
1730
- // And we have to either have no loaders or have been provided hydrationData
1731
- !initialMatches.some(m => m.route.loader) || init.hydrationData != null);
1720
+ let initialized;
1721
+ let hasLazyRoutes = initialMatches.some(m => m.route.lazy);
1722
+ let hasLoaders = initialMatches.some(m => m.route.loader);
1723
+ if (hasLazyRoutes) {
1724
+ // All initialMatches need to be loaded before we're ready. If we have lazy
1725
+ // functions around still then we'll need to run them in initialize()
1726
+ initialized = false;
1727
+ } else if (!hasLoaders) {
1728
+ // If we've got no loaders to run, then we're good to go
1729
+ initialized = true;
1730
+ } else if (future.v7_partialHydration) {
1731
+ // If partial hydration is enabled, we're initialized so long as we were
1732
+ // provided with hydrationData for every route with a loader, and no loaders
1733
+ // were marked for explicit hydration
1734
+ let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
1735
+ let errors = init.hydrationData ? init.hydrationData.errors : null;
1736
+ initialized = initialMatches.every(m => m.route.loader && m.route.loader.hydrate !== true && (loaderData && loaderData[m.route.id] !== undefined || errors && errors[m.route.id] !== undefined));
1737
+ } else {
1738
+ // Without partial hydration - we're initialized if we were provided any
1739
+ // hydrationData - which is expected to be complete
1740
+ initialized = init.hydrationData != null;
1741
+ }
1732
1742
  let router;
1733
1743
  let state = {
1734
1744
  historyAction: init.history.action,
@@ -1895,7 +1905,7 @@
1895
1905
  // in the normal navigation flow. For SSR it's expected that lazy modules are
1896
1906
  // resolved prior to router creation since we can't go into a fallbackElement
1897
1907
  // UI for SSR'd apps
1898
- if (!state.initialized || future.v7_partialHydration && state.matches.some(m => isUnhydratedRoute(state, m.route))) {
1908
+ if (!state.initialized) {
1899
1909
  startNavigation(Action.Pop, state.location, {
1900
1910
  initialHydration: true
1901
1911
  });
@@ -3267,8 +3277,7 @@
3267
3277
  }
3268
3278
  // Config driven behavior flags
3269
3279
  let future = _extends({
3270
- v7_relativeSplatPath: false,
3271
- v7_throwAbortReason: false
3280
+ v7_relativeSplatPath: false
3272
3281
  }, opts ? opts.future : null);
3273
3282
  let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, undefined, manifest);
3274
3283
 
@@ -3491,7 +3500,8 @@
3491
3500
  requestContext
3492
3501
  });
3493
3502
  if (request.signal.aborted) {
3494
- throwStaticHandlerAbortedError(request, isRouteRequest, future);
3503
+ let method = isRouteRequest ? "queryRoute" : "query";
3504
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3495
3505
  }
3496
3506
  }
3497
3507
  if (isRedirectResult(result)) {
@@ -3609,7 +3619,8 @@
3609
3619
  requestContext
3610
3620
  }))]);
3611
3621
  if (request.signal.aborted) {
3612
- throwStaticHandlerAbortedError(request, isRouteRequest, future);
3622
+ let method = isRouteRequest ? "queryRoute" : "query";
3623
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3613
3624
  }
3614
3625
 
3615
3626
  // Process and commit output from loaders
@@ -3654,14 +3665,6 @@
3654
3665
  });
3655
3666
  return newContext;
3656
3667
  }
3657
- function throwStaticHandlerAbortedError(request, isRouteRequest, future) {
3658
- let method = isRouteRequest ? "queryRoute" : "query";
3659
- if (future.v7_throwAbortReason && request.signal.reason !== undefined) {
3660
- throw request.signal.reason;
3661
- } else {
3662
- throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3663
- }
3664
- }
3665
3668
  function isSubmissionNavigation(opts) {
3666
3669
  return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== undefined);
3667
3670
  }
@@ -3858,18 +3861,24 @@
3858
3861
  let boundaryId = pendingError ? Object.keys(pendingError)[0] : undefined;
3859
3862
  let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
3860
3863
  let navigationMatches = boundaryMatches.filter((match, index) => {
3861
- if (isInitialLoad) {
3862
- // On initial hydration we don't do any shouldRevalidate stuff - we just
3863
- // call the unhydrated loaders
3864
- return isUnhydratedRoute(state, match.route);
3865
- }
3866
- if (match.route.lazy) {
3864
+ let {
3865
+ route
3866
+ } = match;
3867
+ if (route.lazy) {
3867
3868
  // We haven't loaded this route yet so we don't know if it's got a loader!
3868
3869
  return true;
3869
3870
  }
3870
- if (match.route.loader == null) {
3871
+ if (route.loader == null) {
3871
3872
  return false;
3872
3873
  }
3874
+ if (isInitialLoad) {
3875
+ if (route.loader.hydrate) {
3876
+ return true;
3877
+ }
3878
+ return state.loaderData[route.id] === undefined && (
3879
+ // Don't re-run if the loader ran and threw an error
3880
+ !state.errors || state.errors[route.id] === undefined);
3881
+ }
3873
3882
 
3874
3883
  // Always call the loader on new route instances and pending defer cancellations
3875
3884
  if (isNewLoader(state.loaderData, state.matches[index], match) || cancelledDeferredRoutes.some(id => id === match.route.id)) {
@@ -3971,20 +3980,6 @@
3971
3980
  });
3972
3981
  return [navigationMatches, revalidatingFetchers];
3973
3982
  }
3974
-
3975
- // Is this route unhydrated (when v7_partialHydration=true) such that we need
3976
- // to call it's loader on the initial router creation
3977
- function isUnhydratedRoute(state, route) {
3978
- if (!route.loader) {
3979
- return false;
3980
- }
3981
- if (route.loader.hydrate) {
3982
- return true;
3983
- }
3984
- return state.loaderData[route.id] === undefined && (!state.errors ||
3985
- // Loader ran but errored - don't re-run
3986
- state.errors[route.id] === undefined);
3987
- }
3988
3983
  function isNewLoader(currentLoaderData, currentMatch, match) {
3989
3984
  let isNew =
3990
3985
  // [a] -> [a, b]