@remix-run/router 0.0.0-experimental-e192105b → 0.0.0-experimental-178bc9ee

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-e192105b
2
+ * @remix-run/router v0.0.0-experimental-178bc9ee
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1194,6 +1194,13 @@
1194
1194
  return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0);
1195
1195
  }
1196
1196
 
1197
+ // Return the array of pathnames for the current route matches - used to
1198
+ // generate the routePathnames input for resolveTo()
1199
+ function getResolveToMatches(matches) {
1200
+ // Use the full pathname for the leaf match so we include splat values for "." links
1201
+ return getPathContributingMatches(matches).map((match, idx) => idx === matches.length - 1 ? match.pathname : match.pathnameBase);
1202
+ }
1203
+
1197
1204
  /**
1198
1205
  * @private
1199
1206
  */
@@ -1223,16 +1230,30 @@
1223
1230
  // `to` values that do not provide a pathname. `to` can simply be a search or
1224
1231
  // hash string, in which case we should assume that the navigation is relative
1225
1232
  // to the current location's pathname and *not* the route pathname.
1226
- if (isPathRelative || toPathname == null) {
1233
+ if (toPathname == null) {
1227
1234
  from = locationPathname;
1235
+ } else if (isPathRelative) {
1236
+ let fromSegments = routePathnames[routePathnames.length - 1].replace(/^\//, "").split("/");
1237
+ if (toPathname.startsWith("..")) {
1238
+ let toSegments = toPathname.split("/");
1239
+
1240
+ // With relative="path", each leading .. segment means "go up one URL segment"
1241
+ while (toSegments[0] === "..") {
1242
+ toSegments.shift();
1243
+ fromSegments.pop();
1244
+ }
1245
+ to.pathname = toSegments.join("/");
1246
+ }
1247
+ from = "/" + fromSegments.join("/");
1228
1248
  } else {
1229
1249
  let routePathnameIndex = routePathnames.length - 1;
1230
1250
  if (toPathname.startsWith("..")) {
1231
1251
  let toSegments = toPathname.split("/");
1232
1252
 
1233
- // Each leading .. segment means "go up one route" instead of "go up one
1234
- // URL segment". This is a key difference from how <a href> works and a
1235
- // major reason we call this a "to" value instead of a "href".
1253
+ // With relative="route" (the default), each leading .. segment means
1254
+ // "go up one route" instead of "go up one URL segment". This is a key
1255
+ // difference from how <a href> works and a major reason we call this a
1256
+ // "to" value instead of a "href".
1236
1257
  while (toSegments[0] === "..") {
1237
1258
  toSegments.shift();
1238
1259
  routePathnameIndex -= 1;
@@ -1667,6 +1688,7 @@
1667
1688
  let future = _extends({
1668
1689
  v7_fetcherPersist: false,
1669
1690
  v7_normalizeFormMethod: false,
1691
+ v7_partialHydration: false,
1670
1692
  v7_prependBasename: false
1671
1693
  }, init.future);
1672
1694
  // Cleanup function for history
@@ -1703,7 +1725,13 @@
1703
1725
  [route.id]: error
1704
1726
  };
1705
1727
  }
1706
- let initialized =
1728
+
1729
+ // "Initialized" here really means "Can `RouterProvider` render my route tree?"
1730
+ // Prior to `route.Fallback`, we only had a root `fallbackElement` so we used
1731
+ // `state.initialized` to render that instead of `<DataRoutes>`. Now that we
1732
+ // support route level fallbacks we can always render and we'll just render
1733
+ // as deep as we have data for and detect the nearest ancestor Fallback
1734
+ let initialized = future.v7_partialHydration ||
1707
1735
  // All initialMatches need to be loaded before we're ready. If we have lazy
1708
1736
  // functions around still then we'll need to run them in initialize()
1709
1737
  !initialMatches.some(m => m.route.lazy) && (
@@ -1741,9 +1769,6 @@
1741
1769
  // Should the current navigation enable document.startViewTransition?
1742
1770
  let pendingViewTransitionEnabled = false;
1743
1771
 
1744
- // Should the current navigation use flushSync for state updates?
1745
- let pendingFlushSync = false;
1746
-
1747
1772
  // Store applied view transitions so we can apply them on POP
1748
1773
  let appliedViewTransitions = new Map();
1749
1774
 
@@ -1857,8 +1882,6 @@
1857
1882
  blockers.set(blockerKey, IDLE_BLOCKER);
1858
1883
  updateState({
1859
1884
  blockers
1860
- }, {
1861
- flushSync: false
1862
1885
  });
1863
1886
  }
1864
1887
  });
@@ -1880,8 +1903,10 @@
1880
1903
  // in the normal navigation flow. For SSR it's expected that lazy modules are
1881
1904
  // resolved prior to router creation since we can't go into a fallbackElement
1882
1905
  // UI for SSR'd apps
1883
- if (!state.initialized) {
1884
- startNavigation(Action.Pop, state.location);
1906
+ if (!state.initialized || future.v7_partialHydration && state.matches.some(m => m.route.loader && state.loaderData[m.route.id] === undefined)) {
1907
+ startNavigation(Action.Pop, state.location, {
1908
+ initialHydration: true
1909
+ });
1885
1910
  }
1886
1911
  return router;
1887
1912
  }
@@ -1908,6 +1933,9 @@
1908
1933
 
1909
1934
  // Update our state and notify the calling context of the change
1910
1935
  function updateState(newState, opts) {
1936
+ if (opts === void 0) {
1937
+ opts = {};
1938
+ }
1911
1939
  state = _extends({}, state, newState);
1912
1940
 
1913
1941
  // Prep fetcher cleanup so we can tell the UI which fetcher data entries
@@ -1935,7 +1963,7 @@
1935
1963
  [...subscribers].forEach(subscriber => subscriber(state, {
1936
1964
  deletedFetchers: deletedFetchersKeys,
1937
1965
  unstable_viewTransitionOpts: opts.viewTransitionOpts,
1938
- unstable_flushSync: opts.flushSync
1966
+ unstable_flushSync: opts.flushSync === true
1939
1967
  }));
1940
1968
 
1941
1969
  // Remove idle fetchers from state since we only care about in-flight fetchers.
@@ -1950,8 +1978,11 @@
1950
1978
  // - Location is a required param
1951
1979
  // - Navigation will always be set to IDLE_NAVIGATION
1952
1980
  // - Can pass any other state in newState
1953
- function completeNavigation(location, newState) {
1981
+ function completeNavigation(location, newState, _temp) {
1954
1982
  var _location$state, _location$state2;
1983
+ let {
1984
+ flushSync
1985
+ } = _temp === void 0 ? {} : _temp;
1955
1986
  // Deduce if we're in a loading/actionReload state:
1956
1987
  // - We have committed actionData in the store
1957
1988
  // - The current navigation was a mutation submission
@@ -2044,14 +2075,13 @@
2044
2075
  blockers
2045
2076
  }), {
2046
2077
  viewTransitionOpts,
2047
- flushSync: pendingFlushSync
2078
+ flushSync: flushSync === true
2048
2079
  });
2049
2080
 
2050
2081
  // Reset stateful navigation vars
2051
2082
  pendingAction = Action.Pop;
2052
2083
  pendingPreventScrollReset = false;
2053
2084
  pendingViewTransitionEnabled = false;
2054
- pendingFlushSync = false;
2055
2085
  isUninterruptedRevalidation = false;
2056
2086
  isRevalidationRequired = false;
2057
2087
  cancelledDeferredRoutes = [];
@@ -2118,8 +2148,6 @@
2118
2148
  blockers.set(blockerKey, IDLE_BLOCKER);
2119
2149
  updateState({
2120
2150
  blockers
2121
- }, {
2122
- flushSync
2123
2151
  });
2124
2152
  }
