From 2492002c5f9ae6a4925733205baea2c8bbc45204 Mon Sep 17 00:00:00 2001 From: Ming Date: Wed, 30 Oct 2024 12:05:36 +0800 Subject: [PATCH] feat(router): support v7_startTransition configuration (#6461) --- .changeset/silent-weeks-allow.md | 6 ++++++ packages/runtime/plugin-runtime/src/common.ts | 2 ++ .../runtime/plugin-runtime/src/router/runtime/plugin.tsx | 3 ++- packages/runtime/plugin-runtime/src/router/runtime/types.ts | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/silent-weeks-allow.md diff --git a/.changeset/silent-weeks-allow.md b/.changeset/silent-weeks-allow.md new file mode 100644 index 000000000000..b0bf18de0ef3 --- /dev/null +++ b/.changeset/silent-weeks-allow.md @@ -0,0 +1,6 @@ +--- +'@modern-js/runtime': patch +--- + +feat(router): support v7_startTransition configuration +feat(router): 支持 v7_startTransition 配置 diff --git a/packages/runtime/plugin-runtime/src/common.ts b/packages/runtime/plugin-runtime/src/common.ts index 99bdb30567a1..a93d33eddf2e 100644 --- a/packages/runtime/plugin-runtime/src/common.ts +++ b/packages/runtime/plugin-runtime/src/common.ts @@ -1,4 +1,5 @@ import type { Plugin } from './core/plugin'; +import type { RouterConfig } from './router'; import type { StateConfig } from './state'; export const isBrowser = () => @@ -6,6 +7,7 @@ export const isBrowser = () => export interface AppConfig { state?: StateConfig | boolean; + router?: Pick; [key: string]: any; } diff --git a/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx b/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx index cf3100dc13a1..cbb7a0087964 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx +++ b/packages/runtime/plugin-runtime/src/router/runtime/plugin.tsx @@ -70,6 +70,7 @@ export const routerPlugin = ( basename = '', routesConfig, createRoutes, + future, } = merge(pluginConfig.router || {}, userConfig) as RouterConfig; const select = (pathname: string) => serverBase.find(baseUrl => pathname.search(baseUrl) === 0) || '/'; @@ -181,7 +182,7 @@ export const routerPlugin = ( // According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct. // To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render. <> - + diff --git a/packages/runtime/plugin-runtime/src/router/runtime/types.ts b/packages/runtime/plugin-runtime/src/router/runtime/types.ts index 94b3c19cb5c3..25f7bc7d7975 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/types.ts +++ b/packages/runtime/plugin-runtime/src/router/runtime/types.ts @@ -47,6 +47,9 @@ export type RouterConfig = { supportHtml5History?: boolean; basename?: string; createRoutes?: () => RouteObject[]; + future?: Partial<{ + v7_startTransition: boolean; + }>; }; export type Routes = RouterConfig['routesConfig']['routes'];