@remix-run/router 1.21.0 → 1.21.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -1162,6 +1162,14 @@ export function createRouter(init: RouterInit): Router {
1162
1162
  });
1163
1163
  }
1164
1164
 
1165
+ // Remove any lingering deleted fetchers that have already been removed
1166
+ // from state.fetchers
1167
+ deletedFetchers.forEach((key) => {
1168
+ if (!state.fetchers.has(key) && !fetchControllers.has(key)) {
1169
+ deletedFetchersKeys.push(key);
1170
+ }
1171
+ });
1172
+
1165
1173
  // Iterate over a local copy so that if flushSync is used and we end up
1166
1174
  // removing and adding a new subscriber due to the useCallback dependencies,
1167
1175
  // we don't get ourselves into a loop calling the new subscriber immediately
@@ -1177,6 +1185,10 @@ export function createRouter(init: RouterInit): Router {
1177
1185
  if (future.v7_fetcherPersist) {
1178
1186
  completedFetchers.forEach((key) => state.fetchers.delete(key));
1179
1187
  deletedFetchersKeys.forEach((key) => deleteFetcher(key));
1188
+ } else {
1189
+ // We already called deleteFetcher() on these, can remove them from this
1190
+ // Set now that we've handed the keys off to the data layer
1191
+ deletedFetchersKeys.forEach((key) => deletedFetchers.delete(key));
1180
1192
  }
1181
1193
  }
1182
1194
 
@@ -2942,13 +2954,11 @@ export function createRouter(init: RouterInit): Router {
2942
2954
  }
2943
2955
 
2944
2956
  function getFetcher<TData = any>(key: string): Fetcher<TData> {
2945
- if (future.v7_fetcherPersist) {
2946
- activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
2947
- // If this fetcher was previously marked for deletion, unmark it since we
2948
- // have a new instance
2949
- if (deletedFetchers.has(key)) {
2950
- deletedFetchers.delete(key);
2951
- }
2957
+ activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
2958
+ // If this fetcher was previously marked for deletion, unmark it since we
2959
+ // have a new instance
2960
+ if (deletedFetchers.has(key)) {
2961
+ deletedFetchers.delete(key);
2952
2962
  }
2953
2963
  return state.fetchers.get(key) || IDLE_FETCHER;
2954
2964
  }
@@ -2967,23 +2977,33 @@ export function createRouter(init: RouterInit): Router {
2967
2977
  fetchLoadMatches.delete(key);
2968
2978
  fetchReloadIds.delete(key);
2969
2979
  fetchRedirectIds.delete(key);
2970
- deletedFetchers.delete(key);
2980
+
2981
+ // If we opted into the flag we can clear this now since we're calling
2982
+ // deleteFetcher() at the end of updateState() and we've already handed the
2983
+ // deleted fetcher keys off to the data layer.
2984
+ // If not, we're eagerly calling deleteFetcher() and we need to keep this
2985
+ // Set populated until the next updateState call, and we'll clear
2986
+ // `deletedFetchers` then
2987
+ if (future.v7_fetcherPersist) {
2988
+ deletedFetchers.delete(key);
2989
+ }
2990
+
2971
2991
  cancelledFetcherLoads.delete(key);
2972
2992
  state.fetchers.delete(key);
2973
2993
  }
2974
2994
 
2975
2995
  function deleteFetcherAndUpdateState(key: string): void {
2976
- if (future.v7_fetcherPersist) {
2977
- let count = (activeFetchers.get(key) || 0) - 1;
2978
- if (count <= 0) {
2979
- activeFetchers.delete(key);
2980
- deletedFetchers.add(key);
2981
- } else {
2982
- activeFetchers.set(key, count);
2996
+ let count = (activeFetchers.get(key) || 0) - 1;
2997
+ if (count <= 0) {
2998
+ activeFetchers.delete(key);
2999
+ deletedFetchers.add(key);
3000
+ if (!future.v7_fetcherPersist) {
3001
+ deleteFetcher(key);
2983
3002
  }
2984
3003
  } else {
2985
- deleteFetcher(key);
3004
+ activeFetchers.set(key, count);
2986
3005
  }
3006
+
2987
3007
  updateState({ fetchers: new Map(state.fetchers) });
2988
3008
  }
2989
3009