2125
2153
  });
@@ -2144,8 +2172,6 @@
2144
2172
  interruptActiveLoads();
2145
2173
  updateState({
2146
2174
  revalidation: "loading"
2147
- }, {
2148
- flushSync: false
2149
2175
  });
2150
2176
 
2151
2177
  // If we're currently submitting an action, we don't need to start a new
@@ -2189,10 +2215,10 @@
2189
2215
  saveScrollPosition(state.location, state.matches);
2190
2216
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
2191
2217
  pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
2192
- pendingFlushSync = (opts && opts.flushSync) === true;
2193
2218
  let routesToUse = inFlightDataRoutes || dataRoutes;
2194
2219
  let loadingNavigation = opts && opts.overrideNavigation;
2195
2220
  let matches = matchRoutes(routesToUse, location, basename);
2221
+ let flushSync = (opts && opts.flushSync) === true;
2196
2222
 
2197
2223
  // Short circuit with a 404 on the root error boundary if we match nothing
2198
2224
  if (!matches) {
@@ -2211,6 +2237,8 @@
2211
2237
  errors: {
2212
2238
  [route.id]: error
2213
2239
  }
2240
+ }, {
2241
+ flushSync
2214
2242
  });
2215
2243
  return;
2216
2244
  }
@@ -2224,13 +2252,15 @@
2224
2252
  if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
