react-router 0.0.0-experimental-35fa15e5 → 0.0.0-experimental-8bb3ffdf

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-35fa15e5
2
+ * React Router v0.0.0-experimental-8bb3ffdf
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -226,6 +226,7 @@
226
226
  let dataRouterContext = React__namespace.useContext(DataRouterContext);
227
227
  let {
228
228
  basename,
229
+ future,
229
230
  navigator
230
231
  } = React__namespace.useContext(NavigationContext);
231
232
  let {
@@ -234,7 +235,7 @@
234
235
  let {
235
236
  pathname: locationPathname
236
237
  } = useLocation();
237
- let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches));
238
+ let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath));
238
239
  let activeRef = React__namespace.useRef(false);
239
240
  useIsomorphicLayoutEffect(() => {
240
241
  activeRef.current = true;
@@ -317,13 +318,16 @@
317
318
  let {
318
319
  relative
319
320
  } = _temp2 === void 0 ? {} : _temp2;
321
+ let {
322
+ future
323
+ } = React__namespace.useContext(NavigationContext);
320
324
  let {
321
325
  matches
322
326
  } = React__namespace.useContext(RouteContext);
323
327
  let {
324
328
  pathname: locationPathname
325
329
  } = useLocation();
326
- let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches));
330
+ let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath));
327
331
  return React__namespace.useMemo(() => router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
328
332
  }
329
333
 
@@ -396,7 +400,7 @@
396
400
  });
397
401
  {
398
402
  router.UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") ;
399
- 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.") ;
403
+ 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.") ;
400
404
  }
401
405
  let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
402
406
  params: Object.assign({}, parentParams, match.params),
@@ -494,7 +498,7 @@
494
498
  // this because the error provided from the app state may be cleared without
495
499
  // the location changing.
496
500
  return {
497
- error: props.error || state.error,
501
+ error: props.error !== undefined ? props.error : state.error,
498
502
  location: state.location,
499
503
  revalidation: props.revalidation || state.revalidation
500
504
  };
@@ -503,7 +507,7 @@
503
507
  console.error("React Router caught the following error during render", error, errorInfo);
504
508
  }
