@remix-run/router 0.0.0-experimental-1e8b7a59 → 0.0.0-experimental-e0f088aa

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-1e8b7a59
2
+ * @remix-run/router v0.0.0-experimental-e0f088aa
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1751,11 +1751,6 @@ 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
-
1759
1754
  // Track loads based on the order in which they started
1760
1755
  let incrementingLoadId = 0;
1761
1756
 
@@ -1884,20 +1879,19 @@ function createRouter(init) {
1884
1879
 
1885
1880
  // Update our state and notify the calling context of the change
1886
1881
  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
- }
1897
1882
  state = _extends({}, state, newState);
1898
1883
  subscribers.forEach(subscriber => subscriber(state, {
1899
1884
  unstable_viewTransitionOpts: viewTransitionOpts
1900
1885
  }));
1886
+
1887
+ // Remove idle fetchers from state since we only care about in-flight fetchers.
1888
+ // We keep fetchLoadeMatches around for revalidations purposes.
1889
+ // The React layer persists the data for completed fetchers.
1890
+ state.fetchers.forEach((fetcher, key) => {
1891
+ if (fetcher.state === "idle") {
1892
+ state.fetchers.delete(key);
1893
+ }
1894
+ });
1901
1895
  }
1902
1896
 
1903
1897
  // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
@@ -2449,9 +2443,6 @@ function createRouter(init) {
2449
2443
  fetchers: new Map(state.fetchers)
2450
2444
  } : {});
2451
2445
  }
2452
- function getFetcher(key) {
2453
- return state.fetchers.get(key) || IDLE_FETCHER;
2454
- }
2455
2446
 
2456
2447
  // Trigger a fetcher load/submit for the given fetcher key
2457
2448
  function fetch(key, routeId, href, opts) {
@@ -2480,10 +2471,6 @@ function createRouter(init) {
2480
2471
  let match = getTargetMatch(matches, path);
2481
2472
  pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
2482
2473
  if (submission && isMutationMethod(submission.formMethod)) {
2483
- // Mark this fetcher as persisted, but not deleted
2484
- if (opts.persist) {
2485
- persistedFetchers.set(key, false);
2486
- }
2487
2474
  handleFetcherAction(key, routeId, path, match, matches, submission);
2488
2475
  return;
2489
2476
  }
@@ -2494,7 +2481,6 @@ function createRouter(init) {
2494
2481
  routeId,
2495
2482
  path
2496
2483
  });
2497
- persistedFetchers.delete(key);
2498
2484
  handleFetcherLoader(key, routeId, path, match, matches, submission);
2499
2485
  }
2500
2486
 
@@ -2896,7 +2882,9 @@ function createRouter(init) {
2896
2882
  fetchers: new Map(state.fetchers)
2897
2883
  });
2898
2884
  }
2899
- function cleanupFetcher(key, fetcher) {
2885
+ function deleteFetcher(key) {
2886
+ let fetcher = state.fetchers.get(key);
2887
+
2900
2888
  // Don't abort the controller if this is a deletion of a fetcher.submit()
2901
2889
  // in it's loading phase since - we don't want to abort the corresponding
2902
2890
  // revalidation and want them to complete and land
@@ -2906,24 +2894,8 @@ function createRouter(init) {
2906
2894
  fetchLoadMatches.delete(key);
2907
2895
  fetchReloadIds.delete(key);
2908
2896
  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);
2919
2897
  state.fetchers.delete(key);
2920
2898
  }
2921
- function deleteFetcherAndUpdateState(key) {
2922
- deleteFetcher(key);
2923
- updateState({
2924
- fetchers: new Map(state.fetchers)
2925
- });
2926
- }
2927
2899
  function abortFetcher(key) {
2928
2900
  let controller = fetchControllers.get(key);
2929
2901
  invariant(controller, "Expected fetch controller: " + key);
@@ -2932,8 +2904,8 @@ function createRouter(init) {
2932
2904
  }
2933
2905
  function markFetchersDone(keys) {
2934
2906
  for (let key of keys) {
2935
- let fetcher = getFetcher(key);
2936
- let doneFetcher = getDoneFetcher(fetcher.data);
2907
+ let fetcher = state.fetchers.get(key);
2908
+ let doneFetcher = getDoneFetcher(fetcher ? fetcher.data : undefined);
2937
2909
  state.fetchers.set(key, doneFetcher);
2938
2910
  }
2939
2911
  }
@@ -3117,8 +3089,7 @@ function createRouter(init) {
3117
3089
  // hash-aware URLs in DOM paths
3118
3090
  createHref: to => init.history.createHref(to),
3119
3091
  encodeLocation: to => init.history.encodeLocation(to),
3120
- getFetcher,
3121
- deleteFetcher: deleteFetcherAndUpdateState,
3092
+ deleteFetcher,
3122
3093
  dispose,
3123
3094
  getBlocker,
3124
3095
  deleteBlocker,