react-router-dom-v5-compat 6.18.0 → 6.19.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,5 +1,13 @@
1
1
  # `react-router-dom-v5-compat`
2
2
 
3
+ ## 6.19.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - `react-router-dom@6.19.0`
9
+ - `react-router@6.19.0`
10
+
3
11
  ## 6.18.0
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -47,6 +47,6 @@
47
47
  * deprecate the deep require if we wanted to avoid the duplication here.
48
48
  */
49
49
  export type { ActionFunction, ActionFunctionArgs, AwaitProps, BrowserRouterProps, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FetcherWithComponents, FormEncType, FormMethod, FormProps, GetScrollRestorationKeyFunction, Hash, HashRouterProps, HistoryRouterProps, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LinkProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavLinkProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, ParamKeyValuePair, ParamParseKey, Params, Path, PathMatch, PathPattern, PathRouteProps, Pathname, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, ScrollRestorationProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, SubmitFunction, SubmitOptions, To, URLSearchParamsInit, UIMatch, unstable_Blocker, unstable_BlockerFunction, } from "./react-router-dom";
50
- export { AbortedDeferredError, Await, BrowserRouter, Form, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, createSearchParams, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, unstable_HistoryRouter, unstable_useBlocker, unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, } from "./react-router-dom";
50
+ export { AbortedDeferredError, Await, BrowserRouter, Form, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, createSearchParams, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, unstable_HistoryRouter, useBlocker, unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, } from "./react-router-dom";
51
51
  export type { StaticRouterProps } from "./lib/components";
52
52
  export { CompatRoute, CompatRouter, StaticRouter } from "./lib/components";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router DOM v5 Compat v6.18.0
2
+ * React Router DOM v5 Compat v6.19.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,8 +9,9 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import { UNSAFE_mapRouteProperties, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, Router, UNSAFE_useRoutesImpl, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, Routes, Route } from 'react-router';
13
- export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, 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';
12
+ import * as ReactDOM from 'react-dom';
13
+ import { UNSAFE_mapRouteProperties, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, Router, UNSAFE_useRoutesImpl, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, useBlocker, Routes, Route } from 'react-router';
14
+ export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, 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, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
14
15
  import { stripBasename, UNSAFE_warning, createRouter, createBrowserHistory, createHashHistory, UNSAFE_ErrorResponseImpl, UNSAFE_invariant, joinPaths, IDLE_FETCHER, matchPath } from '@remix-run/router';
15
16
  import { parsePath, Action, createPath as createPath$1 } from 'history';
16
17
  import { Route as Route$1, useHistory } from 'react-router-dom';