2225
2253
  completeNavigation(location, {
2226
2254
  matches
2255
+ }, {
2256
+ flushSync
2227
2257
  });
2228
2258
  return;
2229
2259
  }
2230
2260
 
2231
2261
  // Create a controller/Request for this navigation
2232
2262
  pendingNavigationController = new AbortController();
2233
- let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.submission);
2263
+ let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.initialHydration === true, opts && opts.submission);
2234
2264
  let pendingActionData;
2235
2265
  let pendingError;
2236
2266
  if (opts && opts.pendingError) {
@@ -2244,7 +2274,8 @@
2244
2274
  } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
2245
2275
  // Call action if we received an action submission
2246
2276
  let actionOutput = await handleAction(request, location, opts.submission, matches, {
2247
- replace: opts.replace
2277
+ replace: opts.replace,
2278
+ flushSync
2248
2279
  });
2249
2280
  if (actionOutput.shortCircuited) {
2250
2281
  return;
@@ -2252,6 +2283,7 @@
2252
2283
  pendingActionData = actionOutput.pendingActionData;
2253
2284
  pendingError = actionOutput.pendingActionError;
2254
2285
  loadingNavigation = getLoadingNavigation(location, opts.submission);
2286
+ flushSync = false;
2255
2287
 
2256
2288
  // Create a GET request for the loaders
2257
2289
  request = new Request(request.url, {
@@ -2264,7 +2296,7 @@
2264
2296
  shortCircuited,
2265
2297
  loaderData,
2266
2298
  errors
2267
- } = await handleLoaders(request, location, matches, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, pendingActionData, pendingError);
2299
+ } = await handleLoaders(request, location, matches, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionData, pendingError);
2268
2300
  if (shortCircuited) {
2269
2301
  return;
2270
2302
  }
@@ -2296,7 +2328,7 @@
2296
2328
  updateState({
2297
2329
  navigation
2298
2330
  }, {
2299
- flushSync: pendingFlushSync
2331
+ flushSync: opts.flushSync === true
2300
2332
  });
2301
2333
 
2302
2334
  // Call our action and get the result
@@ -2371,7 +2403,7 @@
2371
2403
 
2372
2404
  // Call all applicable loaders for the given matches, handling redirects,
2373
2405
  // errors, etc.
2374
- async function handleLoaders(request, location, matches, overrideNavigation, submission, fetcherSubmission, replace, pendingActionData, pendingError) {
2406
+ async function handleLoaders(request, location, matches, overrideNavigation, submission, fetcherSubmission, replace, initialHydration, flushSync, pendingActionData, pendingError) {
2375
2407
  // Figure out the right navigation we want to use for data loading
2376
2408
  let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
2377
2409
 
@@ -2379,7 +2411,7 @@
2379
2411
  // we have it on the loading navigation so use that if available
2380
2412
  let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
2381
2413
  let routesToUse = inFlightDataRoutes || dataRoutes;
2382
- let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionData, pendingError);
2414
+ let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionData, pendingError);
2383
2415
 
2384
2416
  // Cancel pending deferreds for no-longer-matched routes or routes we're
2385
2417
  // about to reload. Note that if this is an action reload we would have
@@ -2399,7 +2431,9 @@
2399
2431
  actionData: pendingActionData
2400
2432
  } : {}, updatedFetchers ? {
2401
2433
  fetchers: new Map(state.fetchers)
2402
- } : {}));
2434
+ } : {}), {
2435
+ flushSync
2436
+ });
2403
2437
  return {
2404
2438
  shortCircuited: true
2405
2439
  };
