@remix-run/router 1.21.1 → 1.22.0-pre-v6.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/dist/utils.d.ts CHANGED
@@ -201,6 +201,7 @@ export interface DataStrategyFunction {
201
201
  (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
202
202
  }
203
203
  export type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
204
+ signal: AbortSignal;
204
205
  path: string;
205
206
  matches: M[];
206
207
  patch: (routeId: string | null, children: O[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.21.1",
3
+ "version": "1.22.0-pre-v6.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -829,6 +829,7 @@ export function createRouter(init: RouterInit): Router {
829
829
  let initialScrollRestored = init.hydrationData != null;
830
830
 
831
831
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
832
+ let initialMatchesIsFOW = false;
832
833
  let initialErrors: RouteData | null = null;
833
834
 
834
835
  if (initialMatches == null && !patchRoutesOnNavigationImpl) {
@@ -874,6 +875,7 @@ export function createRouter(init: RouterInit): Router {
874
875
  init.history.location.pathname
875
876
  );
876
877
  if (fogOfWar.active && fogOfWar.matches) {
878
+ initialMatchesIsFOW = true;
877
879
  initialMatches = fogOfWar.matches;
878
880
  }
879
881
  }
@@ -1522,7 +1524,14 @@ export function createRouter(init: RouterInit): Router {
1522
1524
 
1523
1525
  let routesToUse = inFlightDataRoutes || dataRoutes;
1524
1526
  let loadingNavigation = opts && opts.overrideNavigation;
1525
- let matches = matchRoutes(routesToUse, location, basename);
1527
+ let matches =
1528
+ opts?.initialHydration &&
1529
+ state.matches &&
1530
+ state.matches.length > 0 &&
1531
+ !initialMatchesIsFOW
1532
+ ? // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1533
+ state.matches
1534
+ : matchRoutes(routesToUse, location, basename);
1526
1535
  let flushSync = (opts && opts.flushSync) === true;
1527
1536
 
1528
1537
  let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
@@ -2255,7 +2264,7 @@ export function createRouter(init: RouterInit): Router {
2255
2264
  if (isFogOfWar) {
2256
2265
  let discoverResult = await discoverRoutes(
2257
2266
  requestMatches,
2258
- path,
2267
+ new URL(fetchRequest.url).pathname,
2259
2268
  fetchRequest.signal
2260
2269
  );
2261
2270
 
@@ -2547,7 +2556,7 @@ export function createRouter(init: RouterInit): Router {
2547
2556
  if (isFogOfWar) {
2548
2557
  let discoverResult = await discoverRoutes(
2549
2558
  matches,
2550
- path,
2559
+ new URL(fetchRequest.url).pathname,
2551
2560
  fetchRequest.signal
2552
2561
  );
2553
2562
 
@@ -3284,6 +3293,7 @@ export function createRouter(init: RouterInit): Router {
3284
3293
  let localManifest = manifest;
3285
3294
  try {
3286
3295
  await patchRoutesOnNavigationImpl({
3296
+ signal,
3287
3297
  path: pathname,
3288
3298
  matches: partialMatches,
3289
3299
  patch: (routeId, children) => {
@@ -5052,15 +5062,25 @@ async function convertDataStrategyResultToDataResult(
5052
5062
  type: ResultType.error,
5053
5063
  error: result.data,
5054
5064
  statusCode: result.init?.status,
5065
+ headers: result.init?.headers
5066
+ ? new Headers(result.init.headers)
5067
+ : undefined,
5055
5068
  };
5056
5069
  }
5057
5070
 
5058
5071
  // Convert thrown data() to ErrorResponse instances
5059
- result = new ErrorResponseImpl(
5060
- result.init?.status || 500,
5061
- undefined,
5062
- result.data
5063
- );
5072
+ return {
5073
+ type: ResultType.error,
5074
+ error: new ErrorResponseImpl(
5075
+ result.init?.status || 500,
5076
+ undefined,
5077
+ result.data
5078
+ ),
5079
+ statusCode: isRouteErrorResponse(result) ? result.status : undefined,
5080
+ headers: result.init?.headers
5081
+ ? new Headers(result.init.headers)
5082
+ : undefined,
5083
+ };
5064
5084
  }
5065
5085
  return {
5066
5086
  type: ResultType.error,
package/utils.ts CHANGED
@@ -259,6 +259,7 @@ export type AgnosticPatchRoutesOnNavigationFunctionArgs<
259
259
  O extends AgnosticRouteObject = AgnosticRouteObject,
260
260
  M extends AgnosticRouteMatch = AgnosticRouteMatch
261
261
  > = {
262
+ signal: AbortSignal;
262
263
  path: string;
263
264
  matches: M[];
264
265
  patch: (routeId: string | null, children: O[]) => void;