react-router 0.0.0-experimental-4a8a492a → 0.0.0-experimental-e0f088aa

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-4a8a492a
2
+ * React Router v0.0.0-experimental-e0f088aa
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -59,12 +59,6 @@
59
59
  {
60
60
  DataRouterStateContext.displayName = "DataRouterState";
61
61
  }
62
- const ViewTransitionContext = /*#__PURE__*/React__namespace.createContext({
63
- isTransitioning: false
64
- });
65
- {
66
- ViewTransitionContext.displayName = "ViewTransition";
67
- }
68
62
  const AwaitContext = /*#__PURE__*/React__namespace.createContext(null);
69
63
  {
70
64
  AwaitContext.displayName = "Await";
@@ -895,36 +889,6 @@
895
889
  */
896
890
  const START_TRANSITION = "startTransition";
897
891
  const startTransitionImpl = React__namespace[START_TRANSITION];
898
- function startTransitionSafe(cb) {
899
- if (startTransitionImpl) {
900
- startTransitionImpl(cb);
901
- } else {
902
- cb();
903
- }
904
- }
905
- class Deferred {
906
- // @ts-expect-error - no initializer
907
-
908
- // @ts-expect-error - no initializer
909
-
910
- constructor() {
911
- this.status = "pending";
912
- this.promise = new Promise((resolve, reject) => {
913
- this.resolve = value => {
914
- if (this.status === "pending") {
915
- this.status = "resolved";
916
- resolve(value);
917
- }
918
- };
919
- this.reject = reason => {
920
- if (this.status === "pending") {
921
- this.status = "rejected";
922
- reject(reason);
923
- }
924
- };
925
- });
926
- }
927
- }
928
892
 
929
893
  /**
930
894
  * Given a Remix Router instance, render the appropriate UI
@@ -936,107 +900,20 @@
936
900
  future
937
901
  } = _ref;
938
902
  let [state, setStateImpl] = React__namespace.useState(router.state);
939
- let [pendingState, setPendingState] = React__namespace.useState();
940
- let [vtContext, setVtContext] = React__namespace.useState({
941
- isTransitioning: false
942
- });
943
- let [renderDfd, setRenderDfd] = React__namespace.useState();
944
- let [transition, setTransition] = React__namespace.useState();
945
- let [interruption, setInterruption] = React__namespace.useState();
946
903
  let {
947
904
  v7_startTransition
948
905
  } = future || {};
949
- let optInStartTransition = React__namespace.useCallback(cb => {
950
- if (v7_startTransition) {
951
- startTransitionSafe(cb);
952
- } else {
953
- cb();
954
- }
955
- }, [v7_startTransition]);
956
- let setState = React__namespace.useCallback((newState, _ref2) => {
957
- let {
958
- viewTransitionOpts
959
- } = _ref2;
960
- if (!viewTransitionOpts || typeof document.startViewTransition !== "function") {
961
- // Mid-navigation state update, or startViewTransition isn't available
962
- optInStartTransition(() => setStateImpl(newState));
963
- } else if (transition && renderDfd) {
964
- // Interrupting an in-progress transition, cancel and let everything flush
965
- // out, and then kick off a new transition from the interruption state
966
- renderDfd.resolve();
967
- transition.skipTransition();
968
- setInterruption({
969
- state: newState,
970
- currentLocation: viewTransitionOpts.currentLocation,
971
- nextLocation: viewTransitionOpts.nextLocation
972
- });
906
+ let setState = React__namespace.useCallback(newState => {
907
+ if (v7_startTransition && startTransitionImpl) {
908
+ startTransitionImpl(() => setStateImpl(newState));
973
909
  } else {
974
- // Completed navigation update with opted-in view transitions, let 'er rip
975
- setPendingState(newState);
976
- setVtContext({
977
- isTransitioning: true,
978
- currentLocation: viewTransitionOpts.currentLocation,
979
- nextLocation: viewTransitionOpts.nextLocation
980
- });
910
+ setStateImpl(newState);
981
911
  }
982
- }, [optInStartTransition, transition, renderDfd]);
912
+ }, [setStateImpl, v7_startTransition]);
983
913
 
984
914
  // Need to use a layout effect here so we are subscribed early enough to
985
915
  // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
986
916
  React__namespace.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
987
-
988
- // When we start a view transition, create a Deferred we can use for the
989
- // eventual "completed" render
990
- React__namespace.useEffect(() => {
991
- if (vtContext.isTransitioning) {
992
- setRenderDfd(new Deferred());
993
- }
994
- }, [vtContext.isTransitioning]);
995
-
996
- // Once the deferred is created, kick off startViewTransition() to update the
997
- // DOM and then wait on the Deferred to resolve (indicating the DOM update has
998
- // happened)
999
- React__namespace.useEffect(() => {
1000
- if (renderDfd && pendingState) {
1001
- let newState = pendingState;
1002
- let renderPromise = renderDfd.promise;
1003
- let transition = document.startViewTransition(async () => {
1004
- optInStartTransition(() => setStateImpl(newState));
1005
- await renderPromise;
1006
- });
1007
- transition.finished.finally(() => {
1008
- setRenderDfd(undefined);
1009
- setTransition(undefined);
1010
- setPendingState(undefined);
1011
- setVtContext({
1012
- isTransitioning: false
1013
- });
1014
- });
1015
- setTransition(transition);
1016
- }
1017
- }, [optInStartTransition, pendingState, renderDfd]);
1018
-
1019
- // When the new location finally renders and is committed to the DOM, this
1020
- // effect will run to resolve the transition
1021
- React__namespace.useEffect(() => {
1022
- if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
1023
- renderDfd.resolve();
1024
- }
1025
- }, [renderDfd, transition, state.location, pendingState]);
1026
-
1027
- // If we get interrupted with a new navigation during a transition, we skip
1028
- // the active transition, let it cleanup, then kick it off again here
1029
- React__namespace.useEffect(() => {
1030
- if (!vtContext.isTransitioning && interruption) {
1031
- setPendingState(interruption.state);
1032
- setVtContext({
1033
- isTransitioning: true,
1034
- currentLocation: interruption.currentLocation,
1035
- nextLocation: interruption.nextLocation
1036
- });
1037
- setInterruption(undefined);
1038
- }
1039
- }, [vtContext.isTransitioning, interruption]);
1040
917
  let navigator = React__namespace.useMemo(() => {
1041
918
  return {
1042
919
  createHref: router.createHref,
@@ -1071,8 +948,6 @@
1071
948
  value: dataRouterContext
1072
949
  }, /*#__PURE__*/React__namespace.createElement(DataRouterStateContext.Provider, {
1073
950
  value: state
1074
- }, /*#__PURE__*/React__namespace.createElement(ViewTransitionContext.Provider, {
1075
- value: vtContext
1076
951
  }, /*#__PURE__*/React__namespace.createElement(Router, {
1077
952
  basename: basename,
1078
953
  location: state.location,
@@ -1081,13 +956,13 @@
1081
956
  }, state.initialized ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
1082
957
  routes: router.routes,
1083
958
  state: state
1084
- }) : fallbackElement)))), null);
959
+ }) : fallbackElement))), null);
1085
960
  }