@@ -2425,7 +2459,7 @@
2425
2459
  } : {}, revalidatingFetchers.length > 0 ? {
2426
2460
  fetchers: new Map(state.fetchers)
2427
2461
  } : {}), {
2428
- flushSync: pendingFlushSync
2462
+ flushSync
2429
2463
  });
2430
2464
  }
2431
2465
  revalidatingFetchers.forEach(rf => {
@@ -2580,7 +2614,7 @@
2580
2614
 
2581
2615
  // Call the action for the fetcher
2582
2616
  let abortController = new AbortController();
2583
- let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
2617
+ let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, false, submission);
2584
2618
  fetchControllers.set(key, abortController);
2585
2619
  let originatingLoadId = incrementingLoadId;
2586
2620
  let actionResult = await callLoaderOrAction("action", fetchRequest, match, requestMatches, manifest, mapRouteProperties, basename);
@@ -2593,9 +2627,7 @@
2593
2627
  return;
2594
2628
  }
2595
2629
  if (deletedFetchers.has(key)) {
2596
- updateFetcherState(key, getDoneFetcher(undefined), {
2597
- flushSync
2598
- });
2630
+ updateFetcherState(key, getDoneFetcher(undefined));
2599
2631
  return;
2600
2632
  }
2601
2633
  if (isRedirectResult(actionResult)) {
@@ -2605,15 +2637,11 @@
2605
2637
  // should take precedence over this redirect navigation. We already
2606
2638
  // set isRevalidationRequired so all loaders for the new route should
2607
2639
  // fire unless opted out via shouldRevalidate
2608
- updateFetcherState(key, getDoneFetcher(undefined), {
2609
- flushSync
2610
- });
2640
+ updateFetcherState(key, getDoneFetcher(undefined));
2611
2641
  return;
2612
2642
  } else {
2613
2643
  fetchRedirectIds.add(key);
2614
- updateFetcherState(key, getLoadingFetcher(submission), {
2615
- flushSync
2616
- });
2644
+ updateFetcherState(key, getLoadingFetcher(submission));
2617
2645
  return startRedirectNavigation(state, actionResult, {
2618
2646
  fetcherSubmission: submission
2619
2647
  });
@@ -2622,9 +2650,7 @@
2622
2650
 
2623
2651
  // Process any non-redirect errors thrown
2624
2652
  if (isErrorResult(actionResult)) {
2625
- setFetcherError(key, routeId, actionResult.error, {
2626
- flushSync
2627
- });
2653
+ setFetcherError(key, routeId, actionResult.error);
2628
2654
  return;
2629
2655
  }
2630
2656
  if (isDeferredResult(actionResult)) {
@@ -2636,7 +2662,7 @@
2636
2662
  // Start the data load for current matches, or the next location if we're
2637
2663
  // in the middle of a navigation
2638
2664
  let nextLocation = state.navigation.location || state.location;
2639
- let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
2665
+ let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal, false);
2640
2666
  let routesToUse = inFlightDataRoutes || dataRoutes;
2641
2667
  let matches = state.navigation.state !== "idle" ? matchRoutes(routesToUse, state.navigation.location, basename) : state.matches;
2642
2668
  invariant(matches, "Didn't find any matches after fetcher action");
@@ -2644,7 +2670,7 @@
2644
2670
  fetchReloadIds.set(key, loadId);
2645
2671
  let loadFetcher = getLoadingFetcher(submission, actionResult.data);
2646
2672
  state.fetchers.set(key, loadFetcher);
2647
- let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, {
2673
+ let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, {
2648
2674
  [match.route.id]: actionResult.data
2649
2675
  }, undefined // No need to send through errors since we short circuit above
2650
2676
  );
@@ -2666,8 +2692,6 @@
2666
2692
  });
2667
2693
  updateState({
2668
2694
  fetchers: new Map(state.fetchers)
2669
- }, {
2670
- flushSync
2671
2695
  });
2672
2696
  let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach(rf => abortFetcher(rf.key));
2673
2697
  abortController.signal.addEventListener("abort", abortPendingFetchRevalidations);
@@ -2729,8 +2753,6 @@
2729
2753
  errors,
2730
2754
  loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
2731
2755
  fetchers: new Map(state.fetchers)
2732
- }, {
2733
- flushSync
2734
2756
  });
2735
2757
  isRevalidationRequired = false;
2736
2758
  }
