Skip to content

Commit

Permalink
feat(router): support v7_startTransition configuration (#6461)
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe authored Oct 30, 2024
1 parent 3dc0bca commit 2492002
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/silent-weeks-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime': patch
---

feat(router): support v7_startTransition configuration
feat(router): 支持 v7_startTransition 配置
2 changes: 2 additions & 0 deletions packages/runtime/plugin-runtime/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { Plugin } from './core/plugin';
import type { RouterConfig } from './router';
import type { StateConfig } from './state';

export const isBrowser = () =>
typeof window !== 'undefined' && window.name !== 'nodejs';

export interface AppConfig {
state?: StateConfig | boolean;
router?: Pick<RouterConfig, 'future' | 'basename'>;
[key: string]: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) || '/';
Expand Down Expand Up @@ -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.
<>
<RouterProvider router={router} />
<RouterProvider router={router} future={future} />
<Null />
<Null />
</>
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/plugin-runtime/src/router/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export type RouterConfig = {
supportHtml5History?: boolean;
basename?: string;
createRoutes?: () => RouteObject[];
future?: Partial<{
v7_startTransition: boolean;
}>;
};

export type Routes = RouterConfig['routesConfig']['routes'];
Expand Down

0 comments on commit 2492002

Please sign in to comment.