505
509
  render() {
506
- return this.state.error ? /*#__PURE__*/React__namespace.createElement(RouteContext.Provider, {
510
+ return this.state.error !== undefined ? /*#__PURE__*/React__namespace.createElement(RouteContext.Provider, {
507
511
  value: this.props.routeContext
508
512
  }, /*#__PURE__*/React__namespace.createElement(RouteErrorContext.Provider, {
509
513
  value: this.state.error,
@@ -570,17 +574,24 @@
570
574
  if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
571
575
  fallbackIndex = i;
572
576
  }
573
- if (match.route.loader && match.route.id && dataRouterState.loaderData[match.route.id] === undefined && (!dataRouterState.errors || dataRouterState.errors[match.route.id] === undefined)) {
574
- // We found the first route without data/errors which means it's loader
575
- // still needs to run. Flag that we need to render a fallback and
576
- // render up until the appropriate fallback
577
- renderFallback = true;
578
- if (fallbackIndex >= 0) {
579
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
580
- } else {
581
- renderedMatches = [renderedMatches[0]];
577
+ if (match.route.id) {
578
+ let {
579
+ loaderData,
580
+ errors
581
+ } = dataRouterState;
582
+ let needsToRunLoader = match.route.loader && loaderData[match.route.id] === undefined && (!errors || errors[match.route.id] === undefined);
583
+ if (match.route.lazy || needsToRunLoader) {
584
+ // We found the first route that's not ready to render (waiting on
585
+ // lazy, or has a loader that hasn't run yet). Flag that we need to
586
+ // render a fallback and render up until the appropriate fallback
587
+ renderFallback = true;
588
+ if (fallbackIndex >= 0) {
589
+ renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
590
+ } else {
591
+ renderedMatches = [renderedMatches[0]];
592
+ }
593
+ break;
582
594
  }
583
- break;
584
595
  }
585
596
  }
586
597
  }
@@ -591,7 +602,7 @@
591
602
  let errorElement = null;
592
603
  let hydrateFallbackElement = null;
593
604
  if (dataRouterState) {
594
- error = errors && match.route.id ? errors[match.route.id] : null;
605
+ error = errors && match.route.id ? errors[match.route.id] : undefined;
595
606
  errorElement = match.route.errorElement || defaultErrorElement;
596
607
  if (renderFallback) {
597
608
  if (fallbackIndex < 0 && index === 0) {
@@ -781,7 +792,7 @@
781
792
 
782
793
  // If this was a render error, we put it in a RouteError context inside
783
794
  // of RenderErrorBoundary
784
- if (error) {
795
+ if (error !== undefined) {
785
796
  return error;
786
797
  }
787
798
 
@@ -958,7 +969,7 @@
958
969
  // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
959
970
  React__namespace.useLayoutEffect(() => router$1.subscribe(setState), [router$1, setState]);
960
971
  React__namespace.useEffect(() => {
961
- router.UNSAFE_warning(fallbackElement == null || !router$1.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") ;
972
+ router.UNSAFE_warning(fallbackElement == null || !router$1.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") ;
962
973
  // Only log this once on initial mount
963
974
  // eslint-disable-next-line react-hooks/exhaustive-deps
964
975
  }, []);
@@ -1000,8 +1011,11 @@
1000
1011
  basename: basename,
1001
1012
  location: state.location,
1002
1013
  navigationType: state.historyAction,
1003
- navigator: navigator
1004
- }, state.initialized ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
1014
+ navigator: navigator,
1015
+ future: {
1016
+ v7_relativeSplatPath: router$1.future.v7_relativeSplatPath
1017
+ }
1018
+ }, state.initialized || router$1.future.v7_partialHydration ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
1005
1019
  routes: router$1.routes,
1006
1020
  future: router$1.future,
1007
1021
  state: state
@@ -1053,7 +1067,8 @@
1053
1067
  children: children,
1054
1068
  location: state.location,
1055
1069
  navigationType: state.action,
1056
- navigator: history
1070
+ navigator: history,
1071
+ future: future
1057
1072
  });
1058
1073
  }
1059
1074
  /**
@@ -1075,7 +1090,11 @@
1075
1090
  !useInRouterContext() ? router.UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
1076
1091
  // the router loaded. We can help them understand how to avoid that.
1077
1092
  "<Navigate> may be used only in the context of a <Router> component.") : void 0;
1078
- router.UNSAFE_warning(!React__namespace.useContext(NavigationContext).static, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") ;
1093
+ let {
1094
+ future,
1095
+ static: isStatic
1096
+ } = React__namespace.useContext(NavigationContext);
1097
+ router.UNSAFE_warning(!isStatic, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") ;
1079
1098
  let {
1080
1099
  matches
1081
1100
  } = React__namespace.useContext(RouteContext);
@@ -1086,7 +1105,7 @@
1086
1105
 
1087
1106
  // Resolve the path outside of the effect so that when effects run twice in
1088
1107
  // StrictMode they navigate to the same place
1089
- let path = router.resolveTo(to, router.UNSAFE_getResolveToMatches(matches), locationPathname, relative === "path");
1108
+ let path = router.resolveTo(to, router.UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath), locationPathname, relative === "path");
1090
1109
  let jsonPath = JSON.stringify(path);
1091
1110
  React__namespace.useEffect(() => navigate(JSON.parse(jsonPath), {
1092
1111
  replace,
@@ -1127,7 +1146,8 @@
1127
1146
  location: locationProp,
1128
1147
  navigationType = router.Action.Pop,
1129
1148
  navigator,
1130
- static: staticProp = false
1149
+ static: staticProp = false,
1150
+ future
1131
1151
  } = _ref5;
1132
1152
  !!useInRouterContext() ? router.UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : void 0;
1133
1153
 
@@ -1137,8 +1157,11 @@
1137
1157
  let navigationContext = React__namespace.useMemo(() => ({
1138
1158
  basename,
1139
1159
  navigator,
1140
- static: staticProp
1141
- }), [basename, navigator, staticProp]);
1160
+ static: staticProp,
1161
+ future: _extends({
1162
+ v7_relativeSplatPath: false
1163
+ }, future)
1164
+ }), [basename, future, navigator, staticProp]);
1142
1165
  if (typeof locationProp === "string") {
1143
1166
  locationProp = router.parsePath(locationProp);
1144
1167
  }