@remix-run/router 0.0.0-experimental-4a8a492a → 0.0.0-experimental-1e8b7a59

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add experimental support for the [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) by allowing users to opt-into view transitions on navigations via the new `unstable_viewTransition` option to `router.navigate` ([#10916](https://github.com/remix-run/react-router/pull/10916))
8
+
9
+ ### Patch Changes
10
+
11
+ - Allow 404 detection to leverage root route error boundary if path contains a URL segment ([#10852](https://github.com/remix-run/react-router/pull/10852))
12
+ - Fix `ErrorResponse` type to avoid leaking internal field ([#10876](https://github.com/remix-run/react-router/pull/10876))
13
+
3
14
  ## 1.9.0
4
15
 
5
16
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-4a8a492a
2
+ * @remix-run/router v0.0.0-experimental-1e8b7a59
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1751,6 +1751,11 @@ function createRouter(init) {
1751
1751
  // AbortControllers for any in-flight fetchers
1752
1752
  let fetchControllers = new Map();
1753
1753
 
1754
+ // Keys for persisted fetchers
1755
+ // - `false` means it was submitted with `persist:true`
1756
+ // - `true` value means a deletion was requested during submission
1757
+ let persistedFetchers = new Map();
1758
+
1754
1759
  // Track loads based on the order in which they started
1755
1760
  let incrementingLoadId = 0;
1756
1761
 
@@ -1879,9 +1884,19 @@ function createRouter(init) {
1879
1884
 
1880
1885
  // Update our state and notify the calling context of the change
1881
1886
  function updateState(newState, viewTransitionOpts) {
1887
+ // If we're updating fetchers, delete any persisted ones that returned to idle
1888
+ if (newState.fetchers) {
1889
+ let newFetchers = newState.fetchers;
1890
+ newFetchers.forEach((fetcher, key) => {
1891
+ if (persistedFetchers.get(key) && fetcher.state === "idle") {
1892
+ cleanupFetcher(key, fetcher);
1893
+ newFetchers.delete(key);
1894
+ }
1895
+ });
1896
+ }
1882
1897
  state = _extends({}, state, newState);
1883
1898
  subscribers.forEach(subscriber => subscriber(state, {
1884
- viewTransitionOpts
1899
+ unstable_viewTransitionOpts: viewTransitionOpts
1885
1900
  }));
1886
1901
  }
1887
1902
 
@@ -2465,6 +2480,10 @@ function createRouter(init) {
2465
2480
  let match = getTargetMatch(matches, path);
2466
2481
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
2467
2482
  if (submission && isMutationMethod(submission.formMethod)) {
2483
+ // Mark this fetcher as persisted, but not deleted
2484
+ if (opts.persist) {
2485
+ persistedFetchers.set(key, false);
2486
+ }
2468
2487
  handleFetcherAction(key, routeId, path, match, matches, submission);
2469
2488
  return;
2470
2489
  }
@@ -2475,6 +2494,7 @@ function createRouter(init) {
2475
2494
  routeId,
2476
2495
  path
2477
2496
  });
2497
+ persistedFetchers.delete(key);
2478
2498
  handleFetcherLoader(key, routeId, path, match, matches, submission);
2479
2499
  }
2480
2500
 
@@ -2624,7 +2644,7 @@ function createRouter(init) {
2624
2644
  let doneFetcher = getDoneFetcher(actionResult.data);
2625
2645
  state.fetchers.set(key, doneFetcher);
2626
2646
  }
2627
- let didAbortFetchLoads = abortStaleFetchLoads(loadId);
2647
+ abortStaleFetchLoads(loadId);
2628
2648
 
2629
2649
  // If we are currently in a navigation loading state and this fetcher is
2630
2650
  // more recent than the navigation, we want the newer data so abort the
@@ -2642,12 +2662,11 @@ function createRouter(init) {
2642
2662
  // otherwise just update with the fetcher data, preserving any existing
2643
2663
  // loaderData for loaders that did not need to reload. We have to
2644
2664
  // manually merge here since we aren't going through completeNavigation
2645
- updateState(_extends({
2665
+ updateState({
2646
2666
  errors,
2647
- loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors)
2648
- }, didAbortFetchLoads || revalidatingFetchers.length > 0 ? {
2667
+ loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
2649
2668
  fetchers: new Map(state.fetchers)
2650
- } : {}));
2669
+ });
2651
2670
  isRevalidationRequired = false;
2652
2671
  }
2653
2672
  }
@@ -2877,8 +2896,7 @@ function createRouter(init) {
2877
2896
  fetchers: new Map(state.fetchers)
2878
2897
  });
2879
2898
  }
2880
- function deleteFetcher(key) {
2881
- let fetcher = state.fetchers.get(key);
2899
+ function cleanupFetcher(key, fetcher) {
2882
2900
  // Don't abort the controller if this is a deletion of a fetcher.submit()
2883
2901
  // in it's loading phase since - we don't want to abort the corresponding
2884
2902
  // revalidation and want them to complete and land
@@ -2888,8 +2906,24 @@ function createRouter(init) {
2888
2906
  fetchLoadMatches.delete(key);
2889
2907
  fetchReloadIds.delete(key);
2890
2908
  fetchRedirectIds.delete(key);
2909
+ persistedFetchers.delete(key);
2910
+ }
2911
+ function deleteFetcher(key) {
2912
+ let fetcher = state.fetchers.get(key);
2913
+ if (persistedFetchers.has(key) && fetcher && fetcher.state !== "idle") {
2914
+ // Mark for deletion on completion
2915
+ persistedFetchers.set(key, true);
2916
+ return;
2917
+ }
2918
+ cleanupFetcher(key, fetcher);
2891
2919
  state.fetchers.delete(key);
2892
2920
  }
2921
+ function deleteFetcherAndUpdateState(key) {
2922
+ deleteFetcher(key);
2923
+ updateState({
2924
+ fetchers: new Map(state.fetchers)
2925
+ });
2926
+ }
2893
2927
  function abortFetcher(key) {
2894
2928
  let controller = fetchControllers.get(key);
2895
2929
  invariant(controller, "Expected fetch controller: " + key);
@@ -3070,6 +3104,9 @@ function createRouter(init) {
3070
3104
  get routes() {
3071
3105
  return dataRoutes;
3072
3106
  },
3107
+ get window() {
3108
+ return routerWindow;
3109
+ },
3073
3110
  initialize,
3074
3111
  subscribe,
3075
3112
  enableScrollRestoration,
@@ -3081,7 +3118,7 @@ function createRouter(init) {
3081
3118
  createHref: to => init.history.createHref(to),
3082
3119
  encodeLocation: to => init.history.encodeLocation(to),
3083
3120
  getFetcher,
3084
- deleteFetcher,
3121
+ deleteFetcher: deleteFetcherAndUpdateState,
3085
3122
  dispose,
3086
3123
  getBlocker,
3087
3124
  deleteBlocker,
@@ -4266,7 +4303,7 @@ function findNearestBoundary(matches, routeId) {
4266
4303
  }
4267
4304
  function getShortCircuitMatches(routes) {
4268
4305
  // Prefer a root layout route if present, otherwise shim in a route object
4269
- let route = routes.find(r => r.index || !r.path || r.path === "/") || {
4306
+ let route = routes.length === 1 ? routes[0] : routes.find(r => r.index || !r.path || r.path === "/") || {
4270
4307
  id: "__shim-error-route__"
4271
4308
  };
4272
4309
  return {