@remix-run/router 0.0.0-experimental-4a8a492a → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "0.0.0-experimental-4a8a492a",
3
+ "version": "0.0.0-experimental-e0f088aa",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -80,6 +80,14 @@ export interface Router {
80
80
  */
81
81
  get routes(): AgnosticDataRouteObject[];
82
82
 
83
+ /**
84
+ * @internal
85
+ * PRIVATE - DO NOT USE
86
+ *
87
+ * Return the window associated with the router
88
+ */
89
+ get window(): RouterInit["window"];
90
+
83
91
  /**
84
92
  * @internal
85
93
  * PRIVATE - DO NOT USE
@@ -178,15 +186,6 @@ export interface Router {
178
186
  */
179
187
  encodeLocation(to: To): Path;
180
188
 
181
- /**
182
- * @internal
183
- * PRIVATE - DO NOT USE
184
- *
185
- * Get/create a fetcher for the given key
186
- * @param key
187
- */
188
- getFetcher<TData = any>(key?: string): Fetcher<TData>;
189
-
190
189
  /**
191
190
  * @internal
192
191
  * PRIVATE - DO NOT USE
@@ -194,7 +193,7 @@ export interface Router {
194
193
  * Delete the fetcher for a given key
195
194
  * @param key
196
195
  */
197
- deleteFetcher(key?: string): void;
196
+ deleteFetcher(key: string): void;
198
197
 
199
198
  /**
200
199
  * @internal
@@ -400,7 +399,7 @@ export interface RouterSubscriber {
400
399
  (
401
400
  state: RouterState,
402
401
  opts: {
403
- viewTransitionOpts?: ViewTransitionOpts;
402
+ unstable_viewTransitionOpts?: ViewTransitionOpts;
404
403
  }
405
404
  ): void;
406
405
  }
@@ -1007,8 +1006,17 @@ export function createRouter(init: RouterInit): Router {
1007
1006
  ...newState,
1008
1007
  };
1009
1008
  subscribers.forEach((subscriber) =>
1010
- subscriber(state, { viewTransitionOpts })
1009
+ subscriber(state, { unstable_viewTransitionOpts: viewTransitionOpts })
1011
1010
  );
1011
+
1012
+ // Remove idle fetchers from state since we only care about in-flight fetchers.
1013
+ // We keep fetchLoadeMatches around for revalidations purposes.
1014
+ // The React layer persists the data for completed fetchers.
1015
+ state.fetchers.forEach((fetcher, key) => {
1016
+ if (fetcher.state === "idle") {
1017
+ state.fetchers.delete(key);
1018
+ }
1019
+ });
1012
1020
  }
1013
1021
 
1014
1022
  // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
@@ -1716,10 +1724,6 @@ export function createRouter(init: RouterInit): Router {
1716
1724
  };
1717
1725
  }
1718
1726
 
1719
- function getFetcher<TData = any>(key: string): Fetcher<TData> {
1720
- return state.fetchers.get(key) || IDLE_FETCHER;
1721
- }
1722
-
1723
1727
  // Trigger a fetcher load/submit for the given fetcher key
1724
1728
  function fetch(
1725
1729
  key: string,
@@ -2001,7 +2005,7 @@ export function createRouter(init: RouterInit): Router {
2001
2005
  state.fetchers.set(key, doneFetcher);
2002
2006
  }
2003
2007
 
2004
- let didAbortFetchLoads = abortStaleFetchLoads(loadId);
2008
+ abortStaleFetchLoads(loadId);
2005
2009
 
2006
2010
  // If we are currently in a navigation loading state and this fetcher is
2007
2011
  // more recent than the navigation, we want the newer data so abort the
@@ -2031,9 +2035,7 @@ export function createRouter(init: RouterInit): Router {
2031
2035
  matches,
2032
2036
  errors
2033
2037
  ),
2034
- ...(didAbortFetchLoads || revalidatingFetchers.length > 0
2035
- ? { fetchers: new Map(state.fetchers) }
2036
- : {}),
2038
+ fetchers: new Map(state.fetchers),
2037
2039
  });
2038
2040
  isRevalidationRequired = false;
2039
2041
  }
@@ -2356,6 +2358,7 @@ export function createRouter(init: RouterInit): Router {
2356
2358
 
2357
2359
  function deleteFetcher(key: string): void {
2358
2360
  let fetcher = state.fetchers.get(key);
2361
+
2359
2362
  // Don't abort the controller if this is a deletion of a fetcher.submit()
2360
2363
  // in it's loading phase since - we don't want to abort the corresponding
2361
2364
  // revalidation and want them to complete and land
@@ -2380,8 +2383,8 @@ export function createRouter(init: RouterInit): Router {
2380
2383
 
2381
2384
  function markFetchersDone(keys: string[]) {
2382
2385
  for (let key of keys) {
2383
- let fetcher = getFetcher(key);
2384
- let doneFetcher = getDoneFetcher(fetcher.data);
2386
+ let fetcher = state.fetchers.get(key);
2387
+ let doneFetcher = getDoneFetcher(fetcher ? fetcher.data : undefined);
2385
2388
  state.fetchers.set(key, doneFetcher);
2386
2389
  }
2387
2390
  }
@@ -2591,6 +2594,9 @@ export function createRouter(init: RouterInit): Router {
2591
2594
  get routes() {
2592
2595
  return dataRoutes;
2593
2596
  },
2597
+ get window() {
2598
+ return routerWindow;
2599
+ },
2594
2600
  initialize,
2595
2601
  subscribe,
2596
2602
  enableScrollRestoration,
@@ -2601,7 +2607,6 @@ export function createRouter(init: RouterInit): Router {
2601
2607
  // hash-aware URLs in DOM paths
2602
2608
  createHref: (to: To) => init.history.createHref(to),
2603
2609
  encodeLocation: (to: To) => init.history.encodeLocation(to),
2604
- getFetcher,
2605
2610
  deleteFetcher,
2606
2611
  dispose,
2607
2612
  getBlocker,
@@ -4160,9 +4165,12 @@ function getShortCircuitMatches(routes: AgnosticDataRouteObject[]): {
4160
4165
  route: AgnosticDataRouteObject;
4161
4166
  } {
4162
4167
  // Prefer a root layout route if present, otherwise shim in a route object
4163
- let route = routes.find((r) => r.index || !r.path || r.path === "/") || {
4164
- id: `__shim-error-route__`,
4165
- };
4168
+ let route =
4169
+ routes.length === 1
4170
+ ? routes[0]
4171
+ : routes.find((r) => r.index || !r.path || r.path === "/") || {
4172
+ id: `__shim-error-route__`,
4173
+ };
4166
4174
 
4167
4175
  return {
4168
4176
  matches: [