react-router 0.0.0-experimental-e960cf1a → 0.0.0-experimental-a0888892

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-e960cf1a
2
+ * React Router v0.0.0-experimental-a0888892
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -394,13 +394,32 @@
394
394
  location = locationFromContext;
395
395
  }
396
396
  let pathname = location.pathname || "/";
397
- let remainingPathname = parentPathnameBase === "/" ? pathname : pathname.slice(parentPathnameBase.length) || "/";
397
+ let remainingPathname = pathname;
398
+ if (parentPathnameBase !== "/") {
399
+ // Determine the remaining pathname by removing the # of URL segments the
400
+ // parentPathnameBase has, instead of removing based on character count.
401
+ // This is because we can't guarantee that incoming/outgoing encodings/
402
+ // decodings will match exactly.
403
+ // We decode paths before matching on a per-segment basis with
404
+ // decodeURIComponent(), but we re-encode pathnames via `new URL()` so they
405
+ // match what `window.location.pathname` would reflect. Those don't 100%
406
+ // align when it comes to encoded URI characters such as % and &.
407
+ //
408
+ // So we may end up with:
409
+ // pathname: "/descendant/a%25b/match"
410
+ // parentPathnameBase: "/descendant/a%b"
411
+ //
412
+ // And the direct substring removal approach won't work :/
413
+ let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
414
+ let segments = pathname.replace(/^\//, "").split("/");
415
+ remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
416
+ }
398
417
  let matches = router.matchRoutes(routes, {
399
418
  pathname: remainingPathname
400
419
  });
401
420
  {
402
421
  router.UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") ;
403
- router.UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") ;
422
+ router.UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined || matches[matches.length - 1].route.lazy !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") ;
404
423
  }
405
424
  let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
406
425
  params: Object.assign({}, parentParams, match.params),
@@ -574,17 +593,24 @@
574
593
  if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
575
594
  fallbackIndex = i;
576
595
  }
577
- if (match.route.loader && match.route.id && dataRouterState.loaderData[match.route.id] === undefined && (!dataRouterState.errors || dataRouterState.errors[match.route.id] === undefined)) {
578
- // We found the first route without data/errors which means it's loader
579
- // still needs to run. Flag that we need to render a fallback and
580
- // render up until the appropriate fallback
581
- renderFallback = true;
582
- if (fallbackIndex >= 0) {
583
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
584
- } else {
585
- renderedMatches = [renderedMatches[0]];
596
+ if (match.route.id) {
597
+ let {
598
+ loaderData,
599
+ errors
600
+ } = dataRouterState;
601
+ let needsToRunLoader = match.route.loader && loaderData[match.route.id] === undefined && (!errors || errors[match.route.id] === undefined);
602
+ if (match.route.lazy || needsToRunLoader) {
603
+ // We found the first route that's not ready to render (waiting on
604
+ // lazy, or has a loader that hasn't run yet). Flag that we need to
605
+ // render a fallback and render up until the appropriate fallback
606
+ renderFallback = true;
607
+ if (fallbackIndex >= 0) {
608
+ renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
609
+ } else {
610
+ renderedMatches = [renderedMatches[0]];
611
+ }
612
+ break;
586
613
  }
587
- break;
588
614
  }
589
615
  }
590
616
  }
@@ -962,7 +988,7 @@
962
988
  // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
963
989
  React__namespace.useLayoutEffect(() => router$1.subscribe(setState), [router$1, setState]);
964
990
  React__namespace.useEffect(() => {
965
- router.UNSAFE_warning(fallbackElement == null || !router$1.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") ;
991
+ router.UNSAFE_warning(fallbackElement == null || !router$1.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") ;
966
992
  // Only log this once on initial mount
967
993
  // eslint-disable-next-line react-hooks/exhaustive-deps
968
994
  }, []);
@@ -987,10 +1013,7 @@
987
1013
  router: router$1,
988
1014
  navigator,
989
1015
  static: false,
990
- basename,
991
- future: {
992
- v7_relativeSplatPath: router$1.future.v7_relativeSplatPath
993
- }
1016
+ basename
994
1017
  }), [router$1, navigator, basename]);
995
1018
 
996
1019
  // The fragment and {null} here are important! We need them to keep React 18's
@@ -1007,8 +1030,11 @@
1007
1030
  basename: basename,
1008
1031
  location: state.location,
1009
1032
  navigationType: state.historyAction,
1010
- navigator: navigator
1011
- }, state.initialized ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
1033
+ navigator: navigator,
1034
+ future: {
1035
+ v7_relativeSplatPath: router$1.future.v7_relativeSplatPath
1036
+ }
1037
+ }, state.initialized || router$1.future.v7_partialHydration ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
1012
1038
  routes: router$1.routes,
1013
1039
  future: router$1.future,
1014
1040
  state: state