@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/dist/router.d.ts CHANGED
@@ -26,6 +26,13 @@ export interface Router {
26
26
  * Return the routes for this router instance
27
27
  */
28
28
  get routes(): AgnosticDataRouteObject[];
29
+ /**
30
+ * @internal
31
+ * PRIVATE - DO NOT USE
32
+ *
33
+ * Return the window associated with the router
34
+ */
35
+ get window(): RouterInit["window"];
29
36
  /**
30
37
  * @internal
31
38
  * PRIVATE - DO NOT USE
@@ -106,14 +113,6 @@ export interface Router {
106
113
  * @param to
107
114
  */
108
115
  encodeLocation(to: To): Path;
109
- /**
110
- * @internal
111
- * PRIVATE - DO NOT USE
112
- *
113
- * Get/create a fetcher for the given key
114
- * @param key
115
- */
116
- getFetcher<TData = any>(key?: string): Fetcher<TData>;
117
116
  /**
118
117
  * @internal
119
118
  * PRIVATE - DO NOT USE
@@ -121,7 +120,7 @@ export interface Router {
121
120
  * Delete the fetcher for a given key
122
121
  * @param key
123
122
  */
124
- deleteFetcher(key?: string): void;
123
+ deleteFetcher(key: string): void;
125
124
  /**
126
125
  * @internal
127
126
  * PRIVATE - DO NOT USE
@@ -296,7 +295,7 @@ type ViewTransitionOpts = {
296
295
  */
297
296
  export interface RouterSubscriber {
298
297
  (state: RouterState, opts: {
299
- viewTransitionOpts?: ViewTransitionOpts;
298
+ unstable_viewTransitionOpts?: ViewTransitionOpts;
300
299
  }): void;
301
300
  }
302
301
  /**
package/dist/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-4a8a492a
2
+ * @remix-run/router v0.0.0-experimental-e0f088aa
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1508,8 +1508,16 @@ function createRouter(init) {
1508
1508
  function updateState(newState, viewTransitionOpts) {
1509
1509
  state = _extends({}, state, newState);
1510
1510
  subscribers.forEach(subscriber => subscriber(state, {
1511
- viewTransitionOpts
1511
+ unstable_viewTransitionOpts: viewTransitionOpts
1512
1512
  }));
1513
+ // Remove idle fetchers from state since we only care about in-flight fetchers.
1514
+ // We keep fetchLoadeMatches around for revalidations purposes.
1515
+ // The React layer persists the data for completed fetchers.
1516
+ state.fetchers.forEach((fetcher, key) => {
1517
+ if (fetcher.state === "idle") {
1518
+ state.fetchers.delete(key);
1519
+ }
1520
+ });
1513
1521
  }
1514
1522
  // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
1515
1523
  // and setting state.[historyAction/location/matches] to the new route.
@@ -2026,9 +2034,6 @@ function createRouter(init) {
2026
2034
  fetchers: new Map(state.fetchers)
2027
2035
  } : {});
2028
2036
  }
2029
- function getFetcher(key) {
2030
- return state.fetchers.get(key) || IDLE_FETCHER;
2031
- }
2032
2037
  // Trigger a fetcher load/submit for the given fetcher key
2033
2038
  function fetch(key, routeId, href, opts) {
2034
2039
  if (isServer) {
@@ -2206,7 +2211,7 @@ function createRouter(init) {
2206
2211
  let doneFetcher = getDoneFetcher(actionResult.data);
2207
2212
  state.fetchers.set(key, doneFetcher);
2208
2213
  }
2209
- let didAbortFetchLoads = abortStaleFetchLoads(loadId);
2214
+ abortStaleFetchLoads(loadId);
2210
2215
  // If we are currently in a navigation loading state and this fetcher is
2211
2216
  // more recent than the navigation, we want the newer data so abort the
2212
2217
  // navigation and complete it with the fetcher data
@@ -2223,12 +2228,11 @@ function createRouter(init) {
2223
2228
  // otherwise just update with the fetcher data, preserving any existing
2224
2229
  // loaderData for loaders that did not need to reload. We have to
2225
2230
  // manually merge here since we aren't going through completeNavigation
2226
- updateState(_extends({
2231
+ updateState({
2227
2232
  errors,
2228
- loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors)
2229
- }, didAbortFetchLoads || revalidatingFetchers.length > 0 ? {
2233
+ loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
2230
2234
  fetchers: new Map(state.fetchers)
2231
- } : {}));
2235
+ });
2232
2236
  isRevalidationRequired = false;
2233
2237
  }
2234
2238
  }
@@ -2466,8 +2470,8 @@ function createRouter(init) {
2466
2470
  }
2467
2471
  function markFetchersDone(keys) {
2468
2472
  for (let key of keys) {
2469
- let fetcher = getFetcher(key);
2470
- let doneFetcher = getDoneFetcher(fetcher.data);
2473
+ let fetcher = state.fetchers.get(key);
2474
+ let doneFetcher = getDoneFetcher(fetcher ? fetcher.data : undefined);
2471
2475
  state.fetchers.set(key, doneFetcher);
2472
2476
  }
2473
2477
  }
@@ -2632,6 +2636,9 @@ function createRouter(init) {
2632
2636
  get routes() {
2633
2637
  return dataRoutes;
2634
2638
  },
2639
+ get window() {
2640
+ return routerWindow;
2641
+ },
2635
2642
  initialize,
2636
2643
  subscribe,
2637
2644
  enableScrollRestoration,
@@ -2642,7 +2649,6 @@ function createRouter(init) {
2642
2649
  // hash-aware URLs in DOM paths
2643
2650
  createHref: to => init.history.createHref(to),
2644
2651
  encodeLocation: to => init.history.encodeLocation(to),
2645
- getFetcher,
2646
2652
  deleteFetcher,
2647
2653
  dispose,
2648
2654
  getBlocker,
@@ -3776,7 +3782,7 @@ function findNearestBoundary(matches, routeId) {
3776
3782
  }
3777
3783
  function getShortCircuitMatches(routes) {
3778
3784
  // Prefer a root layout route if present, otherwise shim in a route object
3779
- let route = routes.find(r => r.index || !r.path || r.path === "/") || {
3785
+ let route = routes.length === 1 ? routes[0] : routes.find(r => r.index || !r.path || r.path === "/") || {
3780
3786
  id: "__shim-error-route__"
3781
3787
  };
3782
3788
  return {