Skip to content

Commit 00e5d60

Browse files
authored
fix: should not rely on runtimeByEntries (#7948)
1 parent 359c4eb commit 00e5d60

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

packages/runtime/plugin-runtime/src/cli/code.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ import { resolveSSRMode } from './ssr/mode';
2020
import * as template from './template';
2121
import * as serverTemplate from './template.server';
2222

23-
function getSSRMode(
24-
entry: string,
25-
config: AppToolsNormalizedConfig,
26-
): 'string' | 'stream' | false {
27-
return resolveSSRMode({ entry, config });
28-
}
29-
3023
export const generateCode = async (
3124
entrypoints: Entrypoint[],
3225
appContext: AppToolsContext,
@@ -45,15 +38,25 @@ export const generateCode = async (
4538
} = appContext;
4639
await Promise.all(
4740
entrypoints.map(async entrypoint => {
48-
const { entryName, isAutoMount, entry, customEntry, customServerEntry } =
49-
entrypoint;
41+
const {
42+
entryName,
43+
isAutoMount,
44+
entry,
45+
customEntry,
46+
customServerEntry,
47+
nestedRoutesEntry,
48+
} = entrypoint;
5049
const { plugins: runtimePlugins } =
5150
await hooks._internalRuntimePlugins.call({
5251
entrypoint,
5352
plugins: [],
5453
});
5554
if (isAutoMount) {
56-
const ssrMode = getSSRMode(entryName, config);
55+
const ssrMode = resolveSSRMode({
56+
entry: entryName,
57+
config,
58+
nestedRoutesEntry,
59+
});
5760
let indexCode = '';
5861
// index.jsx
5962
if (!ssrMode && config.server.rsc) {

packages/runtime/plugin-runtime/src/cli/ssr/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
ServerUserConfig,
77
} from '@modern-js/app-tools';
88
import type { CLIPluginAPI } from '@modern-js/plugin';
9+
import type { Entrypoint } from '@modern-js/types';
910
import { LOADABLE_STATS_FILE, isUseSSRBundle } from '@modern-js/utils';
1011
import type { RsbuildPlugin } from '@rsbuild/core';
1112
import { resolveSSRMode } from './mode';
@@ -43,12 +44,32 @@ const hasStringSSREntry = (userConfig: AppToolsNormalizedConfig): boolean => {
4344
return false;
4445
};
4546

47+
/**
48+
* Check if any entry uses string SSR mode.
49+
* Returns true if at least one entry uses 'string' SSR mode.
50+
*/
4651
const checkUseStringSSR = (
4752
config: AppToolsNormalizedConfig,
4853
appDirectory?: string,
54+
entrypoints?: Entrypoint[],
4955
): boolean => {
50-
const ssrMode = resolveSSRMode({ config, appDirectory });
51-
return ssrMode === 'string';
56+
// If entrypoints are provided, check each entry
57+
if (entrypoints && entrypoints.length > 0) {
58+
for (const entrypoint of entrypoints) {
59+
const ssrMode = resolveSSRMode({
60+
entry: entrypoint.entryName,
61+
config,
62+
appDirectory,
63+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
64+
});
65+
if (ssrMode === 'string') {
66+
return true;
67+
}
68+
}
69+
return false;
70+
}
71+
72+
return true;
5273
};
5374

5475
const ssrBuilderPlugin = (
@@ -70,12 +91,12 @@ const ssrBuilderPlugin = (
7091
: 'node';
7192

7293
const appContext = modernAPI.getAppContext();
73-
const { appDirectory } = appContext;
94+
const { appDirectory, entrypoints } = appContext;
7495

7596
const useLoadablePlugin =
7697
isUseSSRBundle(userConfig) &&
7798
!isServerEnvironment &&
78-
checkUseStringSSR(userConfig, appDirectory);
99+
checkUseStringSSR(userConfig, appDirectory, entrypoints);
79100

80101
return mergeEnvironmentConfig(config, {
81102
source: {

packages/runtime/plugin-runtime/src/cli/ssr/mode.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export function resolveSSRMode(params: {
1717
entry?: string;
1818
config: AppToolsNormalizedConfig;
1919
appDirectory?: string;
20+
nestedRoutesEntry?: string;
2021
}): SSRMode {
21-
const { entry, config, appDirectory } = params;
22+
const { entry, config, appDirectory, nestedRoutesEntry } = params;
2223

2324
// 1. Check if SSG is enabled first (SSG takes precedence over SSR when both are configured)
2425
const isSsgEnabled =
@@ -29,19 +30,11 @@ export function resolveSSRMode(params: {
2930
: Object.keys(config.output.ssgByEntries).length > 0));
3031

3132
if (isSsgEnabled) {
32-
// If user explicitly disables conventional routing (non-conventional routing), force 'string'
33-
const entryRouterConfig = entry
34-
? config.runtimeByEntries?.[entry]?.router
35-
: undefined;
36-
const routerConfig =
37-
entryRouterConfig !== undefined
38-
? entryRouterConfig
39-
: config.runtime?.router;
40-
41-
if (!routerConfig) {
33+
if (nestedRoutesEntry) {
34+
return 'stream';
35+
} else {
4236
return 'string';
4337
}
44-
4538
if (appDirectory) {
4639
return isReact18(appDirectory) ? 'stream' : 'string';
4740
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export const generateCode = async (
171171
entry: entrypoint.entryName,
172172
config,
173173
appDirectory: appContext.appDirectory,
174+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
174175
});
175176

176177
if (ssrMode === 'stream') {

0 commit comments

Comments
 (0)