@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.
package/dist/utils.d.ts CHANGED
@@ -261,7 +261,7 @@ type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _P
261
261
  * "/:a/:b" -> "a" | "b"
262
262
  * "/:a/b/:c/*" -> "a" | "c" | "*"
263
263
  */
264
- type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
264
+ export type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
265
265
  export type ParamParseKey<Segment extends string> = [
266
266
  PathParam<Segment>
267
267
  ] extends [never] ? string : PathParam<Segment>;
@@ -399,6 +399,7 @@ export declare function resolvePath(to: To, fromPathname?: string): Path;
399
399
  * </Route>
400
400
  */
401
401
  export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
402
+ export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): string[];
402
403
  /**
403
404
  * @private
404
405
  */
package/index.ts CHANGED
@@ -20,6 +20,7 @@ export type {
20
20
  ParamParseKey,
21
21
  Params,
22
22
  PathMatch,
23
+ PathParam,
23
24
  PathPattern,
24
25
  RedirectFunction,
25
26
  ShouldRevalidateFunction,
@@ -86,7 +87,7 @@ export {
86
87
  ErrorResponseImpl as UNSAFE_ErrorResponseImpl,
87
88
  convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes,
88
89
  convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch,
89
- getPathContributingMatches as UNSAFE_getPathContributingMatches,
90
+ getResolveToMatches as UNSAFE_getResolveToMatches,
90
91
  } from "./utils";
91
92
 
92
93
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "0.0.0-experimental-e192105b",
3
+ "version": "0.0.0-experimental-178bc9ee",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  convertRouteMatchToUiMatch,
41
41
  convertRoutesToDataRoutes,
42
42
  getPathContributingMatches,
43
+ getResolveToMatches,
43
44
  immutableRouteKeys,
44
45
  isRouteErrorResponse,
45
46
  joinPaths,
@@ -64,6 +65,14 @@ export interface Router {
64
65
  */
65
66
  get basename(): RouterInit["basename"];
66
67
 
68
+ /**
69
+ * @internal
70
+ * PRIVATE - DO NOT USE
71
+ *
72
+ * Return the future config for the router
73
+ */
74
+ get future(): FutureConfig;
75
+
67
76
  /**
68
77
  * @internal
69
78
  * PRIVATE - DO NOT USE
@@ -345,6 +354,7 @@ export type HydrationState = Partial<
345
354
  export interface FutureConfig {
346
355
  v7_fetcherPersist: boolean;
347
356
  v7_normalizeFormMethod: boolean;
357
+ v7_partialHydration: boolean;
348
358
  v7_prependBasename: boolean;
349
359
  }
350
360
 
@@ -411,7 +421,7 @@ export interface RouterSubscriber {
411
421
  opts: {
412
422
  deletedFetchers: string[];
413
423
  unstable_viewTransitionOpts?: ViewTransitionOpts;
414
- unstable_flushSync?: boolean;
424
+ unstable_flushSync: boolean;
415
425
  }
416
426
  ): void;
417
427
  }
@@ -769,6 +779,7 @@ export function createRouter(init: RouterInit): Router {
769
779
  let future: FutureConfig = {
770
780
  v7_fetcherPersist: false,
771
781
  v7_normalizeFormMethod: false,
782
+ v7_partialHydration: false,
772
783
  v7_prependBasename: false,
773
784
  ...init.future,
774
785
  };
@@ -804,12 +815,19 @@ export function createRouter(init: RouterInit): Router {
804
815
  initialErrors = { [route.id]: error };
805
816
  }
806
817
 
818
+ // "Initialized" here really means "Can `RouterProvider` render my route tree?"
819
+ // Prior to `route.Fallback`, we only had a root `fallbackElement` so we used
820
+ // `state.initialized` to render that instead of `<DataRoutes>`. Now that we
821
+ // support route level fallbacks we can always render and we'll just render
822
+ // as deep as we have data for and detect the nearest ancestor Fallback
807
823
  let initialized =
824
+ future.v7_partialHydration ||
808
825
  // All initialMatches need to be loaded before we're ready. If we have lazy
809
826
  // functions around still then we'll need to run them in initialize()
810
- !initialMatches.some((m) => m.route.lazy) &&
811
- // And we have to either have no loaders or have been provided hydrationData
812
- (!initialMatches.some((m) => m.route.loader) || init.hydrationData != null);
827
+ (!initialMatches.some((m) => m.route.lazy) &&
828
+ // And we have to either have no loaders or have been provided hydrationData
829
+ (!initialMatches.some((m) => m.route.loader) ||
830
+ init.hydrationData != null));
813
831
 
814
832
  let router: Router;
815
833
  let state: RouterState = {
@@ -843,9 +861,6 @@ export function createRouter(init: RouterInit): Router {
843
861
  // Should the current navigation enable document.startViewTransition?
844
862
  let pendingViewTransitionEnabled = false;
845
863
 
846
- // Should the current navigation use flushSync for state updates?
847
- let pendingFlushSync = false;
848
-
849
864
  // Store applied view transitions so we can apply them on POP
850
865
  let appliedViewTransitions: Map<string, Set<string>> = new Map<
851
866
  string,
@@ -967,7 +982,7 @@ export function createRouter(init: RouterInit): Router {
967
982
  reset() {
968
983
  let blockers = new Map(state.blockers);
969
984
  blockers.set(blockerKey!, IDLE_BLOCKER);
970
- updateState({ blockers }, { flushSync: false });
985
+ updateState({ blockers });
971
986
  },
972
987
  });
973
988
  return;
@@ -993,8 +1008,16 @@ export function createRouter(init: RouterInit): Router {
993
1008
  // in the normal navigation flow. For SSR it's expected that lazy modules are
994
1009
  // resolved prior to router creation since we can't go into a fallbackElement
995
1010
  // UI for SSR'd apps
996
- if (!state.initialized) {
997
- startNavigation(HistoryAction.Pop, state.location);
1011
+ if (
1012
+ !state.initialized ||
1013
+ (future.v7_partialHydration &&
1014
+ state.matches.some(
1015
+ (m) => m.route.loader && state.loaderData[m.route.id] === undefined
1016
+ ))
1017
+ ) {
1018
+ startNavigation(HistoryAction.Pop, state.location, {
1019
+ initialHydration: true,
1020
+ });
998
1021
  }
999
1022
 
1000
1023
  return router;
@@ -1024,9 +1047,9 @@ export function createRouter(init: RouterInit): Router {
1024
1047
  function updateState(
1025
1048
  newState: Partial<RouterState>,
1026
1049
  opts: {
1027
- flushSync: boolean;
1050
+ flushSync?: boolean;
1028
1051
  viewTransitionOpts?: ViewTransitionOpts;
1029
- }
1052
+ } = {}
1030
1053
  ): void {
1031
1054
  state = {
1032
1055
  ...state,
@@ -1060,7 +1083,7 @@ export function createRouter(init: RouterInit): Router {
1060
1083
  subscriber(state, {
1061
1084
  deletedFetchers: deletedFetchersKeys,
1062
1085
  unstable_viewTransitionOpts: opts.viewTransitionOpts,
1063
- unstable_flushSync: opts.flushSync,
1086
+ unstable_flushSync: opts.flushSync === true,
1064
1087
  })
1065
1088
  );
1066
1089
 
@@ -1078,7 +1101,8 @@ export function createRouter(init: RouterInit): Router {
1078
1101
  // - Can pass any other state in newState
1079
1102
  function completeNavigation(
1080
1103
  location: Location,
1081
- newState: Partial<Omit<RouterState, "action" | "location" | "navigation">>
1104
+ newState: Partial<Omit<RouterState, "action" | "location" | "navigation">>,
1105
+ { flushSync }: { flushSync?: boolean } = {}
1082
1106
  ): void {
1083
1107
  // Deduce if we're in a loading/actionReload state:
1084
1108
  // - We have committed actionData in the store
@@ -1202,7 +1226,7 @@ export function createRouter(init: RouterInit): Router {
1202
1226
  },
1203
1227
  {
1204
1228
  viewTransitionOpts,
1205
- flushSync: pendingFlushSync,
1229
+ flushSync: flushSync === true,
1206
1230
  }
1207
1231
  );
1208
1232
 
@@ -1210,7 +1234,6 @@ export function createRouter(init: RouterInit): Router {
1210
1234
  pendingAction = HistoryAction.Pop;
1211
1235
  pendingPreventScrollReset = false;
1212
1236
  pendingViewTransitionEnabled = false;
1213
- pendingFlushSync = false;
1214
1237
  isUninterruptedRevalidation = false;
1215
1238
  isRevalidationRequired = false;
1216
1239
  cancelledDeferredRoutes = [];
@@ -1308,7 +1331,7 @@ export function createRouter(init: RouterInit): Router {
1308
1331
  reset() {
1309
1332
  let blockers = new Map(state.blockers);
1310
1333
  blockers.set(blockerKey!, IDLE_BLOCKER);
1311
- updateState({ blockers }, { flushSync });
1334
+ updateState({ blockers });
1312
1335
  },
1313
1336
  });
1314
1337
  return;
@@ -1331,7 +1354,7 @@ export function createRouter(init: RouterInit): Router {
1331
1354
  // loaders during the next loader round
1332
1355
  function revalidate() {
1333
1356
  interruptActiveLoads();
1334
- updateState({ revalidation: "loading" }, { flushSync: false });
1357
+ updateState({ revalidation: "loading" });
1335
1358
 
1336
1359
  // If we're currently submitting an action, we don't need to start a new
1337
1360
  // navigation, we'll just let the follow up loader execution call all loaders
@@ -1366,6 +1389,7 @@ export function createRouter(init: RouterInit): Router {
1366
1389
  historyAction: HistoryAction,
1367
1390
  location: Location,
1368
1391
  opts?: {
1392
+ initialHydration?: boolean;
1369
1393
  submission?: Submission;
1370
1394
  fetcherSubmission?: Submission;
1371
1395
  overrideNavigation?: Navigation;
@@ -1392,11 +1416,11 @@ export function createRouter(init: RouterInit): Router {
1392
1416
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
1393
1417
 
1394
1418
  pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
1395
- pendingFlushSync = (opts && opts.flushSync) === true;
1396
1419
 
1397
1420
  let routesToUse = inFlightDataRoutes || dataRoutes;
1398
1421
  let loadingNavigation = opts && opts.overrideNavigation;
1399
1422
  let matches = matchRoutes(routesToUse, location, basename);
1423
+ let flushSync = (opts && opts.flushSync) === true;
1400
1424
 
1401
1425
  // Short circuit with a 404 on the root error boundary if we match nothing
1402
1426
  if (!matches) {
@@ -1405,13 +1429,17 @@ export function createRouter(init: RouterInit): Router {
1405
1429
  getShortCircuitMatches(routesToUse);
1406
1430
  // Cancel all pending deferred on 404s since we don't keep any routes
1407
1431
  cancelActiveDeferreds();
1408
- completeNavigation(location, {
1409
- matches: notFoundMatches,
1410
- loaderData: {},
1411
- errors: {
1412
- [route.id]: error,
1432
+ completeNavigation(
1433
+ location,
1434
+ {
1435
+ matches: notFoundMatches,
1436
+ loaderData: {},
1437
+ errors: {
1438
+ [route.id]: error,
1439
+ },
1413
1440
  },
1414
- });
1441
+ { flushSync }
1442
+ );
1415
1443
  return;
1416
1444
  }
1417
1445
 
@@ -1427,7 +1455,7 @@ export function createRouter(init: RouterInit): Router {
1427
1455
  isHashChangeOnly(state.location, location) &&
1428
1456
  !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))
1429
1457
  ) {
1430
- completeNavigation(location, { matches });
1458
+ completeNavigation(location, { matches }, { flushSync });
1431
1459
  return;
1432
1460
  }
1433
1461
 
@@ -1437,6 +1465,7 @@ export function createRouter(init: RouterInit): Router {
1437
1465
  init.history,
1438
1466
  location,
1439
1467
  pendingNavigationController.signal,
1468
+ opts && opts.initialHydration === true,
1440
1469
  opts && opts.submission
1441
1470
  );
1442
1471
  let pendingActionData: RouteData | undefined;
@@ -1461,7 +1490,7 @@ export function createRouter(init: RouterInit): Router {
1461
1490
  location,
1462
1491
  opts.submission,
1463
1492
  matches,
1464
- { replace: opts.replace }
1493
+ { replace: opts.replace, flushSync }
1465
1494
  );
1466
1495
 
1467
1496
  if (actionOutput.shortCircuited) {
@@ -1471,6 +1500,7 @@ export function createRouter(init: RouterInit): Router {
1471
1500
  pendingActionData = actionOutput.pendingActionData;
1472
1501
  pendingError = actionOutput.pendingActionError;
1473
1502
  loadingNavigation = getLoadingNavigation(location, opts.submission);
1503
+ flushSync = false;
1474
1504
 
1475
1505
  // Create a GET request for the loaders
1476
1506
  request = new Request(request.url, { signal: request.signal });
@@ -1485,6 +1515,8 @@ export function createRouter(init: RouterInit): Router {
1485
1515
  opts && opts.submission,
1486
1516
  opts && opts.fetcherSubmission,
1487
1517
  opts && opts.replace,
1518
+ opts && opts.initialHydration === true,
1519
+ flushSync,
1488
1520
  pendingActionData,
1489
1521
  pendingError
1490
1522
  );
@@ -1513,13 +1545,13 @@ export function createRouter(init: RouterInit): Router {
1513
1545
  location: Location,
1514
1546
  submission: Submission,
1515
1547
  matches: AgnosticDataRouteMatch[],
1516
- opts: { replace?: boolean } = {}
1548
+ opts: { replace?: boolean; flushSync?: boolean } = {}
1517
1549
  ): Promise<HandleActionResult> {
1518
1550
  interruptActiveLoads();
1519
1551
 
1520
1552
  // Put us in a submitting state
1521
1553
  let navigation = getSubmittingNavigation(location, submission);
1522
- updateState({ navigation }, { flushSync: pendingFlushSync });
1554
+ updateState({ navigation }, { flushSync: opts.flushSync === true });
1523
1555
 
1524
1556
  // Call our action and get the result
1525
1557
  let result: DataResult;
@@ -1604,6 +1636,8 @@ export function createRouter(init: RouterInit): Router {
1604
1636
  submission?: Submission,
1605
1637
  fetcherSubmission?: Submission,
1606
1638
  replace?: boolean,
1639
+ initialHydration?: boolean,
1640
+ flushSync?: boolean,
1607
1641
  pendingActionData?: RouteData,
1608
1642
  pendingError?: RouteData
1609
1643
  ): Promise<HandleLoadersResult> {
@@ -1625,9 +1659,11 @@ export function createRouter(init: RouterInit): Router {
1625
1659
  matches,
1626
1660
  activeSubmission,
1627
1661
  location,
1662
+ future.v7_partialHydration && initialHydration === true,
1628
1663
  isRevalidationRequired,
1629
1664
  cancelledDeferredRoutes,
1630
1665
  cancelledFetcherLoads,
1666
+ deletedFetchers,
1631
1667
  fetchLoadMatches,
1632
1668
  fetchRedirectIds,
1633
1669
  routesToUse,
@@ -1650,14 +1686,18 @@ export function createRouter(init: RouterInit): Router {
1650
1686
  // Short circuit if we have no loaders to run
1651
1687
  if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) {
1652
1688
  let updatedFetchers = markFetchRedirectsDone();
1653
- completeNavigation(location, {
1654
- matches,
1655
- loaderData: {},
1656
- // Commit pending error if we're short circuiting
1657
- errors: pendingError || null,
1658
- ...(pendingActionData ? { actionData: pendingActionData } : {}),
1659
- ...(updatedFetchers ? { fetchers: new Map(state.fetchers) } : {}),
1660
- });
1689
+ completeNavigation(
1690
+ location,
1691
+ {
1692
+ matches,
1693
+ loaderData: {},
1694
+ // Commit pending error if we're short circuiting
1695
+ errors: pendingError || null,
1696
+ ...(pendingActionData ? { actionData: pendingActionData } : {}),
1697
+ ...(updatedFetchers ? { fetchers: new Map(state.fetchers) } : {}),
1698
+ },
1699
+ { flushSync }
1700
+ );
1661
1701
  return { shortCircuited: true };
1662
1702
  }
1663
1703
 
@@ -1688,7 +1728,7 @@ export function createRouter(init: RouterInit): Router {
1688
1728
  : {}),
1689
1729
  },
1690
1730
  {
1691
- flushSync: pendingFlushSync,
1731
+ flushSync,
1692
1732
  }
1693
1733
  );
1694
1734
  }
@@ -1909,6 +1949,7 @@ export function createRouter(init: RouterInit): Router {
1909
1949
  init.history,
1910
1950
  path,
1911
1951
  abortController.signal,
1952
+ false,
1912
1953
  submission
1913
1954
  );
1914
1955
  fetchControllers.set(key, abortController);
@@ -1934,7 +1975,7 @@ export function createRouter(init: RouterInit): Router {
1934
1975
  }
1935
1976
 
1936
1977
  if (deletedFetchers.has(key)) {
1937
- updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
1978
+ updateFetcherState(key, getDoneFetcher(undefined));
1938
1979
  return;
1939
1980
  }
1940
1981
 
@@ -1945,11 +1986,11 @@ export function createRouter(init: RouterInit): Router {
1945
1986
  // should take precedence over this redirect navigation. We already
1946
1987
  // set isRevalidationRequired so all loaders for the new route should
1947
1988
  // fire unless opted out via shouldRevalidate
1948
- updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
1989
+ updateFetcherState(key, getDoneFetcher(undefined));
1949
1990
  return;
1950
1991
  } else {
1951
1992
  fetchRedirectIds.add(key);
1952
- updateFetcherState(key, getLoadingFetcher(submission), { flushSync });
1993
+ updateFetcherState(key, getLoadingFetcher(submission));
1953
1994
  return startRedirectNavigation(state, actionResult, {
1954
1995
  fetcherSubmission: submission,
1955
1996
  });
@@ -1958,7 +1999,7 @@ export function createRouter(init: RouterInit): Router {
1958
1999
 
1959
2000
  // Process any non-redirect errors thrown
1960
2001
  if (isErrorResult(actionResult)) {
1961
- setFetcherError(key, routeId, actionResult.error, { flushSync });
2002
+ setFetcherError(key, routeId, actionResult.error);
1962
2003
  return;
1963
2004
  }
1964
2005
 
@@ -1972,7 +2013,8 @@ export function createRouter(init: RouterInit): Router {
1972
2013
  let revalidationRequest = createClientSideRequest(
1973
2014
  init.history,
1974
2015
  nextLocation,
1975
- abortController.signal
2016
+ abortController.signal,
2017
+ false
1976
2018
  );
1977
2019
  let routesToUse = inFlightDataRoutes || dataRoutes;
1978
2020
  let matches =
@@ -1994,9 +2036,11 @@ export function createRouter(init: RouterInit): Router {
1994
2036
  matches,
1995
2037
  submission,
1996
2038
  nextLocation,
2039
+ false,
1997
2040
  isRevalidationRequired,
1998
2041
  cancelledDeferredRoutes,
1999
2042
  cancelledFetcherLoads,
2043
+ deletedFetchers,
2000
2044
  fetchLoadMatches,
2001
2045
  fetchRedirectIds,
2002
2046
  routesToUse,
@@ -2026,7 +2070,7 @@ export function createRouter(init: RouterInit): Router {
2026
2070
  }
2027
2071
  });
2028
2072
 
2029
- updateState({ fetchers: new Map(state.fetchers) }, { flushSync });
2073
+ updateState({ fetchers: new Map(state.fetchers) });
2030
2074
 
2031
2075
  let abortPendingFetchRevalidations = () =>
2032
2076
  revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
@@ -2112,19 +2156,16 @@ export function createRouter(init: RouterInit): Router {
2112
2156
  // otherwise just update with the fetcher data, preserving any existing
2113
2157
  // loaderData for loaders that did not need to reload. We have to
2114
2158
  // manually merge here since we aren't going through completeNavigation
2115
- updateState(
2116
- {
2117
- errors,
2118
- loaderData: mergeLoaderData(
2119
- state.loaderData,
2120
- loaderData,
2121
- matches,
2122
- errors
2123
- ),
2124
- fetchers: new Map(state.fetchers),
2125
- },
2126
- { flushSync }
2127
- );
2159
+ updateState({
2160
+ errors,
2161
+ loaderData: mergeLoaderData(
2162
+ state.loaderData,
2163
+ loaderData,
2164
+ matches,
2165
+ errors
2166
+ ),
2167
+ fetchers: new Map(state.fetchers),
2168
+ });
2128
2169
  isRevalidationRequired = false;
2129
2170
  }
2130
2171
  }
@@ -2154,7 +2195,8 @@ export function createRouter(init: RouterInit): Router {
2154
2195
  let fetchRequest = createClientSideRequest(
2155
2196
  init.history,
2156
2197
  path,
2157
- abortController.signal
2198
+ abortController.signal,
2199
+ false
2158
2200
  );
2159
2201
  fetchControllers.set(key, abortController);
2160
2202
 
@@ -2190,7 +2232,7 @@ export function createRouter(init: RouterInit): Router {
2190
2232
  }
2191
2233
 
2192
2234
  if (deletedFetchers.has(key)) {
2193
- updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
2235
+ updateFetcherState(key, getDoneFetcher(undefined));
2194
2236
  return;
2195
2237
  }
2196
2238
 
@@ -2199,7 +2241,7 @@ export function createRouter(init: RouterInit): Router {
2199
2241
  if (pendingNavigationLoadId > originatingLoadId) {
2200
2242
  // A new navigation was kicked off after our loader started, so that
2201
2243
  // should take precedence over this redirect navigation
2202
- updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
2244
+ updateFetcherState(key, getDoneFetcher(undefined));
2203
2245
  return;
2204
2246
  } else {
2205
2247
  fetchRedirectIds.add(key);
@@ -2210,14 +2252,14 @@ export function createRouter(init: RouterInit): Router {
2210
2252
 
2211
2253
  // Process any non-redirect errors thrown
2212
2254
  if (isErrorResult(result)) {
2213
- setFetcherError(key, routeId, result.error, { flushSync });
2255
+ setFetcherError(key, routeId, result.error);
2214
2256
  return;
2215
2257
  }
2216
2258
 
2217
2259
  invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
2218
2260
 
2219
2261
  // Put the fetcher back into an idle state
2220
- updateFetcherState(key, getDoneFetcher(result.data), { flushSync });
2262
+ updateFetcherState(key, getDoneFetcher(result.data));
2221
2263
  }
2222
2264
 
2223
2265
  /**
@@ -2369,7 +2411,12 @@ export function createRouter(init: RouterInit): Router {
2369
2411
  if (f.matches && f.match && f.controller) {
2370
2412
  return callLoaderOrAction(
2371
2413
  "loader",
2372
- createClientSideRequest(init.history, f.path, f.controller.signal),
2414
+ createClientSideRequest(
2415
+ init.history,
2416
+ f.path,
2417
+ f.controller.signal,
2418
+ false
2419
+ ),
2373
2420
  f.match,
2374
2421
  f.matches,
2375
2422
  manifest,
@@ -2429,12 +2476,12 @@ export function createRouter(init: RouterInit): Router {
2429
2476
  function updateFetcherState(
2430
2477
  key: string,
2431
2478
  fetcher: Fetcher,
2432
- opts: { flushSync: boolean }
2479
+ opts: { flushSync?: boolean } = {}
2433
2480
  ) {
2434
2481
  state.fetchers.set(key, fetcher);
2435
2482
  updateState(
2436
2483
  { fetchers: new Map(state.fetchers) },
2437
- { flushSync: opts.flushSync }
2484
+ { flushSync: (opts && opts.flushSync) === true }
2438
2485
  );
2439
2486
  }
2440
2487
 
@@ -2442,7 +2489,7 @@ export function createRouter(init: RouterInit): Router {
2442
2489
  key: string,
2443
2490
  routeId: string,
2444
2491
  error: any,
2445
- opts: { flushSync: boolean }
2492
+ opts: { flushSync?: boolean } = {}
2446
2493
  ) {
2447
2494
  let boundaryMatch = findNearestBoundary(state.matches, routeId);
2448
2495
  deleteFetcher(key);
@@ -2453,7 +2500,7 @@ export function createRouter(init: RouterInit): Router {
2453
2500
  },
2454
2501
  fetchers: new Map(state.fetchers),
2455
2502
  },
2456
- { flushSync: opts.flushSync }
2503
+ { flushSync: (opts && opts.flushSync) === true }
2457
2504
  );
2458
2505
  }
2459
2506
 
@@ -2499,7 +2546,7 @@ export function createRouter(init: RouterInit): Router {
2499
2546
  } else {
2500
2547
  deleteFetcher(key);
2501
2548
  }
2502
- updateState({ fetchers: new Map(state.fetchers) }, { flushSync: false });
2549
+ updateState({ fetchers: new Map(state.fetchers) });
2503
2550
  }
2504
2551
 
2505
2552
  function abortFetcher(key: string) {
@@ -2582,7 +2629,7 @@ export function createRouter(init: RouterInit): Router {
2582
2629
 
2583
2630
  let blockers = new Map(state.blockers);
2584
2631
  blockers.set(key, newBlocker);
2585
- updateState({ blockers }, { flushSync: false });
2632
+ updateState({ blockers });
2586
2633
  }
2587
2634
 
2588
2635
  function shouldBlockNavigation({
@@ -2656,7 +2703,7 @@ export function createRouter(init: RouterInit): Router {
2656
2703
  initialScrollRestored = true;
2657
2704
  let y = getSavedScrollPosition(state.location, state.matches);
2658
2705
  if (y != null) {
2659
- updateState({ restoreScrollPosition: y }, { flushSync: false });
2706
+ updateState({ restoreScrollPosition: y });
2660
2707
  }
2661
2708
  }
2662
2709
 
@@ -2716,6 +2763,9 @@ export function createRouter(init: RouterInit): Router {
2716
2763
  get basename() {
2717
2764
  return basename;
2718
2765
  },
2766
+ get future() {
2767
+ return future;
2768
+ },
2719
2769
  get state() {
2720
2770
  return state;
2721
2771
  },
@@ -3314,11 +3364,9 @@ function normalizeTo(
3314
3364
  ) {
3315
3365
  let contextualMatches: AgnosticDataRouteMatch[];
3316
3366
  let activeRouteMatch: AgnosticDataRouteMatch | undefined;
3317
- if (fromRouteId != null && relative !== "path") {
3367
+ if (fromRouteId) {
3318
3368
  // Grab matches up to the calling route so our route-relative logic is
3319
- // relative to the correct source route. When using relative:path,
3320
- // fromRouteId is ignored since that is always relative to the current
3321
- // location path
3369
+ // relative to the correct source route
3322
3370
  contextualMatches = [];
3323
3371
  for (let match of matches) {
3324
3372
  contextualMatches.push(match);
@@ -3335,7 +3383,7 @@ function normalizeTo(
3335
3383
  // Resolve the relative path
3336
3384
  let path = resolveTo(
3337
3385
  to ? to : ".",
3338
- getPathContributingMatches(contextualMatches).map((m) => m.pathnameBase),
3386
+ getResolveToMatches(contextualMatches),
3339
3387
  stripBasename(location.pathname, basename) || location.pathname,
3340
3388
  relative === "path"
3341
3389
  );
@@ -3543,9 +3591,11 @@ function getMatchesToLoad(
3543
3591
  matches: AgnosticDataRouteMatch[],
3544
3592
  submission: Submission | undefined,
3545
3593
  location: Location,
3594
+ isInitialLoad: boolean,
3546
3595
  isRevalidationRequired: boolean,
3547
3596
  cancelledDeferredRoutes: string[],
3548
3597
  cancelledFetcherLoads: string[],
3598
+ deletedFetchers: Set<string>,
3549
3599
  fetchLoadMatches: Map<string, FetchLoadMatch>,
3550
3600
  fetchRedirectIds: Set<string>,
3551
3601
  routesToUse: AgnosticDataRouteObject[],
@@ -3567,6 +3617,13 @@ function getMatchesToLoad(
3567
3617
  let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
3568
3618
 
3569
3619
  let navigationMatches = boundaryMatches.filter((match, index) => {
3620
+ if (isInitialLoad) {
3621
+ // On initial hydration we don't do any shouldRevalidate stuff - we just
3622
+ // call the loaders that don't have hydration data
3623
+ return (
3624
+ match.route.loader && state.loaderData[match.route.id] === undefined
3625
+ );
3626
+ }
3570
3627
  if (match.route.lazy) {
3571
3628
  // We haven't loaded this route yet so we don't know if it's got a loader!
3572
3629
  return true;
@@ -3612,8 +3669,16 @@ function getMatchesToLoad(
3612
3669
  // Pick fetcher.loads that need to be revalidated
3613
3670
  let revalidatingFetchers: RevalidatingFetcher[] = [];
3614
3671
  fetchLoadMatches.forEach((f, key) => {
3615
- // Don't revalidate if fetcher won't be present in the subsequent render
3616
- if (!matches.some((m) => m.route.id === f.routeId)) {
3672
+ // Don't revalidate:
3673
+ // - on initial load (shouldn't be any fetchers then anyway)
3674
+ // - if fetcher won't be present in the subsequent render
3675
+ // - no longer matches the URL (v7_fetcherPersist=false)
3676
+ // - was unmounted but persisted due to v7_fetcherPersist=true
3677
+ if (
3678
+ isInitialLoad ||
3679
+ !matches.some((m) => m.route.id === f.routeId) ||
3680
+ deletedFetchers.has(key)
3681
+ ) {
3617
3682
  return;
3618
3683
  }
3619
3684
 
@@ -4029,11 +4094,16 @@ function createClientSideRequest(
4029
4094
  history: History,
4030
4095
  location: string | Location,
4031
4096
  signal: AbortSignal,
4097
+ initial?: boolean,
4032
4098
  submission?: Submission
4033
4099
  ): Request {
4034
4100
  let url = history.createURL(stripHashFromPath(location)).toString();
4035
4101
  let init: RequestInit = { signal };
4036
4102
 
4103
+ if (initial) {
4104
+ init.headers = { "X-Remix-Initial-Load": "yes" };
4105
+ }
4106
+
4037
4107
  if (submission && isMutationMethod(submission.formMethod)) {
4038
4108
  let { formMethod, formEncType } = submission;
4039
4109
  // Didn't think we needed this but it turns out unlike other methods, patch