@@ -2745,7 +2767,7 @@
2745
2767
 
2746
2768
  // Call the loader for this fetcher route match
2747
2769
  let abortController = new AbortController();
2748
- let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
2770
+ let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, false);
2749
2771
  fetchControllers.set(key, abortController);
2750
2772
  let originatingLoadId = incrementingLoadId;
2751
2773
  let result = await callLoaderOrAction("loader", fetchRequest, match, matches, manifest, mapRouteProperties, basename);
@@ -2767,9 +2789,7 @@
2767
2789
  return;
2768
2790
  }
2769
2791
  if (deletedFetchers.has(key)) {
2770
- updateFetcherState(key, getDoneFetcher(undefined), {
2771
- flushSync
2772
- });
2792
+ updateFetcherState(key, getDoneFetcher(undefined));
2773
2793
  return;
2774
2794
  }
2775
2795
 
@@ -2778,9 +2798,7 @@
2778
2798
  if (pendingNavigationLoadId > originatingLoadId) {
2779
2799
  // A new navigation was kicked off after our loader started, so that
2780
2800
  // should take precedence over this redirect navigation
2781
- updateFetcherState(key, getDoneFetcher(undefined), {
2782
- flushSync
2783
- });
2801
+ updateFetcherState(key, getDoneFetcher(undefined));
2784
2802
  return;
2785
2803
  } else {
2786
2804
  fetchRedirectIds.add(key);
@@ -2791,17 +2809,13 @@
2791
2809
 
2792
2810
  // Process any non-redirect errors thrown
2793
2811
  if (isErrorResult(result)) {
2794
- setFetcherError(key, routeId, result.error, {
2795
- flushSync
2796
- });
2812
+ setFetcherError(key, routeId, result.error);
2797
2813
  return;
2798
2814
  }
2799
2815
  invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
2800
2816
 
2801
2817
  // Put the fetcher back into an idle state
2802
- updateFetcherState(key, getDoneFetcher(result.data), {
2803
- flushSync
2804
- });
2818
+ updateFetcherState(key, getDoneFetcher(result.data));
2805
2819
  }
2806
2820
 
2807
2821
  /**
@@ -2823,12 +2837,12 @@
2823
2837
  * actually touch history until we've processed redirects, so we just use
2824
2838
  * the history action from the original navigation (PUSH or REPLACE).
2825
2839
  */
2826
- async function startRedirectNavigation(state, redirect, _temp) {
2840
+ async function startRedirectNavigation(state, redirect, _temp2) {
2827
2841
  let {
2828
2842
  submission,
2829
2843
  fetcherSubmission,
2830
2844
  replace
2831
- } = _temp === void 0 ? {} : _temp;
2845
+ } = _temp2 === void 0 ? {} : _temp2;
2832
2846
  if (redirect.revalidate) {
2833
2847
  isRevalidationRequired = true;
2834
2848
  }
@@ -2906,7 +2920,7 @@
2906
2920
  // accordingly
2907
2921
  let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, manifest, mapRouteProperties, basename)), ...fetchersToLoad.map(f => {
2908
2922
  if (f.matches && f.match && f.controller) {
2909
- return callLoaderOrAction("loader", createClientSideRequest(init.history, f.path, f.controller.signal), f.match, f.matches, manifest, mapRouteProperties, basename);
2923
+ return callLoaderOrAction("loader", createClientSideRequest(init.history, f.path, f.controller.signal, false), f.match, f.matches, manifest, mapRouteProperties, basename);
2910
2924
  } else {
2911
2925
  let error = {
2912
2926
  type: ResultType.error,
@@ -2943,14 +2957,20 @@
2943
2957
  });
2944
2958
  }
2945
2959
  function updateFetcherState(key, fetcher, opts) {
2960
+ if (opts === void 0) {
2961
+ opts = {};
2962
+ }
2946
2963
  state.fetchers.set(key, fetcher);
2947
2964
  updateState({
2948
2965
  fetchers: new Map(state.fetchers)
2949
2966
  }, {
2950
- flushSync: opts.flushSync
2967
+ flushSync: (opts && opts.flushSync) === true
2951
2968
  });
2952
2969
  }
2953
2970
  function setFetcherError(key, routeId, error, opts) {
2971
+ if (opts === void 0) {
2972
+ opts = {};
2973
+ }
2954
2974
  let boundaryMatch = findNearestBoundary(state.matches, routeId);
2955
2975
  deleteFetcher(key);
2956
2976
  updateState({
@@ -2959,7 +2979,7 @@
2959
2979
  },
2960
2980
  fetchers: new Map(state.fetchers)
2961
2981
  }, {
2962
- flushSync: opts.flushSync
2982
+ flushSync: (opts && opts.flushSync) === true
2963
2983
  });
2964
2984
  }
