@remix-run/router 0.0.0-experimental-db3389095 → 0.0.0-experimental-e6fb6e074

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/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-db3389095
2
+ * @remix-run/router v0.0.0-experimental-e6fb6e074
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1398,6 +1398,7 @@ function createRouter(init) {
1398
1398
  // SSR did the initial scroll restoration.
1399
1399
  let initialScrollRestored = init.hydrationData != null;
1400
1400
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
1401
+ let initialMatchesIsFOW = false;
1401
1402
  let initialErrors = null;
1402
1403
  if (initialMatches == null && !patchRoutesOnNavigationImpl) {
1403
1404
  // If we do not match a user-provided-route, fall back to the root
@@ -1436,6 +1437,7 @@ function createRouter(init) {
1436
1437
  if (future.v7_partialHydration) {
1437
1438
  let fogOfWar = checkFogOfWar(null, dataRoutes, init.history.location.pathname);
1438
1439
  if (fogOfWar.active && fogOfWar.matches) {
1440
+ initialMatchesIsFOW = true;
1439
1441
  initialMatches = fogOfWar.matches;
1440
1442
  }
1441
1443
  }
@@ -1638,13 +1640,9 @@ function createRouter(init) {
1638
1640
  }
1639
1641
  // Update our state and notify the calling context of the change
1640
1642
  function updateState(newState, opts) {
1641
- var _newState$navigation;
1642
1643
  if (opts === void 0) {
1643
1644
  opts = {};
1644
1645
  }
1645
- console.log("updateState()", opts.viewTransitionOpts);
1646
- console.log(" navigation change", state.navigation.state, "->", (_newState$navigation = newState.navigation) == null ? void 0 : _newState$navigation.state);
1647
- console.log(" revalidation change", state.revalidation, "->", newState.revalidation);
1648
1646
  state = _extends({}, state, newState);
1649
1647
  // Prep fetcher cleanup so we can tell the UI which fetcher data entries
1650
1648
  // can be removed
@@ -1800,7 +1798,6 @@ function createRouter(init) {
1800
1798
  // Trigger a navigation event, which can either be a numerical POP or a PUSH
1801
1799
  // replace with an optional submission
1802
1800
  async function navigate(to, opts) {
1803
- console.log("navigate()", to, JSON.stringify(state.navigation));
1804
1801
  if (typeof to === "number") {
1805
1802
  init.history.go(to);
1806
1803
  return;
@@ -1877,8 +1874,6 @@ function createRouter(init) {
1877
1874
  // is interrupted by a navigation, allow this to "succeed" by calling all
1878
1875
  // loaders during the next loader round
1879
1876
  function revalidate() {
1880
- console.log("revalidate()");
1881
- console.log(" current navigation", JSON.stringify(state.navigation));
1882
1877
  interruptActiveLoads();
1883
1878
  updateState({
1884
1879
  revalidation: "loading"
@@ -1892,7 +1887,6 @@ function createRouter(init) {
1892
1887
  // action/location and mark it as uninterrupted, which will skip the history
1893
1888
  // update in completeNavigation
1894
1889
  if (state.navigation.state === "idle") {
1895
- console.log("startNavigation() - startUninterruptedRevalidation=true");
1896
1890
  startNavigation(state.historyAction, state.location, {
1897
1891
  startUninterruptedRevalidation: true
1898
1892
  });
@@ -1901,9 +1895,6 @@ function createRouter(init) {
1901
1895
  // Otherwise, if we're currently in a loading state, just start a new
1902
1896
  // navigation to the navigation.location but do not trigger an uninterrupted
1903
1897
  // revalidation so that history correctly updates once the navigation completes
1904
- console.log("startNavigation() - interrupting", {
1905
- pendingViewTransitionEnabled
1906
- });
1907
1898
  startNavigation(pendingAction || state.historyAction, state.navigation.location, {
1908
1899
  overrideNavigation: state.navigation,
1909
1900
  // Proxy through any rending view transition
@@ -1928,8 +1919,24 @@ function createRouter(init) {
1928
1919
  pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
1929
1920
  let routesToUse = inFlightDataRoutes || dataRoutes;
1930
1921
  let loadingNavigation = opts && opts.overrideNavigation;
1931
- let matches = matchRoutes(routesToUse, location, basename);
1922
+ let matches = opts != null && opts.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ?
1923
+ // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1924
+ state.matches : matchRoutes(routesToUse, location, basename);
1932
1925
  let flushSync = (opts && opts.flushSync) === true;
1926
+ // Short circuit if it's only a hash change and not a revalidation or
1927
+ // mutation submission.
1928
+ //
1929
+ // Ignore on initial page loads because since the initial hydration will always
1930
+ // be "same hash". For example, on /page#hash and submit a <Form method="post">
1931
+ // which will default to a navigation to /page
1932
+ if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1933
+ completeNavigation(location, {
1934
+ matches
1935
+ }, {
1936
+ flushSync
1937
+ });
1938
+ return;
1939
+ }
1933
1940
  let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
1934
1941
  if (fogOfWar.active && fogOfWar.matches) {
1935
1942
  matches = fogOfWar.matches;
@@ -1952,20 +1959,6 @@ function createRouter(init) {
1952
1959
  });
1953
1960
  return;
1954
1961
  }
1955
- // Short circuit if it's only a hash change and not a revalidation or
1956
- // mutation submission.
1957
- //
1958
- // Ignore on initial page loads because since the initial hydration will always
1959
- // be "same hash". For example, on /page#hash and submit a <Form method="post">
1960
- // which will default to a navigation to /page
1961
- if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1962
- completeNavigation(location, {
1963
- matches
1964
- }, {
1965
- flushSync
1966
- });
1967
- return;
1968
- }
1969
1962
  // Create a controller/Request for this navigation
1970
1963
  pendingNavigationController = new AbortController();
1971
1964
  let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.submission);
@@ -2014,16 +2007,13 @@ function createRouter(init) {
2014
2007
  request = createClientSideRequest(init.history, request.url, request.signal);
2015
2008
  }
2016
2009
  // Call loaders
2017
- console.log(" start handleLoaders()");
2018
2010
  let {
2019
2011
  shortCircuited,
2020
2012
  matches: updatedMatches,
2021
2013
  loaderData,
2022
2014
  errors
2023
2015
  } = await handleLoaders(request, location, matches, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult);
2024
- console.log(" end handleLoaders()");
2025
2016
  if (shortCircuited) {
2026
- console.log(" short circuited from handleLoaders()");
2027
2017
  return;
2028
2018
  }
2029
2019
  // Clean up now that the action/loaders have completed. Don't clean up if
@@ -2440,7 +2430,7 @@ function createRouter(init) {
2440
2430
  let abortController = new AbortController();
2441
2431
  let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
2442
2432
  if (isFogOfWar) {
2443
- let discoverResult = await discoverRoutes(requestMatches, path, fetchRequest.signal);
2433
+ let discoverResult = await discoverRoutes(requestMatches, new URL(fetchRequest.url).pathname, fetchRequest.signal, key);
2444
2434
  if (discoverResult.type === "aborted") {
2445
2435
  return;
2446
2436
  } else if (discoverResult.type === "error") {
@@ -2617,7 +2607,7 @@ function createRouter(init) {
2617
2607
  let abortController = new AbortController();
2618
2608
  let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
2619
2609
  if (isFogOfWar) {
2620
- let discoverResult = await discoverRoutes(matches, path, fetchRequest.signal);
2610
+ let discoverResult = await discoverRoutes(matches, new URL(fetchRequest.url).pathname, fetchRequest.signal, key);
2621
2611
  if (discoverResult.type === "aborted") {
2622
2612
  return;
2623
2613
  } else if (discoverResult.type === "error") {
@@ -3138,7 +3128,7 @@ function createRouter(init) {
3138
3128
  matches: null
3139
3129
  };
3140
3130
  }
3141
- async function discoverRoutes(matches, pathname, signal) {
3131
+ async function discoverRoutes(matches, pathname, signal, fetcherKey) {
3142
3132
  if (!patchRoutesOnNavigationImpl) {
3143
3133
  return {
3144
3134
  type: "success",
@@ -3152,8 +3142,10 @@ function createRouter(init) {
3152
3142
  let localManifest = manifest;
3153
3143
  try {
3154
3144
  await patchRoutesOnNavigationImpl({
3145
+ signal,
3155
3146
  path: pathname,
3156
3147
  matches: partialMatches,
3148
+ fetcherKey,
3157
3149
  patch: (routeId, children) => {
3158
3150
  if (signal.aborted) return;
3159
3151
  patchRoutesImpl(routeId, children, routesToUse, localManifest, mapRouteProperties);
@@ -4364,17 +4356,23 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4364
4356
  }
4365
4357
  if (type === ResultType.error) {
4366
4358
  if (isDataWithResponseInit(result)) {
4367
- var _result$init2;
4359
+ var _result$init3, _result$init4;
4368
4360
  if (result.data instanceof Error) {
4369
- var _result$init;
4361
+ var _result$init, _result$init2;
4370
4362
  return {
4371
4363
  type: ResultType.error,
4372
4364
  error: result.data,
4373
- statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status
4365
+ statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status,
4366
+ headers: (_result$init2 = result.init) != null && _result$init2.headers ? new Headers(result.init.headers) : undefined
4374
4367
  };
4375
4368
  }
4376
4369
  // Convert thrown data() to ErrorResponse instances
4377
- result = new ErrorResponseImpl(((_result$init2 = result.init) == null ? void 0 : _result$init2.status) || 500, undefined, result.data);
4370
+ return {
4371
+ type: ResultType.error,
4372
+ error: new ErrorResponseImpl(((_result$init3 = result.init) == null ? void 0 : _result$init3.status) || 500, undefined, result.data),
4373
+ statusCode: isRouteErrorResponse(result) ? result.status : undefined,
4374
+ headers: (_result$init4 = result.init) != null && _result$init4.headers ? new Headers(result.init.headers) : undefined
4375
+ };
4378
4376
  }
4379
4377
  return {
4380
4378
  type: ResultType.error,
@@ -4383,21 +4381,21 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4383
4381
  };
4384
4382
  }
4385
4383
  if (isDeferredData(result)) {
4386
- var _result$init3, _result$init4;
4384
+ var _result$init5, _result$init6;
4387
4385
  return {
4388
4386
  type: ResultType.deferred,
4389
4387
  deferredData: result,
4390
- statusCode: (_result$init3 = result.init) == null ? void 0 : _result$init3.status,
4391
- headers: ((_result$init4 = result.init) == null ? void 0 : _result$init4.headers) && new Headers(result.init.headers)
4388
+ statusCode: (_result$init5 = result.init) == null ? void 0 : _result$init5.status,
4389
+ headers: ((_result$init6 = result.init) == null ? void 0 : _result$init6.headers) && new Headers(result.init.headers)
4392
4390
  };
4393
4391
  }
4394
4392
  if (isDataWithResponseInit(result)) {
4395
- var _result$init5, _result$init6;
4393
+ var _result$init7, _result$init8;
4396
4394
  return {
4397
4395
  type: ResultType.data,
4398
4396
  data: result.data,
4399
- statusCode: (_result$init5 = result.init) == null ? void 0 : _result$init5.status,
4400
- headers: (_result$init6 = result.init) != null && _result$init6.headers ? new Headers(result.init.headers) : undefined
4397
+ statusCode: (_result$init7 = result.init) == null ? void 0 : _result$init7.status,
4398
+ headers: (_result$init8 = result.init) != null && _result$init8.headers ? new Headers(result.init.headers) : undefined
4401
4399
  };
4402
4400
  }
4403
4401
  return {