@remix-run/router 0.0.0-experimental-266d73f72 → 0.0.0-experimental-7a944bb54

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, DataStrategyResult as unstable_DataStrategyResult, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, AgnosticPatchRoutesOnNavigationFunction as unstable_AgnosticPatchRoutesOnNavigationFunction, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, DataWithResponseInit as UNSAFE_DataWithResponseInit, } from "./utils";
2
- export { AbortedDeferredError, data as unstable_data, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, replace, resolvePath, resolveTo, stripBasename, } from "./utils";
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticPatchRoutesOnNavigationFunction, AgnosticPatchRoutesOnNavigationFunctionArgs, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, DataStrategyResult, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, DataWithResponseInit as UNSAFE_DataWithResponseInit, } from "./utils";
2
+ export { AbortedDeferredError, data, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, replace, resolvePath, resolveTo, stripBasename, } from "./utils";
3
3
  export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
4
4
  export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
5
5
  export * from "./router";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-266d73f72
2
+ * @remix-run/router v0.0.0-experimental-7a944bb54
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1711,8 +1711,8 @@ function createRouter(init) {
1711
1711
  let dataRoutes = convertRoutesToDataRoutes(init.routes, mapRouteProperties, undefined, manifest);
1712
1712
  let inFlightDataRoutes;
1713
1713
  let basename = init.basename || "/";
1714
- let dataStrategyImpl = init.unstable_dataStrategy || defaultDataStrategy;
1715
- let patchRoutesOnNavigationImpl = init.unstable_patchRoutesOnNavigation;
1714
+ let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
1715
+ let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
1716
1716
 
1717
1717
  // Config driven behavior flags
1718
1718
  let future = _extends({
@@ -1727,10 +1727,6 @@ function createRouter(init) {
1727
1727
  let unlistenHistory = null;
1728
1728
  // Externally-provided functions to call on all state changes
1729
1729
  let subscribers = new Set();
1730
- // FIFO queue of previously discovered routes to prevent re-calling on
1731
- // subsequent navigations to the same path
1732
- let discoveredRoutesMaxSize = 1000;
1733
- let discoveredRoutes = new Set();
1734
1730
  // Externally-provided object to hold scroll restoration locations during routing
1735
1731
  let savedScrollPositions = null;
1736
1732
  // Externally-provided function to get scroll restoration keys
@@ -2059,6 +2055,7 @@ function createRouter(init) {
2059
2055
  // Iterate over a local copy so that if flushSync is used and we end up
2060
2056
  // removing and adding a new subscriber due to the useCallback dependencies,
2061
2057
  // we don't get ourselves into a loop calling the new subscriber immediately
2058
+ debugger;
2062
2059
  [...subscribers].forEach(subscriber => subscriber(state, {
2063
2060
  deletedFetchers: deletedFetchersKeys,
2064
2061
  unstable_viewTransitionOpts: opts.viewTransitionOpts,
@@ -3400,10 +3397,10 @@ function createRouter(init) {
3400
3397
  fetchers: new Map(state.fetchers)
3401
3398
  });
3402
3399
  }
3403
- function abortFetcher(key) {
3400
+ function abortFetcher(key, reason) {
3404
3401
  let controller = fetchControllers.get(key);
3405
3402
  invariant(controller, "Expected fetch controller: " + key);
3406
- controller.abort();
3403
+ controller.abort(reason);
3407
3404
  fetchControllers.delete(key);
3408
3405
  }
3409
3406
  function markFetchersDone(keys) {
@@ -3596,15 +3593,6 @@ function createRouter(init) {
3596
3593
  }
3597
3594
  function checkFogOfWar(matches, routesToUse, pathname) {
3598
3595
  if (patchRoutesOnNavigationImpl) {
3599
- // Don't bother re-calling patchRouteOnMiss for a path we've already
3600
- // processed. the last execution would have patched the route tree
3601
- // accordingly so `matches` here are already accurate.
3602
- if (discoveredRoutes.has(pathname)) {
3603
- return {
3604
- active: false,
3605
- matches
3606
- };
3607
- }
3608
3596
  if (!matches) {
3609
3597
  let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
3610
3598
  return {
@@ -3660,7 +3648,6 @@ function createRouter(init) {
3660
3648
  }
3661
3649
  let newMatches = matchRoutes(routesToUse, pathname, basename);
3662
3650
  if (newMatches) {
3663
- addToFifoQueue(pathname, discoveredRoutes);
3664
3651
  return {
3665
3652
  type: "success",
3666
3653
  matches: newMatches
@@ -3670,7 +3657,6 @@ function createRouter(init) {
3670
3657
 
3671
3658
  // Avoid loops if the second pass results in the same partial matches
3672
3659
  if (!newPartialMatches || partialMatches.length === newPartialMatches.length && partialMatches.every((m, i) => m.route.id === newPartialMatches[i].route.id)) {
3673
- addToFifoQueue(pathname, discoveredRoutes);
3674
3660
  return {
3675
3661
  type: "success",
3676
3662
  matches: null
@@ -3679,13 +3665,6 @@ function createRouter(init) {
3679
3665
  partialMatches = newPartialMatches;
3680
3666
  }
3681
3667
  }
3682
- function addToFifoQueue(path, queue) {
3683
- if (queue.size >= discoveredRoutesMaxSize) {
3684
- let first = queue.values().next().value;
3685
- queue.delete(first);
3686
- }
3687
- queue.add(path);
3688
- }
3689
3668
  function _internalSetRoutes(newRoutes) {
3690
3669
  manifest = {};
3691
3670
  inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest);
@@ -3733,13 +3712,17 @@ function createRouter(init) {
3733
3712
  encodeLocation: to => init.history.encodeLocation(to),
3734
3713
  getFetcher,
3735
3714
  deleteFetcher: deleteFetcherAndUpdateState,
3736
- abortFetcher(key, data) {
3715
+ abortFetcher(key, _temp3) {
3716
+ let {
3717
+ reason,
3718
+ data
3719
+ } = _temp3 === void 0 ? {} : _temp3;
3737
3720
  if (fetchControllers.has(key)) {
3738
- abortFetcher(key);
3721
+ abortFetcher(key, reason);
3739
3722
  } else if (landedFetcherControllers.has(key)) {
3740
- landedFetcherControllers.get(key).abort();
3723
+ landedFetcherControllers.get(key).abort(reason);
3741
3724
  }
3742
- updateFetcherState(key, getDoneFetcher(data));
3725
+ updateFetcherState(key, getDoneFetcher(typeof data === "undefined" ? null : data));
3743
3726
  },
3744
3727
  dispose,
3745
3728
  getBlocker,
@@ -3814,12 +3797,12 @@ function createStaticHandler(routes, opts) {
3814
3797
  * where the client will handle the bubbling and we may need to return data
3815
3798
  * for the handling route
3816
3799
  */
3817
- async function query(request, _temp3) {
3800
+ async function query(request, _temp4) {
3818
3801
  let {
3819
3802
  requestContext,
3820
3803
  skipLoaderErrorBubbling,
3821
- unstable_dataStrategy
3822
- } = _temp3 === void 0 ? {} : _temp3;
3804
+ dataStrategy
3805
+ } = _temp4 === void 0 ? {} : _temp4;
3823
3806
  let url = new URL(request.url);
3824
3807
  let method = request.method;
3825
3808
  let location = createLocation("", createPath(url), null, "default");
@@ -3871,7 +3854,7 @@ function createStaticHandler(routes, opts) {
3871
3854
  activeDeferreds: null
3872
3855
  };
3873
3856
  }
3874
- let result = await queryImpl(request, location, matches, requestContext, unstable_dataStrategy || null, skipLoaderErrorBubbling === true, null);
3857
+ let result = await queryImpl(request, location, matches, requestContext, dataStrategy || null, skipLoaderErrorBubbling === true, null);
3875
3858
  if (isResponse(result)) {
3876
3859
  return result;
3877
3860
  }
@@ -3911,12 +3894,12 @@ function createStaticHandler(routes, opts) {
3911
3894
  * - `opts.requestContext` is an optional server context that will be passed
3912
3895
  * to actions/loaders in the `context` parameter
3913
3896
  */
3914
- async function queryRoute(request, _temp4) {
3897
+ async function queryRoute(request, _temp5) {
3915
3898
  let {
3916
3899
  routeId,
3917
3900
  requestContext,
3918
- unstable_dataStrategy
3919
- } = _temp4 === void 0 ? {} : _temp4;
3901
+ dataStrategy
3902
+ } = _temp5 === void 0 ? {} : _temp5;
3920
3903
  let url = new URL(request.url);
3921
3904
  let method = request.method;
3922
3905
  let location = createLocation("", createPath(url), null, "default");
@@ -3944,7 +3927,7 @@ function createStaticHandler(routes, opts) {
3944
3927
  pathname: location.pathname
3945
3928
  });
3946
3929
  }
3947
- let result = await queryImpl(request, location, matches, requestContext, unstable_dataStrategy || null, false, match);
3930
+ let result = await queryImpl(request, location, matches, requestContext, dataStrategy || null, false, match);
3948
3931
  if (isResponse(result)) {
3949
3932
  return result;
3950
3933
  }
@@ -3971,14 +3954,14 @@ function createStaticHandler(routes, opts) {
3971
3954
  }
3972
3955
  return undefined;
3973
3956
  }
3974
- async function queryImpl(request, location, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch) {
3957
+ async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch) {
3975
3958
  invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
3976
3959
  try {
3977
3960
  if (isMutationMethod(request.method.toLowerCase())) {
3978
- let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch != null);
3961
+ let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch != null);
3979
3962
  return result;
3980
3963
  }
3981
- let result = await loadRouteData(request, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch);
3964
+ let result = await loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch);
3982
3965
  return isResponse(result) ? result : _extends({}, result, {
3983
3966
  actionData: null,
3984
3967
  actionHeaders: {}
@@ -4001,7 +3984,7 @@ function createStaticHandler(routes, opts) {
4001
3984
  throw e;
4002
3985
  }
4003
3986
  }
4004
- async function submit(request, matches, actionMatch, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
3987
+ async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
4005
3988
  let result;
4006
3989
  if (!actionMatch.route.action && !actionMatch.route.lazy) {
4007
3990
  let error = getInternalRouterError(405, {
@@ -4017,7 +4000,7 @@ function createStaticHandler(routes, opts) {
4017
4000
  error
4018
4001
  };
4019
4002
  } else {
4020
- let results = await callDataStrategy("action", request, [actionMatch], matches, isRouteRequest, requestContext, unstable_dataStrategy);
4003
+ let results = await callDataStrategy("action", request, [actionMatch], matches, isRouteRequest, requestContext, dataStrategy);
4021
4004
  result = results[actionMatch.route.id];
4022
4005
  if (request.signal.aborted) {
4023
4006
  throwStaticHandlerAbortedError(request, isRouteRequest, future);
@@ -4079,7 +4062,7 @@ function createStaticHandler(routes, opts) {
4079
4062
  // Store off the pending error - we use it to determine which loaders
4080
4063
  // to call and will commit it when we complete the navigation
4081
4064
  let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
4082
- let context = await loadRouteData(loaderRequest, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result]);
4065
+ let context = await loadRouteData(loaderRequest, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result]);
4083
4066
 
4084
4067
  // action status codes take precedence over loader status codes
4085
4068
  return _extends({}, context, {
@@ -4090,7 +4073,7 @@ function createStaticHandler(routes, opts) {
4090
4073
  } : {})
4091
4074
  });
4092
4075
  }
4093
- let context = await loadRouteData(loaderRequest, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, null);
4076
+ let context = await loadRouteData(loaderRequest, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, null);
4094
4077
  return _extends({}, context, {
4095
4078
  actionData: {
4096
4079
  [actionMatch.route.id]: result.data
@@ -4103,7 +4086,7 @@ function createStaticHandler(routes, opts) {
4103
4086
  } : {}
4104
4087
  });
4105
4088
  }
4106
- async function loadRouteData(request, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
4089
+ async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
4107
4090
  let isRouteRequest = routeMatch != null;
4108
4091
 
4109
4092
  // Short circuit if we have no loaders to run (queryRoute())
@@ -4133,7 +4116,7 @@ function createStaticHandler(routes, opts) {
4133
4116
  activeDeferreds: null
4134
4117
  };
4135
4118
  }
4136
- let results = await callDataStrategy("loader", request, matchesToLoad, matches, isRouteRequest, requestContext, unstable_dataStrategy);
4119
+ let results = await callDataStrategy("loader", request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy);
4137
4120
  if (request.signal.aborted) {
4138
4121
  throwStaticHandlerAbortedError(request, isRouteRequest, future);
4139
4122
  }
@@ -4157,8 +4140,8 @@ function createStaticHandler(routes, opts) {
4157
4140
 
4158
4141
  // Utility wrapper for calling dataStrategy server-side without having to
4159
4142
  // pass around the manifest, mapRouteProperties, etc.
4160
- async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, unstable_dataStrategy) {
4161
- let results = await callDataStrategyImpl(unstable_dataStrategy || defaultDataStrategy, type, null, request, matchesToLoad, matches, null, manifest, mapRouteProperties, requestContext);
4143
+ async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy) {
4144
+ let results = await callDataStrategyImpl(dataStrategy || defaultDataStrategy, type, null, request, matchesToLoad, matches, null, manifest, mapRouteProperties, requestContext);
4162
4145
  let dataResults = {};
4163
4146
  await Promise.all(matches.map(async match => {
4164
4147
  if (!(match.route.id in results)) {
@@ -4596,20 +4579,25 @@ async function loadLazyRouteChildren(patchRoutesOnNavigationImpl, path, matches,
4596
4579
  }
4597
4580
  }
4598
4581
  function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) {
4582
+ var _childrenToPatch;
4583
+ let childrenToPatch;
4599
4584
  if (routeId) {
4600
- var _route$children;
4601
4585
  let route = manifest[routeId];
4602
4586
  invariant(route, "No route found to patch children into: routeId = " + routeId);
4603
- let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, [routeId, "patch", String(((_route$children = route.children) == null ? void 0 : _route$children.length) || "0")], manifest);
4604
- if (route.children) {
4605
- route.children.push(...dataChildren);
4606
- } else {
4607
- route.children = dataChildren;
4587
+ if (!route.children) {
4588
+ route.children = [];
4608
4589
  }
4590
+ childrenToPatch = route.children;
4609
4591
  } else {
4610
- let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routesToUse.length || "0")], manifest);
4611
- routesToUse.push(...dataChildren);
4592
+ childrenToPatch = routesToUse;
4612
4593
  }
4594
+
4595
+ // Don't patch in routes we already know about so that `patch` is idempotent
4596
+ // to simplify user-land code. This is useful because we re-call the
4597
+ // `patchRoutesOnNavigation` function for matched routes with params.
4598
+ let uniqueChildren = children.filter(a => !childrenToPatch.some(b => a.index === b.index && a.path === b.path && a.caseSensitive === b.caseSensitive));
4599
+ let newRoutes = convertRoutesToDataRoutes(uniqueChildren, mapRouteProperties, [routeId || "_", "patch", String(((_childrenToPatch = childrenToPatch) == null ? void 0 : _childrenToPatch.length) || "0")], manifest);
4600
+ childrenToPatch.push(...newRoutes);
4613
4601
  }
4614
4602
 
4615
4603
  /**
@@ -4883,7 +4871,7 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4883
4871
  };
4884
4872
  }
4885
4873
 
4886
- // Convert thrown unstable_data() to ErrorResponse instances
4874
+ // Convert thrown data() to ErrorResponse instances
4887
4875
  result = new ErrorResponseImpl(((_result$init2 = result.init) == null ? void 0 : _result$init2.status) || 500, undefined, result.data);
4888
4876
  }
4889
4877
  return {
@@ -5186,20 +5174,20 @@ function getShortCircuitMatches(routes) {
5186
5174
  route
5187
5175
  };
5188
5176
  }
5189
- function getInternalRouterError(status, _temp5) {
5177
+ function getInternalRouterError(status, _temp6) {
5190
5178
  let {
5191
5179
  pathname,
5192
5180
  routeId,
5193
5181
  method,
5194
5182
  type,
5195
5183
  message
5196
- } = _temp5 === void 0 ? {} : _temp5;
5184
+ } = _temp6 === void 0 ? {} : _temp6;
5197
5185
  let statusText = "Unknown Server Error";
5198
5186
  let errorMessage = "Unknown @remix-run/router error";
5199
5187
  if (status === 400) {
5200
5188
  statusText = "Bad Request";
5201
5189
  if (type === "route-discovery") {
5202
- errorMessage = "Unable to match URL \"" + pathname + "\" - the `unstable_patchRoutesOnNavigation()` " + ("function threw the following error:\n" + message);
5190
+ errorMessage = "Unable to match URL \"" + pathname + "\" - the `patchRoutesOnNavigation()` " + ("function threw the following error:\n" + message);
5203
5191
  } else if (method && pathname && routeId) {
5204
5192
  errorMessage = "You made a " + method + " request to \"" + pathname + "\" but " + ("did not provide a `loader` for route \"" + routeId + "\", ") + "so there is no way to handle the request.";
5205
5193
  } else if (type === "defer-action") {
@@ -5582,6 +5570,7 @@ exports.createMemoryHistory = createMemoryHistory;
5582
5570
  exports.createPath = createPath;
5583
5571
  exports.createRouter = createRouter;
5584
5572
  exports.createStaticHandler = createStaticHandler;
5573
+ exports.data = data;
5585
5574
  exports.defer = defer;
5586
5575
  exports.generatePath = generatePath;
5587
5576
  exports.getStaticContextFromError = getStaticContextFromError;
@@ -5601,5 +5590,4 @@ exports.replace = replace;
5601
5590
  exports.resolvePath = resolvePath;
5602
5591
  exports.resolveTo = resolveTo;
5603
5592
  exports.stripBasename = stripBasename;
5604
- exports.unstable_data = data;
5605
5593
  //# sourceMappingURL=router.cjs.js.map