1086
- function DataRoutes(_ref3) {
961
+ function DataRoutes(_ref2) {
1087
962
  let {
1088
963
  routes,
1089
964
  state
1090
- } = _ref3;
965
+ } = _ref2;
1091
966
  return useRoutesImpl(routes, undefined, state);
1092
967
  }
1093
968
  /**
@@ -1095,14 +970,14 @@
1095
970
  *
1096
971
  * @see https://reactrouter.com/router-components/memory-router
1097
972
  */
1098
- function MemoryRouter(_ref4) {
973
+ function MemoryRouter(_ref3) {
1099
974
  let {
1100
975
  basename,
1101
976
  children,
1102
977
  initialEntries,
1103
978
  initialIndex,
1104
979
  future
1105
- } = _ref4;
980
+ } = _ref3;
1106
981
  let historyRef = React__namespace.useRef();
1107
982
  if (historyRef.current == null) {
1108
983
  historyRef.current = router.createMemoryHistory({
@@ -1140,13 +1015,13 @@
1140
1015
  *
1141
1016
  * @see https://reactrouter.com/components/navigate
1142
1017
  */
1143
- function Navigate(_ref5) {
1018
+ function Navigate(_ref4) {
1144
1019
  let {
1145
1020
  to,
1146
1021
  replace,
1147
1022
  state,
1148
1023
  relative
1149
- } = _ref5;
1024
+ } = _ref4;
1150
1025
  !useInRouterContext() ? router.UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
1151
1026
  // the router loaded. We can help them understand how to avoid that.
1152
1027
  "<Navigate> may be used only in the context of a <Router> component.") : void 0;
@@ -1195,7 +1070,7 @@
1195
1070
  *
1196
1071
  * @see https://reactrouter.com/router-components/router
1197
1072
  */
1198
- function Router(_ref6) {
1073
+ function Router(_ref5) {
1199
1074
  let {
1200
1075
  basename: basenameProp = "/",
1201
1076
  children = null,
@@ -1203,7 +1078,7 @@
1203
1078
  navigationType = router.Action.Pop,
1204
1079
  navigator,
1205
1080
  static: staticProp = false
1206
- } = _ref6;
1081
+ } = _ref5;
1207
1082
  !!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;
1208
1083
 
1209
1084
  // Preserve trailing slashes on basename, so we can let the user control
@@ -1257,23 +1132,23 @@
1257
1132
  *
1258
1133
  * @see https://reactrouter.com/components/routes
1259
1134
  */
1260
- function Routes(_ref7) {
1135
+ function Routes(_ref6) {
1261
1136
  let {
1262
1137
  children,
1263
1138
  location
1264
- } = _ref7;
1139
+ } = _ref6;
1265
1140
  return useRoutes(createRoutesFromChildren(children), location);
1266
1141
  }
1267
1142
  /**
1268
1143
  * Component to use for rendering lazily loaded data from returning defer()
1269
1144
  * in a loader function
1270
1145
  */
1271
- function Await(_ref8) {
1146
+ function Await(_ref7) {
1272
1147
  let {
1273
1148
  children,
1274
1149
  errorElement,
1275
1150
  resolve
1276
- } = _ref8;
1151
+ } = _ref7;
1277
1152
  return /*#__PURE__*/React__namespace.createElement(AwaitErrorBoundary, {
1278
1153
  resolve: resolve,
1279
1154
  errorElement: errorElement
@@ -1378,10 +1253,10 @@
1378
1253
  * @private
1379
1254
  * Indirection to leverage useAsyncValue for a render-prop API on `<Await>`
1380
1255
  */
1381
- function ResolveAwait(_ref9) {
1256
+ function ResolveAwait(_ref8) {
1382
1257
  let {
1383
1258
  children
1384
- } = _ref9;
1259
+ } = _ref8;
1385
1260
  let data = useAsyncValue();
1386
1261
  let toRender = typeof children === "function" ? children(data) : children;
1387
1262
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, toRender);
@@ -1559,7 +1434,6 @@
1559
1434
  exports.UNSAFE_LocationContext = LocationContext;
1560
1435
  exports.UNSAFE_NavigationContext = NavigationContext;
1561
1436
  exports.UNSAFE_RouteContext = RouteContext;
1562
- exports.UNSAFE_ViewTransitionContext = ViewTransitionContext;
1563
1437
  exports.UNSAFE_mapRouteProperties = mapRouteProperties;
1564
1438
  exports.UNSAFE_useRouteId = useRouteId;
1565
1439
  exports.UNSAFE_useRoutesImpl = useRoutesImpl;