react-router-dom-v5-compat 6.16.0-pre.2 → 6.17.0-pre.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 CHANGED
@@ -1,34 +1,20 @@
1
1
  # `react-router-dom-v5-compat`
2
2
 
3
- ## 6.16.0-pre.2
3
+ ## 6.17.0-pre.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - Updated dependencies:
8
- - `react-router@6.16.0-pre.2`
9
- - `react-router-dom@6.16.0-pre.2`
8
+ - `react-router@6.17.0-pre.0`
9
+ - `react-router-dom@6.17.0-pre.0`
10
10
 
11
- ## 6.16.0-pre.1
12
-
13
- ### Patch Changes
14
-
15
- - Updated dependencies:
16
- - `react-router-dom@6.16.0-pre.1`
17
- - `react-router@6.16.0-pre.1`
18
-
19
- ## 6.16.0-pre.0
11
+ ## 6.16.0
20
12
 
21
13
  ### Minor Changes
22
14
 
23
- - Removed internal API only required for the Remix v1 back-compat layer and no longer needed in Remix v2 (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`) ([#10715](https://github.com/remix-run/react-router/pull/10715))
24
-
25
- ### Patch Changes
26
-
27
- - Move the `@private` class export `ErrorResponse` to an `UNSAFE_ErrorResponseImpl` export since it is an implementation detail and there should be no construction of `ErrorResponse` instances in userland. This frees us up to export a `type ErrorResponse` which correlates to an instance of the class via `InstanceType`. Userland code should only ever be using `ErrorResponse` as a type and should be type-narrowing via `isRouteErrorResponse`. ([#10811](https://github.com/remix-run/react-router/pull/10811))
28
- - Export `ShouldRevalidateFunctionArgs` interface ([#10797](https://github.com/remix-run/react-router/pull/10797))
29
15
  - Updated dependencies:
30
- - `react-router-dom@6.16.0-pre.0`
31
- - `react-router@6.16.0-pre.0`
16
+ - `react-router-dom@6.16.0`
17
+ - `react-router@6.16.0`
32
18
 
33
19
  ## 6.15.0
34
20
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router DOM v5 Compat v6.16.0-pre.2
2
+ * React Router DOM v5 Compat v6.17.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,9 +9,9 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import { UNSAFE_mapRouteProperties, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext, Routes, Route } from 'react-router';
12
+ import { UNSAFE_mapRouteProperties, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_ViewTransitionContext, UNSAFE_DataRouterContext, Routes, Route } from 'react-router';
13
13
  export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
14
- import { stripBasename, UNSAFE_warning, createRouter, createBrowserHistory, createHashHistory, UNSAFE_ErrorResponseImpl, UNSAFE_invariant, joinPaths } from '@remix-run/router';
14
+ import { stripBasename, UNSAFE_warning, createRouter, createBrowserHistory, createHashHistory, UNSAFE_ErrorResponseImpl, UNSAFE_invariant, joinPaths, matchPath } from '@remix-run/router';
15
15
  import { parsePath, Action, createPath as createPath$1 } from 'history';
16
16
  import { Route as Route$1, useHistory } from 'react-router-dom';
17
17
 
@@ -208,9 +208,9 @@ function getFormSubmissionInfo(target, basename) {
208
208
  };
209
209
  }
210
210
 
211
- const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset"],
212
- _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"],
213
- _excluded3 = ["reloadDocument", "replace", "state", "method", "action", "onSubmit", "submit", "relative", "preventScrollReset"];
211
+ const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset", "unstable_viewTransition"],
212
+ _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "unstable_viewTransition", "children"],
213
+ _excluded3 = ["reloadDocument", "replace", "state", "method", "action", "onSubmit", "submit", "relative", "preventScrollReset", "unstable_viewTransition"];
214
214
  function createBrowserRouter(routes, opts) {
215
215
  return createRouter({
216
216
  basename: opts == null ? void 0 : opts.basename,
@@ -222,7 +222,8 @@ function createBrowserRouter(routes, opts) {
222
222
  }),
223
223
  hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
224
224
  routes,
225
- mapRouteProperties: UNSAFE_mapRouteProperties
225
+ mapRouteProperties: UNSAFE_mapRouteProperties,
226
+ window: opts == null ? void 0 : opts.window
226
227
  }).initialize();
227
228
  }
228
229
  function createHashRouter(routes, opts) {
@@ -236,7 +237,8 @@ function createHashRouter(routes, opts) {
236
237
  }),
237
238
  hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
238
239
  routes,
239
- mapRouteProperties: UNSAFE_mapRouteProperties
240
+ mapRouteProperties: UNSAFE_mapRouteProperties,
241
+ window: opts == null ? void 0 : opts.window
240
242
  }).initialize();
241
243
  }
242
244
  function parseHydrationData() {
@@ -428,7 +430,7 @@ if (process.env.NODE_ENV !== "production") {
428
430
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
429
431
  const ABSOLUTE_URL_REGEX$1 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
430
432
  /**
431
- * The public API for rendering a history-aware <a>.
433
+ * The public API for rendering a history-aware `<a>`.
432
434
  */
433
435
  const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
434
436
  let {
@@ -439,7 +441,8 @@ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
439
441
  state,
440
442
  target,
441
443
  to,
442
- preventScrollReset
444
+ preventScrollReset,
445
+ unstable_viewTransition
443
446
  } = _ref4,
444
447
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
445
448
  let {
@@ -478,7 +481,8 @@ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
478
481
  state,
479
482
  target,
480
483
  preventScrollReset,
481
- relative
484
+ relative,
485
+ unstable_viewTransition
482
486
  });
483
487
  function handleClick(event) {
484
488
  if (onClick) onClick(event);
@@ -501,7 +505,7 @@ if (process.env.NODE_ENV !== "production") {
501
505
  Link.displayName = "Link";
502
506
  }
503
507
  /**
504
- * A <Link> wrapper that knows if it's "active" or not.
508
+ * A `<Link>` wrapper that knows if it's "active" or not.
505
509
  */
506
510
  const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref) {
507
511
  let {
@@ -511,6 +515,7 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref
511
515
  end = false,
512
516
  style: styleProp,
513
517
  to,
518
+ unstable_viewTransition,
514
519
  children
515
520
  } = _ref5,
516
521
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded2);
@@ -522,6 +527,10 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref
522
527
  let {
523
528
  navigator
524
529
  } = React.useContext(UNSAFE_NavigationContext);
530
+ let isTransitioning = routerState != null &&
531
+ // Conditional usage is OK here because the usage of a data router is static
532
+ // eslint-disable-next-line react-hooks/rules-of-hooks
533
+ useViewTransitionState(path) && unstable_viewTransition === true;
525
534
  let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
526
535
  let locationPathname = location.pathname;
527
536
  let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
@@ -532,35 +541,32 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref
532
541
  }
533
542
  let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(toPathname.length) === "/";
534
543
  let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
544
+ let renderProps = {
545
+ isActive,
546
+ isPending,
547
+ isTransitioning
548
+ };
535
549
  let ariaCurrent = isActive ? ariaCurrentProp : undefined;
536
550
  let className;
537
551
  if (typeof classNameProp === "function") {
538
- className = classNameProp({
539
- isActive,
540
- isPending
541
- });
552
+ className = classNameProp(renderProps);
542
553
  } else {
543
554
  // If the className prop is not a function, we use a default `active`
544
555
  // class for <NavLink />s that are active. In v5 `active` was the default
545
556
  // value for `activeClassName`, but we are removing that API and can still
546
557
  // use the old default behavior for a cleaner upgrade path and keep the
547
558
  // simple styling rules working as they currently do.
548
- className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null].filter(Boolean).join(" ");
559
+ className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null, isTransitioning ? "transitioning" : null].filter(Boolean).join(" ");
549
560
  }
550
- let style = typeof styleProp === "function" ? styleProp({
551
- isActive,
552
- isPending
553
- }) : styleProp;
561
+ let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
554
562
  return /*#__PURE__*/React.createElement(Link, _extends({}, rest, {
555
563
  "aria-current": ariaCurrent,
556
564
  className: className,
557
565
  ref: ref,
558
566
  style: style,
559
- to: to
560
- }), typeof children === "function" ? children({
561
- isActive,
562
- isPending
563
- }) : children);
567
+ to: to,
568
+ unstable_viewTransition: unstable_viewTransition
569
+ }), typeof children === "function" ? children(renderProps) : children);
564
570
  });
565
571
  if (process.env.NODE_ENV !== "production") {
566
572
  NavLink.displayName = "NavLink";
@@ -591,7 +597,8 @@ const FormImpl = /*#__PURE__*/React.forwardRef((_ref6, forwardedRef) => {
591
597
  onSubmit,
592
598
  submit,
593
599
  relative,
594
- preventScrollReset
600
+ preventScrollReset,
601
+ unstable_viewTransition
595
602
  } = _ref6,
596
603
  props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
597
604
  let formMethod = method.toLowerCase() === "get" ? "get" : "post";
@@ -609,7 +616,8 @@ const FormImpl = /*#__PURE__*/React.forwardRef((_ref6, forwardedRef) => {
609
616
  replace,
610
617
  state,
611
618
  relative,
612
- preventScrollReset
619
+ preventScrollReset,
620
+ unstable_viewTransition
613
621
  });
614
622
  };
615
623
  return /*#__PURE__*/React.createElement("form", _extends({
@@ -650,6 +658,8 @@ var DataRouterHook;
650
658
  DataRouterHook["UseSubmit"] = "useSubmit";
651
659
  DataRouterHook["UseSubmitFetcher"] = "useSubmitFetcher";
652
660
  DataRouterHook["UseFetcher"] = "useFetcher";
661
+ DataRouterHook["useViewTransitionStates"] = "useViewTransitionStates";
662
+ DataRouterHook["useViewTransitionState"] = "useViewTransitionState";
653
663
  })(DataRouterHook || (DataRouterHook = {}));
654
664
  var DataRouterStateHook;
655
665
  (function (DataRouterStateHook) {
@@ -680,7 +690,8 @@ function useLinkClickHandler(to, _temp) {
680
690
  replace: replaceProp,
681
691
  state,
682
692
  preventScrollReset,
683
- relative
693
+ relative,
694
+ unstable_viewTransition
684
695
  } = _temp === void 0 ? {} : _temp;
685
696
  let navigate = useNavigate();
686
697
  let location = useLocation();
@@ -697,10 +708,11 @@ function useLinkClickHandler(to, _temp) {
697
708
  replace,
698
709
  state,
699
710
  preventScrollReset,
700
- relative
711
+ relative,
712
+ unstable_viewTransition
701
713
  });
702
714
  }
703
- }, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative]);
715
+ }, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, unstable_viewTransition]);
704
716
  }
705
717
  /**
706
718
  * A convenient wrapper for reading and writing search parameters via the
@@ -761,7 +773,8 @@ function useSubmit() {
761
773
  formEncType: options.encType || encType,
762
774
  replace: options.replace,
763
775
  state: options.state,
764
- fromRouteId: currentRouteId
776
+ fromRouteId: currentRouteId,
777
+ unstable_viewTransition: options.unstable_viewTransition
765
778
  });
766
779
  }, [router, basename, currentRouteId]);
767
780
  }
@@ -948,7 +961,11 @@ function useScrollRestoration(_temp3) {
948
961
  let key = (getKey ? getKey(location, matches) : null) || location.key;
949
962
  savedScrollPositions[key] = window.scrollY;
950
963
  }
951
- sessionStorage.setItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY, JSON.stringify(savedScrollPositions));
964
+ try {
965
+ sessionStorage.setItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY, JSON.stringify(savedScrollPositions));
966
+ } catch (error) {
967
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (" + error + ").") : void 0;
968
+ }
952
969
  window.history.scrollRestoration = "auto";
953
970
  }, [storageKey, getKey, navigation.state, location, matches]));
954
971
  // Read in any saved scroll locations
@@ -1080,6 +1097,45 @@ function usePrompt(_ref8) {
1080
1097
  }
1081
1098
  }, [blocker, when]);
1082
1099
  }
1100
+ /**
1101
+ * Return a boolean indicating if there is an active view transition to the
1102
+ * given href. You can use this value to render CSS classes or viewTransitionName
1103
+ * styles onto your elements
1104
+ *
1105
+ * @param href The destination href
1106
+ * @param [opts.relative] Relative routing type ("route" | "path")
1107
+ */
1108
+ function useViewTransitionState(to, opts) {
1109
+ if (opts === void 0) {
1110
+ opts = {};
1111
+ }
1112
+ let vtContext = React.useContext(UNSAFE_ViewTransitionContext);
1113
+ let {
1114
+ basename
1115
+ } = useDataRouterContext(DataRouterHook.useViewTransitionState);
1116
+ let path = useResolvedPath(to, {
1117
+ relative: opts.relative
1118
+ });
1119
+ if (vtContext.isTransitioning) {
1120
+ let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
1121
+ let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
1122
+ // Transition is active if we're going to or coming from the indicated
1123
+ // destination. This ensures that other PUSH navigations that reverse
1124
+ // an indicated transition apply. I.e., on the list view you have:
1125
+ //
1126
+ // <NavLink to="/details/1" unstable_viewTransition>
1127
+ //
1128
+ // If you click the breadcrumb back to the list view:
1129
+ //
1130
+ // <NavLink to="/list" unstable_viewTransition>
1131
+ //
1132
+ // We should apply the transition because it's indicated as active going
1133
+ // from /list -> /details/1 and therefore should be active on the reverse
1134
+ // (even though this isn't strictly a POP reverse)
1135
+ return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
1136
+ }
1137
+ return false;
1138
+ }
1083
1139
  //#endregion
1084
1140
 
1085
1141
  // v5 isn't in TypeScript, they'll also lose the @types/react-router with this
@@ -1126,7 +1182,7 @@ function CompatRouter(_ref) {
1126
1182
  }
1127
1183
  const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1128
1184
  /**
1129
- * A <Router> that may not navigate to any other location. This is useful
1185
+ * A `<Router>` that may not navigate to any other location. This is useful
1130
1186
  * on the server where there is no stateful UI.
1131
1187
  */
1132
1188
  function StaticRouter(_ref2) {