Skip to content

Commit caa0895

Browse files
authored
Add deprecation warnings for v7 flags in v6 (#11750)
1 parent 50c59ea commit caa0895

File tree

13 files changed

+155
-11
lines changed

13 files changed

+155
-11
lines changed

.changeset/ninety-queens-thank.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"react-router-dom": minor
3+
"react-router": minor
4+
"@remix-run/router": minor
5+
---
6+
7+
- Log deprecation warnings for v7 flags
8+
- Add deprecation warnings to `json`/`defer` in favor of returning raw objects
9+
- These methods will be removed in React Router v7

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@
108108
"none": "58.1 kB"
109109
},
110110
"packages/react-router/dist/react-router.production.min.js": {
111-
"none": "15.0 kB"
111+
"none": "16.5 kB"
112112
},
113113
"packages/react-router/dist/umd/react-router.production.min.js": {
114-
"none": "17.5 kB"
114+
"none": "19.0 kB"
115115
},
116116
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
117-
"none": "17.3 kB"
117+
"none": "17.5 kB"
118118
},
119119
"packages/react-router-dom/dist/umd/react-router-dom.production.min.js": {
120-
"none": "23.8 kB"
120+
"none": "24.0 kB"
121121
}
122122
},
123123
"pnpm": {

packages/react-router-dom/__tests__/exports-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as ReactRouter from "react-router";
22
import * as ReactRouterDOM from "react-router-dom";
33

44
let nonReExportedKeys = new Set([
5+
"UNSAFE_logV6DeprecationWarnings",
56
"UNSAFE_mapRouteProperties",
67
"UNSAFE_useRoutesImpl",
78
]);

packages/react-router-dom/__tests__/scroll-restoration-test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@ describe(`ScrollRestoration`, () => {
3939
children: testPages,
4040
},
4141
],
42-
{ basename: "/base", window: testWindow }
42+
{
43+
basename: "/base",
44+
window: testWindow,
45+
future: {
46+
v7_fetcherPersist: true,
47+
v7_normalizeFormMethod: true,
48+
v7_partialHydration: true,
49+
v7_skipActionErrorRevalidation: true,
50+
v7_relativeSplatPath: true,
51+
},
52+
}
53+
);
54+
let { container } = render(
55+
<RouterProvider router={router} future={{ v7_startTransition: true }} />
4356
);
44-
let { container } = render(<RouterProvider router={router} />);
4557

4658
expect(getHtml(container)).toMatch("On page 1");
4759

