Skip to content

Commit 430eabb

Browse files
committed
fix: support streaming ssr + rsc
1 parent 6631d6b commit 430eabb

32 files changed

+244
-160
lines changed

Diff for: .vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@
5959
"[javascript]": {
6060
"editor.defaultFormatter": "biomejs.biome"
6161
},
62+
"todo-tree.tree.disableCompactFolders": true,
6263
}

Diff for: packages/runtime/plugin-runtime/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@
232232
"@types/node": "^14",
233233
"@types/react-side-effect": "^1.1.1",
234234
"jest": "^29",
235-
"react": "^18",
236-
"react-dom": "^18",
235+
"react": "18.3.0-canary-8039e6d0b-20231026",
236+
"react-dom": "18.3.0-canary-8039e6d0b-20231026",
237237
"ts-jest": "^29.1.0",
238238
"typescript": "^5",
239239
"webpack": "^5.93.0"

Diff for: packages/runtime/plugin-runtime/src/cli/template.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const index = ({
6868
customBootstrap?: string | false;
6969
mountId?: string;
7070
}) =>
71-
`import '@${metaName}/runtime/registry/${entryName}';
71+
// TODO: remove this
72+
`
7273
${genRenderCode({
7374
srcDirectory,
7475
internalSrcAlias,
@@ -166,6 +167,7 @@ import App from '${
166167
customEntry
167168
? entry
168169
.replace('entry.tsx', 'App')
170+
.replace('entry.jsx', 'App')
169171
.replace(srcDirectory, internalSrcAlias)
170172
: entry.replace(srcDirectory, internalSrcAlias).replace('.tsx', ''),
171173
)

Diff for: packages/runtime/plugin-runtime/src/core/server/stream/afterTemplate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function buildShellAfterTemplate(
3838
async function injectJs(template: string, entryName: string, nonce?: string) {
3939
const { routeManifest } = runtimeContext;
4040
const { routeAssets } = routeManifest;
41-
const asyncEntry = routeAssets[`async-${entryName}`];
41+
const asyncEntry = routeAssets?.[`async-${entryName}`];
4242
if (asyncEntry) {
4343
const { assets } = asyncEntry;
4444
const jsChunkStr = assets

Diff for: packages/runtime/plugin-runtime/src/core/server/stream/createReadableStream.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
6464
* So we use the `SHELL_STREAM_END_MARK` to mark the shell content' tail.
6565
*/
6666
let concatedChunk = chunkVec.join('');
67-
if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
68-
concatedChunk = concatedChunk.replace(
69-
ESCAPED_SHELL_STREAM_END_MARK,
70-
'',
71-
);
72-
73-
shellChunkStatus = ShellChunkStatus.FINISH;
74-
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
75-
}
67+
// if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
68+
concatedChunk = concatedChunk.replace(
69+
ESCAPED_SHELL_STREAM_END_MARK,
70+
'',
71+
);
72+
73+
shellChunkStatus = ShellChunkStatus.FINISH;
74+
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
75+
// }
7676
} else {
7777
this.push(chunk);
7878
}

Diff for: packages/solutions/app-tools/src/plugins/analyze/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default ({
168168

169169
builder.onAfterBuild(async ({ stats }) => {
170170
const hookRunners = api.useHookRunners();
171-
await hookRunners.afterBuild({ stats });
171+
await hookRunners.afterBuild({ stats: stats as any });
172172
await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
173173
});
174174

Diff for: pnpm-lock.yaml

+65-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/integration/basic-next-app/modern.config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ export default applyBaseConfig({
88
router: false,
99
},
1010
source: {
11+
enableCustomEntry: true,
1112
// 避免 Modern.js 项目代码中用的是其他版本
1213
alias: {
13-
// react$: require.resolve('react'),
14+
// react$: path.resolve(__dirname, 'node_modules/react'),
1415
// 'react-dom/client': require.resolve('react-dom/client'),
1516
// 'react-dom': require.resolve('react-dom'),
1617
},
1718
},
19+
server: {
20+
ssr: {
21+
mode: 'stream',
22+
},
23+
},
1824
tools: {
1925
babel(config, { modifyPresetReactOptions }) {
2026
modifyPresetReactOptions({

Diff for: tests/integration/basic-next-app/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"name": "tmp",
3+
"name": "basic-next-app",
44
"version": "2.9.0",
55
"scripts": {
66
"dev": "BUNDLER=webpack NODE_OPTIONS='--conditions=react-server' modern dev",
@@ -21,13 +21,14 @@
2121
"@modern-js/runtime": "workspace:*",
2222
"react": "18.3.0-canary-8039e6d0b-20231026",
2323
"react-dom": "18.3.0-canary-8039e6d0b-20231026",
24+
"react-server-dom-webpack": "18.3.0-canary-8039e6d0b-20231026",
2425
"marked": "4.2.12",
2526
"sanitize-html": "2.10.0",
2627
"react-error-boundary": "3.1.4",
2728
"pg": "8.10.0",
29+
"date-fns": "^2.29.3",
2830
"server-only": "^0.0.1",
29-
"excerpts": "0.0.3",
30-
"react-server-dom-webpack": "18.3.0-canary-8039e6d0b-20231026"
31+
"excerpts": "0.0.3"
3132
},
3233
"devDependencies": {
3334
"@modern-js/app-tools": "workspace:*",

Diff for: tests/integration/basic-next-app/server/serverPlugin.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import React from 'react';
1010
import { Pool } from 'pg';
1111
// import ReactApp from '../src/App';
1212

13-
console.log('react1111111111', React.version);
14-
console.log('renderToReadableStream', renderToReadableStream);
13+
// console.log('react1111111111', React.version);
14+
// console.log('renderToReadableStream', renderToReadableStream);
1515

16-
const pool = new Pool(require('../credentials'));
16+
// const pool = new Pool(require('../credentials'));
1717

1818
interface IProps {
1919
selectedId: string;

Diff for: tests/integration/basic-next-app/server/ssrPlugin.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)