react-router 6.3.0 → 6.4.0-pre.3
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/.eslintrc +12 -0
- package/CHANGELOG.md +8 -0
- package/__tests__/.eslintrc +8 -0
- package/__tests__/DataMemoryRouter-test.tsx +1902 -0
- package/__tests__/Route-test.tsx +45 -0
- package/__tests__/Router-basename-test.tsx +110 -0
- package/__tests__/Router-test.tsx +62 -0
- package/__tests__/Routes-location-test.tsx +69 -0
- package/__tests__/Routes-test.tsx +148 -0
- package/__tests__/__snapshots__/route-matching-test.tsx.snap +197 -0
- package/__tests__/absolute-path-matching-test.tsx +61 -0
- package/__tests__/createRoutesFromChildren-test.tsx +189 -0
- package/__tests__/descendant-routes-params-test.tsx +67 -0
- package/__tests__/descendant-routes-splat-matching-test.tsx +241 -0
- package/__tests__/descendant-routes-warning-test.tsx +140 -0
- package/__tests__/generatePath-test.tsx +45 -0
- package/__tests__/gh-issue-8127-test.tsx +32 -0
- package/__tests__/gh-issue-8165-test.tsx +97 -0
- package/__tests__/greedy-matching-test.tsx +89 -0
- package/__tests__/index-routes-test.tsx +24 -0
- package/__tests__/layout-routes-test.tsx +283 -0
- package/__tests__/matchPath-test.tsx +335 -0
- package/__tests__/matchRoutes-test.tsx +144 -0
- package/__tests__/navigate-test.tsx +49 -0
- package/__tests__/params-decode-test.tsx +36 -0
- package/__tests__/path-matching-test.tsx +270 -0
- package/__tests__/resolvePath-test.tsx +50 -0
- package/__tests__/route-depth-order-matching-test.tsx +135 -0
- package/__tests__/route-matching-test.tsx +164 -0
- package/__tests__/same-component-lifecycle-test.tsx +57 -0
- package/__tests__/setup.ts +15 -0
- package/__tests__/useHref-basename-test.tsx +351 -0
- package/__tests__/useHref-test.tsx +287 -0
- package/__tests__/useLocation-test.tsx +29 -0
- package/__tests__/useMatch-test.tsx +137 -0
- package/__tests__/useNavigate-test.tsx +100 -0
- package/__tests__/useOutlet-test.tsx +355 -0
- package/__tests__/useParams-test.tsx +212 -0
- package/__tests__/useResolvedPath-test.tsx +109 -0
- package/__tests__/useRoutes-test.tsx +122 -0
- package/__tests__/utils/renderStrict.tsx +21 -0
- package/__tests__/utils/waitForRedirect.tsx +5 -0
- package/index.ts +187 -0
- package/jest-transformer.js +10 -0
- package/jest.config.js +10 -0
- package/lib/components.tsx +491 -0
- package/lib/context.ts +96 -0
- package/lib/hooks.tsx +689 -0
- package/lib/use-sync-external-store-shim/index.ts +31 -0
- package/lib/use-sync-external-store-shim/useSyncExternalStoreShimClient.ts +153 -0
- package/lib/use-sync-external-store-shim/useSyncExternalStoreShimServer.ts +20 -0
- package/node-main.js +7 -0
- package/package.json +7 -4
- package/tsconfig.json +20 -0
- package/LICENSE.md +0 -22
- package/index.d.ts +0 -14
- package/index.js +0 -941
- package/index.js.map +0 -1
- package/lib/components.d.ts +0 -110
- package/lib/context.d.ts +0 -31
- package/lib/hooks.d.ts +0 -99
- package/lib/router.d.ts +0 -120
- package/main.js +0 -19
- package/react-router.development.js +0 -895
- package/react-router.development.js.map +0 -1
- package/react-router.production.min.js +0 -12
- package/react-router.production.min.js.map +0 -1
- package/umd/react-router.development.js +0 -990
- package/umd/react-router.development.js.map +0 -1
- package/umd/react-router.production.min.js +0 -12
- package/umd/react-router.production.min.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inlined into the react-router repo since use-sync-external-store does not
|
|
3
|
+
* provide a UMD-compatible package, so we need this to be able to distribute
|
|
4
|
+
* UMD react-router bundles
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
* @flow
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as React from "react";
|
|
17
|
+
|
|
18
|
+
import { useSyncExternalStore as client } from "./useSyncExternalStoreShimClient";
|
|
19
|
+
import { useSyncExternalStore as server } from "./useSyncExternalStoreShimServer";
|
|
20
|
+
|
|
21
|
+
const canUseDOM: boolean = !!(
|
|
22
|
+
typeof window !== "undefined" &&
|
|
23
|
+
typeof window.document !== "undefined" &&
|
|
24
|
+
typeof window.document.createElement !== "undefined"
|
|
25
|
+
);
|
|
26
|
+
const isServerEnvironment = !canUseDOM;
|
|
27
|
+
const shim = isServerEnvironment ? server : client;
|
|
28
|
+
|
|
29
|
+
export const useSyncExternalStore =
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
13
|
+
*/
|
|
14
|
+
function isPolyfill(x: any, y: any) {
|
|
15
|
+
return (
|
|
16
|
+
(x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const is: (x: any, y: any) => boolean =
|
|
21
|
+
typeof Object.is === "function" ? Object.is : isPolyfill;
|
|
22
|
+
|
|
23
|
+
// Intentionally not using named imports because Rollup uses dynamic
|
|
24
|
+
// dispatch for CommonJS interop named imports.
|
|
25
|
+
const { useState, useEffect, useLayoutEffect, useDebugValue } = React;
|
|
26
|
+
|
|
27
|
+
let didWarnOld18Alpha = false;
|
|
28
|
+
let didWarnUncachedGetSnapshot = false;
|
|
29
|
+
|
|
30
|
+
// Disclaimer: This shim breaks many of the rules of React, and only works
|
|
31
|
+
// because of a very particular set of implementation details and assumptions
|
|
32
|
+
// -- change any one of them and it will break. The most important assumption
|
|
33
|
+
// is that updates are always synchronous, because concurrent rendering is
|
|
34
|
+
// only available in versions of React that also have a built-in
|
|
35
|
+
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
36
|
+
// does not exist.
|
|
37
|
+
//
|
|
38
|
+
// Do not assume that the clever hacks used by this hook also work in general.
|
|
39
|
+
// The point of this shim is to replace the need for hacks by other libraries.
|
|
40
|
+
export function useSyncExternalStore<T>(
|
|
41
|
+
subscribe: (fn: () => void) => () => void,
|
|
42
|
+
getSnapshot: () => T,
|
|
43
|
+
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
44
|
+
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
45
|
+
// will need to track that themselves and return the correct value
|
|
46
|
+
// from `getSnapshot`.
|
|
47
|
+
getServerSnapshot?: () => T
|
|
48
|
+
): T {
|
|
49
|
+
if (__DEV__) {
|
|
50
|
+
if (!didWarnOld18Alpha) {
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
if (React.startTransition !== undefined) {
|
|
53
|
+
didWarnOld18Alpha = true;
|
|
54
|
+
console.error(
|
|
55
|
+
"You are using an outdated, pre-release alpha of React 18 that " +
|
|
56
|
+
"does not support useSyncExternalStore. The " +
|
|
57
|
+
"use-sync-external-store shim will not work correctly. Upgrade " +
|
|
58
|
+
"to a newer pre-release."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Read the current snapshot from the store on every render. Again, this
|
|
65
|
+
// breaks the rules of React, and only works here because of specific
|
|
66
|
+
// implementation details, most importantly that updates are
|
|
67
|
+
// always synchronous.
|
|
68
|
+
const value = getSnapshot();
|
|
69
|
+
if (__DEV__) {
|
|
70
|
+
if (!didWarnUncachedGetSnapshot) {
|
|
71
|
+
const cachedValue = getSnapshot();
|
|
72
|
+
if (!is(value, cachedValue)) {
|
|
73
|
+
console.error(
|
|
74
|
+
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
75
|
+
);
|
|
76
|
+
didWarnUncachedGetSnapshot = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Because updates are synchronous, we don't queue them. Instead we force a
|
|
82
|
+
// re-render whenever the subscribed state changes by updating an some
|
|
83
|
+
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
84
|
+
// the current value.
|
|
85
|
+
//
|
|
86
|
+
// Because we don't actually use the state returned by the useState hook, we
|
|
87
|
+
// can save a bit of memory by storing other stuff in that slot.
|
|
88
|
+
//
|
|
89
|
+
// To implement the early bailout, we need to track some things on a mutable
|
|
90
|
+
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
91
|
+
// our useState hook instead.
|
|
92
|
+
//
|
|
93
|
+
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
94
|
+
// new object always fails an equality check.
|
|
95
|
+
const [{ inst }, forceUpdate] = useState({ inst: { value, getSnapshot } });
|
|
96
|
+
|
|
97
|
+
// Track the latest getSnapshot function with a ref. This needs to be updated
|
|
98
|
+
// in the layout phase so we can access it during the tearing check that
|
|
99
|
+
// happens on subscribe.
|
|
100
|
+
useLayoutEffect(() => {
|
|
101
|
+
inst.value = value;
|
|
102
|
+
inst.getSnapshot = getSnapshot;
|
|
103
|
+
|
|
104
|
+
// Whenever getSnapshot or subscribe changes, we need to check in the
|
|
105
|
+
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
106
|
+
// this can happen all the time, but even in synchronous mode, an earlier
|
|
107
|
+
// effect may have mutated the store.
|
|
108
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
109
|
+
// Force a re-render.
|
|
110
|
+
forceUpdate({ inst });
|
|
111
|
+
}
|
|
112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
|
+
}, [subscribe, value, getSnapshot]);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
// Check for changes right before subscribing. Subsequent changes will be
|
|
117
|
+
// detected in the subscription handler.
|
|
118
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
119
|
+
// Force a re-render.
|
|
120
|
+
forceUpdate({ inst });
|
|
121
|
+
}
|
|
122
|
+
const handleStoreChange = () => {
|
|
123
|
+
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
124
|
+
// up to the consumer of this library to wrap their subscription event
|
|
125
|
+
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
126
|
+
// the case and print a warning in development?
|
|
127
|
+
|
|
128
|
+
// The store changed. Check if the snapshot changed since the last time we
|
|
129
|
+
// read from the store.
|
|
130
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
131
|
+
// Force a re-render.
|
|
132
|
+
forceUpdate({ inst });
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
// Subscribe to the store and return a clean-up function.
|
|
136
|
+
return subscribe(handleStoreChange);
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
}, [subscribe]);
|
|
139
|
+
|
|
140
|
+
useDebugValue(value);
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function checkIfSnapshotChanged(inst: any) {
|
|
145
|
+
const latestGetSnapshot = inst.getSnapshot;
|
|
146
|
+
const prevValue = inst.value;
|
|
147
|
+
try {
|
|
148
|
+
const nextValue = latestGetSnapshot();
|
|
149
|
+
return !is(prevValue, nextValue);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function useSyncExternalStore<T>(
|
|
11
|
+
subscribe: (fn: () => void) => () => void,
|
|
12
|
+
getSnapshot: () => T,
|
|
13
|
+
getServerSnapshot?: () => T
|
|
14
|
+
): T {
|
|
15
|
+
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
16
|
+
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
17
|
+
// will need to track that themselves and return the correct value
|
|
18
|
+
// from `getSnapshot`.
|
|
19
|
+
return getSnapshot();
|
|
20
|
+
}
|
package/node-main.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-pre.3",
|
|
4
4
|
"author": "Remix Software <hello@remix.run>",
|
|
5
5
|
"description": "Declarative routing for React",
|
|
6
6
|
"repository": {
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
"module": "./index.js",
|
|
14
14
|
"types": "./index.d.ts",
|
|
15
15
|
"unpkg": "./umd/react-router.production.min.js",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@remix-run/router": "0.2.0-pre.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"react": "^17.0.2"
|
|
21
|
+
},
|
|
16
22
|
"peerDependencies": {
|
|
17
23
|
"react": ">=16.8"
|
|
18
24
|
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"history": "^5.2.0"
|
|
21
|
-
},
|
|
22
25
|
"sideEffects": false,
|
|
23
26
|
"keywords": [
|
|
24
27
|
"react",
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": ["index.ts"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
5
|
+
"target": "ES2020",
|
|
6
|
+
"module": "ES2020",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
|
|
9
|
+
"strict": true,
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"emitDeclarationOnly": true,
|
|
14
|
+
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
|
|
17
|
+
"outDir": "../../build/node_modules/react-router",
|
|
18
|
+
"rootDir": "."
|
|
19
|
+
}
|
|
20
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) React Training 2015-2019
|
|
4
|
-
Copyright (c) Remix Software 2020-2021
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
package/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Hash, Location, Path, Pathname, Search, To } from "history";
|
|
2
|
-
import { Action as NavigationType, parsePath, createPath } from "history";
|
|
3
|
-
import type { MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps } from "./lib/components";
|
|
4
|
-
import { createRoutesFromChildren, renderMatches, MemoryRouter, Navigate, Outlet, Route, Router, Routes } from "./lib/components";
|
|
5
|
-
import type { Navigator } from "./lib/context";
|
|
6
|
-
import { LocationContext, NavigationContext, RouteContext } from "./lib/context";
|
|
7
|
-
import type { NavigateFunction, NavigateOptions } from "./lib/hooks";
|
|
8
|
-
import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes } from "./lib/hooks";
|
|
9
|
-
import type { Params, PathMatch, PathPattern, RouteMatch, RouteObject } from "./lib/router";
|
|
10
|
-
import { generatePath, matchPath, matchRoutes, resolvePath } from "./lib/router";
|
|
11
|
-
export type { Hash, IndexRouteProps, LayoutRouteProps, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, OutletProps, PathMatch, PathPattern, PathRouteProps, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Navigator, Params, Path, Pathname, Search, To, };
|
|
12
|
-
export { MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, };
|
|
13
|
-
/** @internal */
|
|
14
|
-
export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, };
|