react-router 6.5.0 → 6.6.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/CHANGELOG.md +8 -0
- package/dist/index.js +36 -16
- package/dist/index.js.map +1 -1
- package/dist/lib/hooks.d.ts +2 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +36 -16
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +36 -16
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.
|
|
2
|
+
* React Router v6.6.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -616,10 +616,12 @@ class RenderErrorBoundary extends React.Component {
|
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
render() {
|
|
619
|
-
return this.state.error ? /*#__PURE__*/React.createElement(
|
|
619
|
+
return this.state.error ? /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
620
|
+
value: this.props.routeContext
|
|
621
|
+
}, /*#__PURE__*/React.createElement(RouteErrorContext.Provider, {
|
|
620
622
|
value: this.state.error,
|
|
621
623
|
children: this.props.component
|
|
622
|
-
}) : this.props.children;
|
|
624
|
+
})) : this.props.children;
|
|
623
625
|
}
|
|
624
626
|
|
|
625
627
|
}
|
|
@@ -666,12 +668,13 @@ function _renderMatches(matches, parentMatches = [], dataRouterState) {
|
|
|
666
668
|
let error = match.route.id ? errors?.[match.route.id] : null; // Only data routers handle errors
|
|
667
669
|
|
|
668
670
|
let errorElement = dataRouterState ? match.route.errorElement || /*#__PURE__*/React.createElement(DefaultErrorElement, null) : null;
|
|
671
|
+
let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
669
672
|
|
|
670
673
|
let getChildren = () => /*#__PURE__*/React.createElement(RenderedRoute, {
|
|
671
674
|
match: match,
|
|
672
675
|
routeContext: {
|
|
673
676
|
outlet,
|
|
674
|
-
matches
|
|
677
|
+
matches
|
|
675
678
|
}
|
|
676
679
|
}, error ? errorElement : match.route.element !== undefined ? match.route.element : outlet); // Only wrap in an error boundary within data router usages when we have an
|
|
677
680
|
// errorElement on this route. Otherwise let it bubble up to an ancestor
|
|
@@ -682,7 +685,11 @@ function _renderMatches(matches, parentMatches = [], dataRouterState) {
|
|
|
682
685
|
location: dataRouterState.location,
|
|
683
686
|
component: errorElement,
|
|
684
687
|
error: error,
|
|
685
|
-
children: getChildren()
|
|
688
|
+
children: getChildren(),
|
|
689
|
+
routeContext: {
|
|
690
|
+
outlet: null,
|
|
691
|
+
matches
|
|
692
|
+
}
|
|
686
693
|
}) : getChildren();
|
|
687
694
|
}, null);
|
|
688
695
|
}
|
|
@@ -719,6 +726,19 @@ function useDataRouterState(hookName) {
|
|
|
719
726
|
!state ? invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
720
727
|
return state;
|
|
721
728
|
}
|
|
729
|
+
|
|
730
|
+
function useRouteContext(hookName) {
|
|
731
|
+
let route = React.useContext(RouteContext);
|
|
732
|
+
!route ? invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
733
|
+
return route;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function useCurrentRouteId(hookName) {
|
|
737
|
+
let route = useRouteContext(hookName);
|
|
738
|
+
let thisRoute = route.matches[route.matches.length - 1];
|
|
739
|
+
!thisRoute.route.id ? invariant(false, `${hookName} can only be used on routes that contain a unique "id"`) : void 0;
|
|
740
|
+
return thisRoute.route.id;
|
|
741
|
+
}
|
|
722
742
|
/**
|
|
723
743
|
* Returns the current navigation, defaulting to an "idle" navigation when
|
|
724
744
|
* no navigation is in progress
|
|
@@ -775,11 +795,14 @@ function useMatches() {
|
|
|
775
795
|
|
|
776
796
|
function useLoaderData() {
|
|
777
797
|
let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
|
778
|
-
let
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
798
|
+
let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
|
799
|
+
|
|
800
|
+
if (state.errors && state.errors[routeId] != null) {
|
|
801
|
+
console.error(`You cannot \`useLoaderData\` in an errorElement (routeId: ${routeId})`);
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
return state.loaderData[routeId];
|
|
783
806
|
}
|
|
784
807
|
/**
|
|
785
808
|
* Returns the loaderData for the given routeId
|
|
@@ -808,18 +831,15 @@ function useActionData() {
|
|
|
808
831
|
function useRouteError() {
|
|
809
832
|
let error = React.useContext(RouteErrorContext);
|
|
810
833
|
let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
|
811
|
-
let
|
|
812
|
-
let thisRoute = route.matches[route.matches.length - 1]; // If this was a render error, we put it in a RouteError context inside
|
|
834
|
+
let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError); // If this was a render error, we put it in a RouteError context inside
|
|
813
835
|
// of RenderErrorBoundary
|
|
814
836
|
|
|
815
837
|
if (error) {
|
|
816
838
|
return error;
|
|
817
|
-
}
|
|
839
|
+
} // Otherwise look for errors from our data router state
|
|
818
840
|
|
|
819
|
-
!route ? invariant(false, `useRouteError must be used inside a RouteContext`) : void 0;
|
|
820
|
-
!thisRoute.route.id ? invariant(false, `useRouteError can only be used on routes that contain a unique "id"`) : void 0; // Otherwise look for errors from our data router state
|
|
821
841
|
|
|
822
|
-
return state.errors?.[
|
|
842
|
+
return state.errors?.[routeId];
|
|
823
843
|
}
|
|
824
844
|
/**
|
|
825
845
|
* Returns the happy-path data from the nearest ancestor <Await /> value
|