packages/react-router-dom/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
UNSAFE_DataRouterStateContext as DataRouterStateContext,
3434
UNSAFE_NavigationContext as NavigationContext,
3535
UNSAFE_RouteContext as RouteContext,
36+
UNSAFE_logV6DeprecationWarnings as logV6DeprecationWarnings,
3637
UNSAFE_mapRouteProperties as mapRouteProperties,
3738
UNSAFE_useRouteId as useRouteId,
3839
UNSAFE_useRoutesImpl as useRoutesImpl,
@@ -716,6 +717,11 @@ export function RouterProvider({
716717
[router.future.v7_relativeSplatPath]
717718
);
718719

720+
React.useEffect(
721+
() => logV6DeprecationWarnings(future, router.future),
722+
[future, router.future]
723+
);
724+
719725
// The fragment and {null} here are important! We need them to keep React 18's
720726
// useId happy when we are server-rendering since we may have a <script> here
721727
// containing the hydrated server-side staticContext (from StaticRouterProvider).
@@ -807,6 +813,8 @@ export function BrowserRouter({
807813

808814
React.useLayoutEffect(() => history.listen(setState), [history, setState]);
809815

816+
React.useEffect(() => logV6DeprecationWarnings(future), [future]);
817+
810818
return (
811819
<Router
812820
basename={basename}
@@ -858,6 +866,8 @@ export function HashRouter({
858866

859867
React.useLayoutEffect(() => history.listen(setState), [history, setState]);
860868

869+
React.useEffect(() => logV6DeprecationWarnings(future), [future]);
870+
861871
return (
862872
<Router
863873
basename={basename}
@@ -905,6 +915,8 @@ function HistoryRouter({
905915

906916
React.useLayoutEffect(() => history.listen(setState), [history, setState]);
907917

918+
React.useEffect(() => logV6DeprecationWarnings(future), [future]);
919+
908920
return (
909921
<Router
910922
basename={basename}

packages/react-router-native/__tests__/exports-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as ReactRouter from "react-router";
22
import * as ReactRouterNative from "react-router-native";
33

44
let nonReExportedKeys = new Set([
5+
"UNSAFE_logV6DeprecationWarnings",
56
"UNSAFE_mapRouteProperties",
67
"UNSAFE_useRoutesImpl",
78
"UNSAFE_ViewTransitionContext",

packages/react-router/__tests__/Router-basename-test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ describe("<Router basename>", () => {
1616
let renderer: TestRenderer.ReactTestRenderer;
1717
TestRenderer.act(() => {
1818
renderer = TestRenderer.create(
19-
<MemoryRouter basename="/app" initialEntries={["/home"]}>
19+
<MemoryRouter
20+
basename="/app"
21+
initialEntries={["/home"]}
22+
future={{ v7_startTransition: true, v7_relativeSplatPath: true }}
23+
>
2024
<Routes>
2125
<Route path="/" element={<h1>App</h1>} />
2226
</Routes>

packages/react-router/__tests__/Routes-test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ describe("<Routes>", () => {
1919
let renderer: TestRenderer.ReactTestRenderer;
2020
TestRenderer.act(() => {
2121
renderer = TestRenderer.create(
22-
<MemoryRouter>
22+
<MemoryRouter
23+
future={{ v7_startTransition: true, v7_relativeSplatPath: true }}
24+
>
2325
<Routes />
2426
</MemoryRouter>
2527
);

packages/react-router/__tests__/descendant-routes-warning-test.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ describe("Descendant <Routes>", () => {
4141

4242
TestRenderer.act(() => {
4343
TestRenderer.create(
44-
<MemoryRouter initialEntries={["/courses/react"]}>
44+
<MemoryRouter
45+
initialEntries={["/courses/react"]}
46+
future={{ v7_startTransition: true, v7_relativeSplatPath: true }}
47+
>
4548
<Routes>
4649
<Route path="courses" element={<Courses />}>
4750
<Route path="react" element={<ReactCourses />} />
@@ -79,7 +82,10 @@ Please change the parent <Route path="react"> to <Route path="react/*">.`);
7982

8083
TestRenderer.act(() => {
8184
TestRenderer.create(
82-
<MemoryRouter initialEntries={["/"]}>
85+
<MemoryRouter
86+
initialEntries={["/"]}
87+
future={{ v7_startTransition: true, v7_relativeSplatPath: true }}
88+
>
8389
<Routes>
8490
<Route path="/" element={<ReactCourses />} />
8591
</Routes>
@@ -124,7 +130,10 @@ Please change the parent <Route path="/"> to <Route path="*">.`);
124130

125131
TestRenderer.act(() => {
126132
TestRenderer.create(
127-
<MemoryRouter initialEntries={["/courses/react"]}>
133+
<MemoryRouter
134+
initialEntries={["/courses/react"]}
135+
future={{ v7_startTransition: true, v7_relativeSplatPath: true }}
136+
>
128137
<Routes>
129138
<Route path="courses" element={<Courses />}>
130139
<Route path="react/*" element={<ReactCourses />} />

packages/react-router/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import {
124124
useRoutes,
125125
useRoutesImpl,
126126
} from "./lib/hooks";
127+
import { logV6DeprecationWarnings } from "./lib/deprecations";
127128

128129
// Exported for backwards compatibility, but not being used internally anymore
129130
type Hash = string;
@@ -351,4 +352,5 @@ export {
351352
mapRouteProperties as UNSAFE_mapRouteProperties,
352353
useRouteId as UNSAFE_useRouteId,
353354
useRoutesImpl as UNSAFE_useRoutesImpl,
355+
logV6DeprecationWarnings as UNSAFE_logV6DeprecationWarnings,
354356
};

0 commit comments

Comments
 (0)