@@ -327,6 +328,8 @@ if (process.env.NODE_ENV !== "production") {
327
328
  */
328
329
  const START_TRANSITION = "startTransition";
329
330
  const startTransitionImpl = React[START_TRANSITION];
331
+ const FLUSH_SYNC = "flushSync";
332
+ const flushSyncImpl = ReactDOM[FLUSH_SYNC];
330
333
  function startTransitionSafe(cb) {
331
334
  if (startTransitionImpl) {
332
335
  startTransitionImpl(cb);
@@ -334,6 +337,13 @@ function startTransitionSafe(cb) {
334
337
  cb();
335
338
  }
336
339
  }
340
+ function flushSyncSafe(cb) {
341
+ if (flushSyncImpl) {
342
+ flushSyncImpl(cb);
343
+ } else {
344
+ cb();
345
+ }
346
+ }
337
347
  class Deferred {
338
348
  constructor() {
339
349
  this.status = "pending";
@@ -384,6 +394,7 @@ function RouterProvider(_ref) {
384
394
  let setState = React.useCallback((newState, _ref2) => {
385
395
  let {
386
396
  deletedFetchers,
397
+ unstable_flushSync: flushSync,
387
398
  unstable_viewTransitionOpts: viewTransitionOpts
388
399
  } = _ref2;
389
400
  deletedFetchers.forEach(key => fetcherData.current.delete(key));
@@ -392,13 +403,56 @@ function RouterProvider(_ref) {
392
403
  fetcherData.current.set(key, fetcher.data);
393
404
  }
394
405
  });
395
- if (!viewTransitionOpts || router.window == null || typeof router.window.document.startViewTransition !== "function") {
396
- // Mid-navigation state update, or startViewTransition isn't available
397
- optInStartTransition(() => setStateImpl(newState));
398
- } else if (transition && renderDfd) {
406
+ let isViewTransitionUnavailable = router.window == null || typeof router.window.document.startViewTransition !== "function";
407
+ // If this isn't a view transition or it's not available in this browser,
408
+ // just update and be done with it
409
+ if (!viewTransitionOpts || isViewTransitionUnavailable) {
410
+ if (flushSync) {
411
+ flushSyncSafe(() => setStateImpl(newState));
412
+ } else {
413
+ optInStartTransition(() => setStateImpl(newState));
414
+ }
415
+ return;
416
+ }
417
+ // flushSync + startViewTransition
418
+ if (flushSync) {
419
+ // Flush through the context to mark DOM elements as transition=ing
420
+ flushSyncSafe(() => {
421
+ // Cancel any pending transitions
422
+ if (transition) {
423
+ renderDfd && renderDfd.resolve();
424
+ transition.skipTransition();
425
+ }
426
+ setVtContext({
427
+ isTransitioning: true,
428
+ flushSync: true,
429
+ currentLocation: viewTransitionOpts.currentLocation,
430
+ nextLocation: viewTransitionOpts.nextLocation
431
+ });
432
+ });
433
+ // Update the DOM
434
+ let t = router.window.document.startViewTransition(() => {
435
+ flushSyncSafe(() => setStateImpl(newState));
436
+ });
437
+ // Clean up after the animation completes
438
+ t.finished.finally(() => {
439
+ flushSyncSafe(() => {
440
+ setRenderDfd(undefined);
441
+ setTransition(undefined);
442
+ setPendingState(undefined);
443
+ setVtContext({
444
+ isTransitioning: false
445
+ });
446
+ });
447
+ });
448
+ flushSyncSafe(() => setTransition(t));
449
+ return;
450
+ }
451
+ // startTransition + startViewTransition
452
+ if (transition) {
399
453
  // Interrupting an in-progress transition, cancel and let everything flush
400
454
  // out, and then kick off a new transition from the interruption state
401
- renderDfd.resolve();
455
+ renderDfd && renderDfd.resolve();
402
456
  transition.skipTransition();
403
457
  setInterruption({
404
458
  state: newState,
@@ -410,6 +464,7 @@ function RouterProvider(_ref) {
410
464
  setPendingState(newState);
411
465
  setVtContext({
412
466
  isTransitioning: true,
467
+ flushSync: false,
413
468
  currentLocation: viewTransitionOpts.currentLocation,
414
469
  nextLocation: viewTransitionOpts.nextLocation
415
470
  });
@@ -421,10 +476,10 @@ function RouterProvider(_ref) {
421
476
  // When we start a view transition, create a Deferred we can use for the
422
477
  // eventual "completed" render
423
478
  React.useEffect(() => {
424
- if (vtContext.isTransitioning) {
479
+ if (vtContext.isTransitioning && !vtContext.flushSync) {
425
480
  setRenderDfd(new Deferred());
426
481
  }
427
- }, [vtContext.isTransitioning]);
482
+ }, [vtContext]);
428
483
  // Once the deferred is created, kick off startViewTransition() to update the
429
484
  // DOM and then wait on the Deferred to resolve (indicating the DOM update has
430
485
  // happened)
@@ -461,6 +516,7 @@ function RouterProvider(_ref) {
461
516
  setPendingState(interruption.state);
462
517
  setVtContext({
463
518
  isTransitioning: true,
519
+ flushSync: false,
464
520
  currentLocation: interruption.currentLocation,
465
521
  nextLocation: interruption.nextLocation
466
522
  });
@@ -743,7 +799,13 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref
743
799
  nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
744
800
  toPathname = toPathname.toLowerCase();
745
801
  }
746
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(toPathname.length) === "/";
802
+ // If the `to` has a trailing slash, look at that exact spot. Otherwise,
803
+ // we're looking for a slash _after_ what's in `to`. For example:
804
+ //
805
+ // <NavLink to="/users"> and <NavLink to="/users/">
806
+ // both want to look for a / at index 6 to match URL `/users/matt`
807
+ const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
808
+ let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
747
809
  let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
748
810
  let renderProps = {
749
811
  isActive,
@@ -974,7 +1036,8 @@ function useSubmit() {
974
1036
  formData,
975
1037
  body,
976
1038
  formMethod: options.method || method,
977
- formEncType: options.encType || encType
1039
+ formEncType: options.encType || encType,
1040
+ unstable_flushSync: options.unstable_flushSync
978
1041
  });
979
1042
  } else {
980
1043
  router.navigate(options.action || action, {
@@ -986,6 +1049,7 @@ function useSubmit() {
986
1049
  replace: options.replace,
987
1050
  state: options.state,
988
1051
  fromRouteId: currentRouteId,
1052
+ unstable_flushSync: options.unstable_flushSync,
989
1053
  unstable_viewTransition: options.unstable_viewTransition
990
1054
  });
991
1055
  }
@@ -1008,21 +1072,19 @@ function useFormAction(action, _temp2) {
1008
1072
  let path = _extends({}, useResolvedPath(action ? action : ".", {
1009
1073
  relative
1010
1074
  }));
1011
- // Previously we set the default action to ".". The problem with this is that
1012
- // `useResolvedPath(".")` excludes search params of the resolved URL. This is
1013
- // the intended behavior of when "." is specifically provided as
1014
- // the form action, but inconsistent w/ browsers when the action is omitted.
1075
+ // If no action was specified, browsers will persist current search params
1076
+ // when determining the path, so match that behavior
1015
1077
  // https://github.com/remix-run/remix/issues/927
1016
1078
  let location = useLocation();
1017
1079
  if (action == null) {
1018
1080
  // Safe to write to this directly here since if action was undefined, we
1019
1081
  // would have called useResolvedPath(".") which will never include a search
1020
1082
  path.search = location.search;
1021
- // When grabbing search params from the URL, remove the automatically
1022
- // inserted ?index param so we match the useResolvedPath search behavior
1023
- // which would not include ?index
1024
- if (match.route.index) {
1025
- let params = new URLSearchParams(path.search);
1083
+ // When grabbing search params from the URL, remove any included ?index param
1084
+ // since it might not apply to our contextual route. We add it back based
1085
+ // on match.route.index below
1086
+ let params = new URLSearchParams(path.search);
1087
+ if (params.has("index") && params.get("index") === "") {
1026
1088
  params.delete("index");
1027
1089
  path.search = params.toString() ? "?" + params.toString() : "";
1028
1090
  }
@@ -1061,7 +1123,9 @@ function useFetcher(_temp3) {
1061
1123
  !(routeId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0;
1062
1124
  // Fetcher key handling
1063
1125
  let [fetcherKey, setFetcherKey] = React.useState(key || "");
1064
- if (!fetcherKey) {
1126
+ if (key && key !== fetcherKey) {
1127
+ setFetcherKey(key);
1128
+ } else if (!fetcherKey) {
1065
1129
  setFetcherKey(getUniqueFetcherId());
1066
1130
  }
1067
1131
  // Registration/cleanup
@@ -1075,9 +1139,9 @@ function useFetcher(_temp3) {
1075
1139
  };
1076
1140
  }, [router, fetcherKey]);
1077
1141
  // Fetcher additions
1078
- let load = React.useCallback(href => {
1142
+ let load = React.useCallback((href, opts) => {
1079
1143
  !routeId ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for fetcher.load()") : UNSAFE_invariant(false) : void 0;
1080
- router.fetch(fetcherKey, routeId, href);
1144
+ router.fetch(fetcherKey, routeId, href, opts);
1081
1145
  }, [fetcherKey, routeId, router]);
1082
1146
  let submitImpl = useSubmit();
1083
1147
  let submit = React.useCallback((target, opts) => {
@@ -1276,7 +1340,7 @@ function usePrompt(_ref12) {
1276
1340
  when,
1277
1341
  message
1278
1342
  } = _ref12;
1279
- let blocker = unstable_useBlocker(when);
1343
+ let blocker = useBlocker(when);
1280
1344
  React.useEffect(() => {
1281
1345
  if (blocker.state === "blocked") {
1282
1346
  let proceed = window.confirm(message);