@remix-run/router 1.21.1 → 1.21.2-pre-v6.0

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.1",
3
+ "version": "1.21.2-pre-v6.0",
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);
@@ -5052,15 +5061,25 @@ async function convertDataStrategyResultToDataResult(
5052
5061
  type: ResultType.error,
5053
5062
  error: result.data,
5054
5063
  statusCode: result.init?.status,
5064
+ headers: result.init?.headers
5065
+ ? new Headers(result.init.headers)
5066
+ : undefined,
5055
5067
  };
5056
5068
  }
5057
5069
 
5058
5070
  // Convert thrown data() to ErrorResponse instances
5059
- result = new ErrorResponseImpl(
5060
- result.init?.status || 500,
5061
- undefined,
5062
- result.data
5063
- );
5071
+ return {
5072
+ type: ResultType.error,
5073
+ error: new ErrorResponseImpl(
5074
+ result.init?.status || 500,
5075
+ undefined,
5076
+ result.data
5077
+ ),
5078
+ statusCode: isRouteErrorResponse(result) ? result.status : undefined,
5079
+ headers: result.init?.headers
5080
+ ? new Headers(result.init.headers)
5081
+ : undefined,
5082
+ };
5064
5083
  }
5065
5084
  return {
5066
5085
  type: ResultType.error,