Skip to content

Commit e81eeaf

Browse files
authored
refactor: guard react router consistency (#3724)
* refactor: guard react-router version consistency * chore: changeset
1 parent 1ef03dc commit e81eeaf

File tree

23 files changed

+111
-45
lines changed

23 files changed

+111
-45
lines changed

.changeset/good-eels-give.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/plugin-data-loader': patch
3+
'@modern-js/runtime': patch
4+
'@modern-js/utils': patch
5+
---
6+
7+
refactor: guard react-router version consistency
8+
refactor: 保证 react-router 相关包的版本一致性

packages/cli/plugin-data-loader/src/cli/createRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable node/prefer-global/url */
33
import { compile } from 'path-to-regexp';
44
import { redirect } from 'react-router-dom';
5-
import { type UNSAFE_DeferredData as DeferredData } from '@modern-js/utils/runtime/router';
5+
import { type UNSAFE_DeferredData as DeferredData } from '@modern-js/utils/runtime/remix-router';
66
import {
77
LOADER_ID_PARAM,
88
DIRECT_PARAM,

packages/cli/plugin-data-loader/src/cli/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {
1414
UNSAFE_DeferredData as DeferredData,
1515
AbortedDeferredError,
16-
} from '@modern-js/utils/runtime/router';
16+
} from '@modern-js/utils/runtime/remix-router';
1717

1818
const DEFERRED_VALUE_PLACEHOLDER_PREFIX = '__deferred_promise:';
1919
export async function parseDeferredReadableStream(

packages/cli/plugin-data-loader/src/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
ErrorResponse,
1111
UNSAFE_DEFERRED_SYMBOL as DEFERRED_SYMBOL,
1212
type UNSAFE_DeferredData as DeferredData,
13-
transformNestedRoutes,
14-
} from '@modern-js/utils/runtime/router';
13+
} from '@modern-js/utils/runtime/remix-router';
14+
import { transformNestedRoutes } from '@modern-js/utils/runtime/nested-routes';
1515
import { isPlainObject } from '@modern-js/utils/lodash';
1616
import { CONTENT_TYPE_DEFERRED, LOADER_ID_PARAM } from '../common/constants';
1717
import { matchEntry, ServerContext } from '../common/utils';

packages/cli/plugin-data-loader/src/runtime/response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TextEncoder } from 'util';
1111
import {
1212
type UNSAFE_DeferredData as DeferredData,
1313
type TrackedPromise,
14-
} from '@modern-js/utils/runtime/router';
14+
} from '@modern-js/utils/runtime/remix-router';
1515
import { serializeJson } from '@modern-js/utils/runtime-node';
1616

1717
function isTrackedPromise(value: any): value is TrackedPromise {

packages/runtime/plugin-runtime/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@
175175
"invariant": "^2.2.4",
176176
"react-helmet": "^6.1.0",
177177
"react-is": "^18",
178-
"react-router-dom": "^6.8.1",
179178
"react-side-effect": "^2.1.1",
180179
"redux-logger": "^3.0.6",
181180
"styled-components": "^5.3.1",

packages/runtime/plugin-runtime/src/router/runtime/DeferredDataScripts.node.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable react/no-danger */
2-
import { TrackedPromise } from '@modern-js/utils/runtime/router';
2+
import { type TrackedPromise } from '@modern-js/utils/runtime/remix-router';
33
import { Suspense, useEffect, useRef, useMemo, useContext } from 'react';
44
import {
55
Await,
66
UNSAFE_DataRouterContext as DataRouterContext,
77
useAsyncError,
8-
} from 'react-router-dom';
8+
} from '@modern-js/utils/runtime/router';
99
import { serializeJson } from '@modern-js/utils/runtime-node';
1010
import { JSX_SHELL_STREAM_END_MARK } from '../../common';
1111
import { serializeErrors } from './utils';

packages/runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
useMatches,
1515
NavLink as RouterNavLink,
1616
NavLinkProps as RouterNavLinkProps,
17-
} from 'react-router-dom';
17+
} from '@modern-js/utils/runtime/router';
1818
import { RuntimeReactContext } from '../../core';
1919
import { RouteAssets, RouteManifest } from './types';
2020

packages/runtime/plugin-runtime/src/router/runtime/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createWaterfall } from '@modern-js/plugin';
2-
import { RouteObject } from 'react-router-dom';
2+
import { RouteObject } from '@modern-js/utils/runtime/router';
33

44
const modifyRoutes = createWaterfall<RouteObject[]>();
55

packages/runtime/plugin-runtime/src/router/runtime/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRouteLoaderData as useRouteData } from 'react-router-dom';
1+
import { useRouteLoaderData as useRouteData } from '@modern-js/utils/runtime/router';
22
import { routerPlugin } from './plugin';
33
import type { SingleRouteConfig, RouterConfig } from './types';
44

@@ -78,7 +78,7 @@ export type {
7878
Search,
7979
ShouldRevalidateFunction,
8080
To,
81-
} from 'react-router-dom';
81+
} from '@modern-js/utils/runtime/router';
8282

8383
// Note: Keep in sync with react-router-dom exports!
8484
export {
@@ -144,9 +144,7 @@ export {
144144
createPath,
145145
unstable_useBlocker,
146146
unstable_usePrompt,
147-
} from 'react-router-dom';
148-
149-
// `react-router-dom` has its own dependency: `@remix-run/router`.
150-
// In order to make sure `plugin-data-loader` and user's loaders(mainly `defer` API) depend on the singleton of `@remix-run/router`,
151-
// we export these API from the same package `@modern-js/utils/runtime`.
152-
export { defer, json, redirect } from '@modern-js/utils/runtime/router';
147+
defer,
148+
json,
149+
redirect,
150+
} from '@modern-js/utils/runtime/router';

0 commit comments

Comments
 (0)