2965
2985
  function getFetcher(key) {
@@ -3001,8 +3021,6 @@
3001
3021
  }
3002
3022
  updateState({
3003
3023
  fetchers: new Map(state.fetchers)
3004
- }, {
3005
- flushSync: false
3006
3024
  });
3007
3025
  }
3008
3026
  function abortFetcher(key) {
@@ -3072,8 +3090,6 @@
3072
3090
  blockers.set(key, newBlocker);
3073
3091
  updateState({
3074
3092
  blockers
3075
- }, {
3076
- flushSync: false
3077
3093
  });
3078
3094
  }
3079
3095
  function shouldBlockNavigation(_ref2) {
@@ -3141,8 +3157,6 @@
3141
3157
  if (y != null) {
3142
3158
  updateState({
3143
3159
  restoreScrollPosition: y
3144
- }, {
3145
- flushSync: false
3146
3160
  });
3147
3161
  }
3148
3162
  }
@@ -3183,6 +3197,9 @@
3183
3197
  get basename() {
3184
3198
  return basename;
3185
3199
  },
3200
+ get future() {
3201
+ return future;
3202
+ },
3186
3203
  get state() {
3187
3204
  return state;
3188
3205
  },
@@ -3259,10 +3276,10 @@
3259
3276
  * propagate that out and return the raw Response so the HTTP server can
3260
3277
  * return it directly.
3261
3278
  */
3262
- async function query(request, _temp2) {
3279
+ async function query(request, _temp3) {
3263
3280
  let {
3264
3281
  requestContext
3265
- } = _temp2 === void 0 ? {} : _temp2;
3282
+ } = _temp3 === void 0 ? {} : _temp3;
3266
3283
  let url = new URL(request.url);
3267
3284
  let method = request.method;
3268
3285
  let location = createLocation("", createPath(url), null, "default");
@@ -3348,11 +3365,11 @@
3348
3365
  * code. Examples here are 404 and 405 errors that occur prior to reaching
3349
3366
  * any user-defined loaders.
3350
3367
  */
3351
- async function queryRoute(request, _temp3) {
3368
+ async function queryRoute(request, _temp4) {
3352
3369
  let {
3353
3370
  routeId,
3354
3371
  requestContext
3355
- } = _temp3 === void 0 ? {} : _temp3;
3372
+ } = _temp4 === void 0 ? {} : _temp4;
3356
3373
  let url = new URL(request.url);
3357
3374
  let method = request.method;
3358
3375
  let location = createLocation("", createPath(url), null, "default");
@@ -3630,11 +3647,9 @@
3630
3647
  function normalizeTo(location, matches, basename, prependBasename, to, fromRouteId, relative) {
3631
3648
  let contextualMatches;
3632
3649
  let activeRouteMatch;
3633
- if (fromRouteId != null && relative !== "path") {
3650
+ if (fromRouteId) {
3634
3651
  // Grab matches up to the calling route so our route-relative logic is
3635
- // relative to the correct source route. When using relative:path,
3636
- // fromRouteId is ignored since that is always relative to the current
3637
- // location path
3652
+ // relative to the correct source route
3638
3653
  contextualMatches = [];
3639
3654
  for (let match of matches) {
3640
3655
  contextualMatches.push(match);
@@ -3649,7 +3664,7 @@
3649
3664
  }
3650
3665
 
3651
3666
  // Resolve the relative path
3652
- let path = resolveTo(to ? to : ".", getPathContributingMatches(contextualMatches).map(m => m.pathnameBase), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
3667
+ let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
3653
3668
 
3654
3669
  // When `to` is not specified we inherit search/hash from the current
3655
3670
  // location, unlike when to="." and we just inherit the path.
@@ -3813,7 +3828,7 @@
3813
3828
  }
3814
3829
  return boundaryMatches;
3815
3830
  }
3816
- function getMatchesToLoad(history, state, matches, submission, location, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionData, pendingError) {
3831
+ function getMatchesToLoad(history, state, matches, submission, location, isInitialLoad, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionData, pendingError) {
3817
3832
  let actionResult = pendingError ? Object.values(pendingError)[0] : pendingActionData ? Object.values(pendingActionData)[0] : undefined;
3818
3833
  let currentUrl = history.createURL(state.location);
3819
3834
  let nextUrl = history.createURL(location);
@@ -3822,6 +3837,11 @@
3822
3837
  let boundaryId = pendingError ? Object.keys(pendingError)[0] : undefined;
3823
3838
  let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
3824
3839
  let navigationMatches = boundaryMatches.filter((match, index) => {
3840
+ if (isInitialLoad) {
3841
+ // On initial hydration we don't do any shouldRevalidate stuff - we just
3842
+ // call the loaders that don't have hydration data
3843
+ return match.route.loader && state.loaderData[match.route.id] === undefined;
3844
+ }
3825
3845
  if (match.route.lazy) {
3826
3846
  // We haven't loaded this route yet so we don't know if it's got a loader!
3827
3847
  return true;
@@ -3861,8 +3881,12 @@
3861
3881
  // Pick fetcher.loads that need to be revalidated
3862
3882
  let revalidatingFetchers = [];
3863
3883
  fetchLoadMatches.forEach((f, key) => {
3864
- // Don't revalidate if fetcher won't be present in the subsequent render
3865
- if (!matches.some(m => m.route.id === f.routeId)) {
3884
+ // Don't revalidate:
3885
+ // - on initial load (shouldn't be any fetchers then anyway)
3886
+ // - if fetcher won't be present in the subsequent render
3887
+ // - no longer matches the URL (v7_fetcherPersist=false)
3888
+ // - was unmounted but persisted due to v7_fetcherPersist=true
3889
+ if (isInitialLoad || !matches.some(m => m.route.id === f.routeId) || deletedFetchers.has(key)) {
3866
3890
  return;
3867
3891
  }
3868
3892
  let fetcherMatches = matchRoutes(routesToUse, f.path, basename);
@@ -4189,11 +4213,16 @@
4189
4213
  // Utility method for creating the Request instances for loaders/actions during
4190
4214
  // client-side navigations and fetches. During SSR we will always have a
4191
4215
  // Request instance from the static handler (query/queryRoute)
4192
- function createClientSideRequest(history, location, signal, submission) {
4216
+ function createClientSideRequest(history, location, signal, initial, submission) {
4193
4217
  let url = history.createURL(stripHashFromPath(location)).toString();
4194
4218
  let init = {
4195
4219
  signal
4196
4220
  };
4221
+ if (initial) {
4222
+ init.headers = {
4223
+ "X-Remix-Initial-Load": "yes"
4224
+ };
4225
+ }
4197
4226
  if (submission && isMutationMethod(submission.formMethod)) {
4198
4227
  let {
4199
4228
  formMethod,
@@ -4401,13 +4430,13 @@
4401
4430
  route
4402
4431
  };
4403
4432
  }
4404
- function getInternalRouterError(status, _temp4) {
4433
+ function getInternalRouterError(status, _temp5) {
4405
4434
  let {
4406
4435
  pathname,
4407
4436
  routeId,
4408
4437
  method,
4409
4438
  type
4410
- } = _temp4 === void 0 ? {} : _temp4;
4439
+ } = _temp5 === void 0 ? {} : _temp5;
4411
4440
  let statusText = "Unknown Server Error";
4412
4441
  let errorMessage = "Unknown @remix-run/router error";
4413
4442
  if (status === 400) {
@@ -4748,7 +4777,7 @@
4748
4777
  exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
4749
4778
  exports.UNSAFE_convertRouteMatchToUiMatch = convertRouteMatchToUiMatch;
4750
4779
  exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
4751
- exports.UNSAFE_getPathContributingMatches = getPathContributingMatches;
4780
+ exports.UNSAFE_getResolveToMatches = getResolveToMatches;
4752
4781
  exports.UNSAFE_invariant = invariant;
4753
4782
  exports.UNSAFE_warning = warning;
4754
4783
  exports.createBrowserHistory = createBrowserHistory;