@modern-js/render 3.11.0 → 3.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/callServer.js +134 -98
- package/dist/cjs/client/index.js +100 -82
- package/dist/cjs/rsc-html-stream/client.js +53 -49
- package/dist/cjs/rsc-html-stream/server.js +127 -135
- package/dist/cjs/server/rsc/csr.js +61 -49
- package/dist/cjs/server/rsc/index.js +66 -21
- package/dist/cjs/server/rsc/rsc.js +101 -90
- package/dist/cjs/server/ssr/index.js +59 -19
- package/dist/cjs/server/ssr/ssr.js +91 -100
- package/dist/esm/client/callServer.js +95 -75
- package/dist/esm/client/index.js +25 -41
- package/dist/esm/rsc-html-stream/client.js +17 -27
- package/dist/esm/rsc-html-stream/server.js +88 -112
- package/dist/esm/server/rsc/csr.js +26 -28
- package/dist/esm/server/rsc/index.js +2 -2
- package/dist/esm/server/rsc/rsc.js +51 -64
- package/dist/esm/server/ssr/index.js +1 -1
- package/dist/esm/server/ssr/ssr.js +54 -67
- package/dist/esm-node/client/callServer.mjs +96 -75
- package/dist/esm-node/client/index.mjs +26 -41
- package/dist/esm-node/rsc-html-stream/client.mjs +18 -27
- package/dist/esm-node/rsc-html-stream/server.mjs +89 -112
- package/dist/esm-node/server/rsc/csr.mjs +25 -26
- package/dist/esm-node/server/rsc/index.mjs +1 -0
- package/dist/esm-node/server/rsc/rsc.mjs +52 -64
- package/dist/esm-node/server/ssr/index.mjs +1 -0
- package/dist/esm-node/server/ssr/ssr.mjs +54 -66
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/server/rsc/index.d.ts +2 -2
- package/dist/types/server/ssr/index.d.ts +1 -1
- package/package.json +10 -11
|
@@ -1,131 +1,108 @@
|
|
|
1
|
+
import "node:module";
|
|
1
2
|
const encoder = new TextEncoder();
|
|
2
3
|
const closingTagsPattern = /<\/body>\s*<\/html>\s*$/i;
|
|
3
4
|
function injectRSCPayload(rscStream, { injectClosingTags = true }) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
controller.enqueue(encoder.encode(buf));
|
|
17
|
-
}
|
|
18
|
-
buffered.length = 0;
|
|
19
|
-
timeout = null;
|
|
20
|
-
}
|
|
21
|
-
return new TransformStream({
|
|
22
|
-
transform(chunk, controller) {
|
|
23
|
-
buffered.push(chunk);
|
|
24
|
-
if (timeout) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
timeout = setTimeout(async () => {
|
|
28
|
-
flushBufferedChunks(controller);
|
|
29
|
-
if (!startedRSC) {
|
|
30
|
-
startedRSC = true;
|
|
31
|
-
writeRSCStream(rscStream, controller).catch((err) => controller.error(err)).then(() => resolveFlightDataPromise());
|
|
5
|
+
const decoder = new TextDecoder();
|
|
6
|
+
let resolveFlightDataPromise;
|
|
7
|
+
const flightDataPromise = new Promise((resolve)=>resolveFlightDataPromise = resolve);
|
|
8
|
+
let startedRSC = false;
|
|
9
|
+
const buffered = [];
|
|
10
|
+
let timeout = null;
|
|
11
|
+
function flushBufferedChunks(controller) {
|
|
12
|
+
for (const chunk of buffered){
|
|
13
|
+
let buf = decoder.decode(chunk);
|
|
14
|
+
if (closingTagsPattern.test(buf)) buf = buf.replace(closingTagsPattern, '');
|
|
15
|
+
controller.enqueue(encoder.encode(buf));
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
async flush(controller) {
|
|
36
|
-
await flightDataPromise;
|
|
37
|
-
if (timeout) {
|
|
38
|
-
clearTimeout(timeout);
|
|
39
|
-
flushBufferedChunks(controller);
|
|
40
|
-
}
|
|
41
|
-
if (injectClosingTags) {
|
|
42
|
-
controller.enqueue(encoder.encode("</body></html>"));
|
|
43
|
-
}
|
|
17
|
+
buffered.length = 0;
|
|
18
|
+
timeout = null;
|
|
44
19
|
}
|
|
45
|
-
|
|
20
|
+
return new TransformStream({
|
|
21
|
+
transform (chunk, controller) {
|
|
22
|
+
buffered.push(chunk);
|
|
23
|
+
if (timeout) return;
|
|
24
|
+
timeout = setTimeout(async ()=>{
|
|
25
|
+
flushBufferedChunks(controller);
|
|
26
|
+
if (!startedRSC) {
|
|
27
|
+
startedRSC = true;
|
|
28
|
+
writeRSCStream(rscStream, controller).catch((err)=>controller.error(err)).then(()=>resolveFlightDataPromise());
|
|
29
|
+
}
|
|
30
|
+
}, 0);
|
|
31
|
+
},
|
|
32
|
+
async flush (controller) {
|
|
33
|
+
await flightDataPromise;
|
|
34
|
+
if (timeout) {
|
|
35
|
+
clearTimeout(timeout);
|
|
36
|
+
flushBufferedChunks(controller);
|
|
37
|
+
}
|
|
38
|
+
if (injectClosingTags) controller.enqueue(encoder.encode('</body></html>'));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
46
41
|
}
|
|
47
42
|
async function writeRSCStream(rscStream, controller) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})), controller);
|
|
43
|
+
const decoder = new TextDecoder('utf-8', {
|
|
44
|
+
fatal: true
|
|
45
|
+
});
|
|
46
|
+
for await (const chunk of rscStream)try {
|
|
47
|
+
writeChunk(JSON.stringify(decoder.decode(chunk, {
|
|
48
|
+
stream: true
|
|
49
|
+
})), controller);
|
|
56
50
|
} catch (err) {
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
|
|
52
|
+
writeChunk(`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`, controller);
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (remaining.length) {
|
|
63
|
-
writeChunk(JSON.stringify(remaining), controller);
|
|
64
|
-
}
|
|
54
|
+
const remaining = decoder.decode();
|
|
55
|
+
if (remaining.length) writeChunk(JSON.stringify(remaining), controller);
|
|
65
56
|
}
|
|
66
57
|
function writeChunk(chunk, controller) {
|
|
67
|
-
|
|
58
|
+
controller.enqueue(encoder.encode(`<script>${escapeScript(`(self.__FLIGHT_DATA||=[]).push(${chunk})`)}</script>`));
|
|
68
59
|
}
|
|
69
60
|
function escapeScript(script) {
|
|
70
|
-
|
|
61
|
+
return script.replace(/<!--/g, '<\\!--').replace(/<\/(script)/gi, '</\\$1');
|
|
71
62
|
}
|
|
72
63
|
function injectCSS(cssFiles, { injectClosingTags = true } = {}) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (injectClosingTags) {
|
|
80
|
-
controller.enqueue(encoder.encode("</body></html>"));
|
|
64
|
+
if (0 === cssFiles.length) return new TransformStream({
|
|
65
|
+
transform (chunk, controller) {
|
|
66
|
+
controller.enqueue(chunk);
|
|
67
|
+
},
|
|
68
|
+
flush (controller) {
|
|
69
|
+
if (injectClosingTags) controller.enqueue(encoder.encode('</body></html>'));
|
|
81
70
|
}
|
|
82
|
-
}
|
|
83
71
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
buffered.length = 0;
|
|
102
|
-
timeout = null;
|
|
103
|
-
}
|
|
104
|
-
return new TransformStream({
|
|
105
|
-
transform(chunk, controller) {
|
|
106
|
-
buffered.push(chunk);
|
|
107
|
-
if (timeout) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
timeout = setTimeout(() => {
|
|
111
|
-
flushBufferedChunks(controller);
|
|
112
|
-
}, 0);
|
|
113
|
-
},
|
|
114
|
-
async flush(controller) {
|
|
115
|
-
if (timeout) {
|
|
116
|
-
clearTimeout(timeout);
|
|
117
|
-
flushBufferedChunks(controller);
|
|
118
|
-
}
|
|
119
|
-
if (!cssInjected) {
|
|
120
|
-
controller.enqueue(encoder.encode(cssLinks));
|
|
121
|
-
}
|
|
122
|
-
if (injectClosingTags) {
|
|
123
|
-
controller.enqueue(encoder.encode("</body></html>"));
|
|
124
|
-
}
|
|
72
|
+
const decoder = new TextDecoder();
|
|
73
|
+
const headTrailer = '</head>';
|
|
74
|
+
const buffered = [];
|
|
75
|
+
let timeout = null;
|
|
76
|
+
let cssInjected = false;
|
|
77
|
+
const cssLinks = cssFiles.map((css)=>`<link href="${css}" rel="stylesheet" />`).join('');
|
|
78
|
+
function flushBufferedChunks(controller) {
|
|
79
|
+
for (const chunk of buffered){
|
|
80
|
+
let buf = decoder.decode(chunk);
|
|
81
|
+
if (!cssInjected && buf.includes(headTrailer)) {
|
|
82
|
+
buf = buf.replace(headTrailer, `${cssLinks}${headTrailer}`);
|
|
83
|
+
cssInjected = true;
|
|
84
|
+
}
|
|
85
|
+
controller.enqueue(encoder.encode(buf));
|
|
86
|
+
}
|
|
87
|
+
buffered.length = 0;
|
|
88
|
+
timeout = null;
|
|
125
89
|
}
|
|
126
|
-
|
|
90
|
+
return new TransformStream({
|
|
91
|
+
transform (chunk, controller) {
|
|
92
|
+
buffered.push(chunk);
|
|
93
|
+
if (timeout) return;
|
|
94
|
+
timeout = setTimeout(()=>{
|
|
95
|
+
flushBufferedChunks(controller);
|
|
96
|
+
}, 0);
|
|
97
|
+
},
|
|
98
|
+
async flush (controller) {
|
|
99
|
+
if (timeout) {
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
flushBufferedChunks(controller);
|
|
102
|
+
}
|
|
103
|
+
if (!cssInjected) controller.enqueue(encoder.encode(cssLinks));
|
|
104
|
+
if (injectClosingTags) controller.enqueue(encoder.encode('</body></html>'));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
127
107
|
}
|
|
128
|
-
export {
|
|
129
|
-
injectCSS,
|
|
130
|
-
injectRSCPayload
|
|
131
|
-
};
|
|
108
|
+
export { injectCSS, injectRSCPayload };
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
+
import "node:module";
|
|
1
2
|
import { injectCSS, injectRSCPayload } from "../../rsc-html-stream/server.mjs";
|
|
2
3
|
import { renderRsc } from "./rsc.mjs";
|
|
3
4
|
async function renderCSRWithRSC(options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
const entryCssFiles = __rspack_rsc_manifest__?.entryCssFiles;
|
|
6
|
+
const cssFiles = entryCssFiles ? Object.values(entryCssFiles).flat() : [];
|
|
7
|
+
const rscPayloadStream = renderRsc({
|
|
8
|
+
element: options.rscRoot
|
|
9
|
+
});
|
|
10
|
+
const htmlStream = new ReadableStream({
|
|
11
|
+
start (controller) {
|
|
12
|
+
const encoder = new TextEncoder();
|
|
13
|
+
controller.enqueue(encoder.encode(options.html));
|
|
14
|
+
controller.close();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const stream = htmlStream.pipeThrough(injectCSS(cssFiles, {
|
|
18
|
+
injectClosingTags: false
|
|
19
|
+
})).pipeThrough(injectRSCPayload(rscPayloadStream, {
|
|
20
|
+
injectClosingTags: true
|
|
21
|
+
}));
|
|
22
|
+
return new Response(stream, {
|
|
23
|
+
status: 200,
|
|
24
|
+
headers: new Headers({
|
|
25
|
+
'content-type': 'text/html; charset=UTF-8'
|
|
26
|
+
})
|
|
27
|
+
});
|
|
27
28
|
}
|
|
28
|
-
export {
|
|
29
|
-
renderCSRWithRSC
|
|
30
|
-
};
|
|
29
|
+
export { renderCSRWithRSC };
|
|
@@ -1,69 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { loadServerAction,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const renderRsc = (options) => {
|
|
7
|
-
const readable = renderToReadableStream2(options.element);
|
|
8
|
-
return readable;
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { decodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream } from "react-server-dom-rspack/server.node";
|
|
3
|
+
const renderRsc = (options)=>{
|
|
4
|
+
const readable = renderToReadableStream(options.element);
|
|
5
|
+
return readable;
|
|
9
6
|
};
|
|
10
|
-
const handleAction = async (req)
|
|
11
|
-
try {
|
|
12
|
-
const serverReference = req.headers.get("x-rsc-action");
|
|
13
|
-
if (!serverReference) {
|
|
14
|
-
return new Response("Cannot find server reference", {
|
|
15
|
-
status: 404
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const action = loadServerAction(serverReference);
|
|
19
|
-
if (typeof action !== "function") {
|
|
20
|
-
console.error("[RSC] Invalid action: server reference is not a function, serverReference:", serverReference);
|
|
21
|
-
return new Response("Invalid action", {
|
|
22
|
-
status: 400
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const contentType = req.headers.get("content-type");
|
|
26
|
-
let args;
|
|
7
|
+
const handleAction = async (req)=>{
|
|
27
8
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
const serverReference = req.headers.get('x-rsc-action');
|
|
10
|
+
if (!serverReference) return new Response('Cannot find server reference', {
|
|
11
|
+
status: 404
|
|
12
|
+
});
|
|
13
|
+
const action = loadServerAction(serverReference);
|
|
14
|
+
if ('function' != typeof action) {
|
|
15
|
+
console.error('[RSC] Invalid action: server reference is not a function, serverReference:', serverReference);
|
|
16
|
+
return new Response('Invalid action', {
|
|
17
|
+
status: 400
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const contentType = req.headers.get('content-type');
|
|
21
|
+
let args;
|
|
22
|
+
try {
|
|
23
|
+
if (contentType?.includes('multipart/form-data')) {
|
|
24
|
+
const formData = await req.formData();
|
|
25
|
+
args = await decodeReply(formData);
|
|
26
|
+
} else {
|
|
27
|
+
const text = await req.text();
|
|
28
|
+
args = await decodeReply(text);
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('[RSC] Failed to decode request arguments, error:', error instanceof Error ? error.message : String(error), 'contentType:', contentType || 'unknown');
|
|
32
|
+
return new Response('Failed to decode request arguments', {
|
|
33
|
+
status: 400
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const result = await Promise.resolve(action.apply(null, args));
|
|
37
|
+
const stream = renderRsc({
|
|
38
|
+
element: result
|
|
39
|
+
});
|
|
40
|
+
const response = new Response(stream, {
|
|
41
|
+
status: 200,
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'text/html'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return response;
|
|
35
47
|
} catch (error) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
49
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
50
|
+
console.error('[RSC] Error handling server action, error:', errorMessage, errorStack ? `\n${errorStack}` : '');
|
|
51
|
+
return new Response('Internal server error', {
|
|
52
|
+
status: 500
|
|
53
|
+
});
|
|
40
54
|
}
|
|
41
|
-
const result = await Promise.resolve(action.apply(null, args));
|
|
42
|
-
const stream = renderRsc({
|
|
43
|
-
element: result
|
|
44
|
-
});
|
|
45
|
-
const response = new Response(stream, {
|
|
46
|
-
status: 200,
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": "text/html"
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return response;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
54
|
-
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
55
|
-
console.error("[RSC] Error handling server action, error:", errorMessage, errorStack ? `
|
|
56
|
-
${errorStack}` : "");
|
|
57
|
-
return new Response("Internal server error", {
|
|
58
|
-
status: 500
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
export {
|
|
63
|
-
createFromReadableStream,
|
|
64
|
-
handleAction,
|
|
65
|
-
registerClientReference,
|
|
66
|
-
registerServerReference,
|
|
67
|
-
renderRsc,
|
|
68
|
-
renderToReadableStream
|
|
69
55
|
};
|
|
56
|
+
export { createFromReadableStream } from "react-server-dom-rspack/client.node";
|
|
57
|
+
export { handleAction, registerClientReference, registerServerReference, renderRsc, renderToReadableStream };
|
|
@@ -1,76 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
3
4
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
4
5
|
import { ServerElementsProvider } from "../../client/index.mjs";
|
|
5
6
|
function CSSLinks({ cssFiles }) {
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, css))
|
|
14
|
-
});
|
|
7
|
+
if (0 === cssFiles.length) return null;
|
|
8
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
9
|
+
children: cssFiles.map((css)=>/*#__PURE__*/ jsx("link", {
|
|
10
|
+
href: css,
|
|
11
|
+
rel: "stylesheet"
|
|
12
|
+
}, css))
|
|
13
|
+
});
|
|
15
14
|
}
|
|
16
15
|
function wrapStream(stream, originalStream) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
wrappedStream[prop] = originalStream[prop];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return wrappedStream;
|
|
16
|
+
const wrappedStream = Object.create(stream);
|
|
17
|
+
for (const prop of Object.keys(originalStream))if (!(prop in wrappedStream)) wrappedStream[prop] = originalStream[prop];
|
|
18
|
+
return wrappedStream;
|
|
24
19
|
}
|
|
25
|
-
const renderSSRStream = async (children, options)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...options,
|
|
35
|
-
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const [{ renderRsc }, { createFromReadableStream }, { injectRSCPayload }] = await Promise.all([
|
|
40
|
-
import("../rsc/index.mjs"),
|
|
41
|
-
import("react-server-dom-rspack/client.edge"),
|
|
42
|
-
import("../../rsc-html-stream/server.mjs")
|
|
43
|
-
]);
|
|
44
|
-
const rscStream = await renderRsc({
|
|
45
|
-
element: rscRoot || children
|
|
20
|
+
const renderSSRStream = async (children, options)=>{
|
|
21
|
+
const { rscRoot, routes } = options;
|
|
22
|
+
const clientManifest = __rspack_rsc_manifest__?.clientManifest;
|
|
23
|
+
const serverConsumerModuleMap = __rspack_rsc_manifest__?.serverConsumerModuleMap;
|
|
24
|
+
const entryCssFiles = __rspack_rsc_manifest__?.entryCssFiles;
|
|
25
|
+
const hasRoutes = Boolean(routes && routes.length > 0);
|
|
26
|
+
if (!clientManifest || !serverConsumerModuleMap) return renderToReadableStream(children, {
|
|
27
|
+
...options,
|
|
28
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
46
29
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
try {
|
|
31
|
+
const [{ renderRsc }, { createFromReadableStream }, { injectRSCPayload }] = await Promise.all([
|
|
32
|
+
import("../rsc/index.mjs"),
|
|
33
|
+
import("react-server-dom-rspack/client.edge"),
|
|
34
|
+
import("../../rsc-html-stream/server.mjs")
|
|
35
|
+
]);
|
|
36
|
+
const rscStream = await renderRsc({
|
|
37
|
+
element: rscRoot || children
|
|
38
|
+
});
|
|
39
|
+
const [rscElementStream, rscPayloadStream] = rscStream.tee();
|
|
40
|
+
const elements = createFromReadableStream(rscElementStream);
|
|
41
|
+
let cssFiles = [];
|
|
42
|
+
if (!hasRoutes && entryCssFiles) cssFiles = Object.values(entryCssFiles).flat();
|
|
43
|
+
const htmlStream = await renderToReadableStream(/*#__PURE__*/ jsxs(ServerElementsProvider, {
|
|
44
|
+
elements: elements,
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(CSSLinks, {
|
|
47
|
+
cssFiles: cssFiles
|
|
48
|
+
}),
|
|
49
|
+
children
|
|
50
|
+
]
|
|
51
|
+
}), {
|
|
52
|
+
...options,
|
|
53
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
54
|
+
});
|
|
55
|
+
const stream = htmlStream.pipeThrough(injectRSCPayload(rscPayloadStream, {
|
|
56
|
+
injectClosingTags: true
|
|
57
|
+
}));
|
|
58
|
+
return wrapStream(stream, htmlStream);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(error);
|
|
61
|
+
throw error;
|
|
52
62
|
}
|
|
53
|
-
const htmlStream = await renderToReadableStream(/* @__PURE__ */ _jsxs(ServerElementsProvider, {
|
|
54
|
-
elements,
|
|
55
|
-
children: [
|
|
56
|
-
/* @__PURE__ */ _jsx(CSSLinks, {
|
|
57
|
-
cssFiles
|
|
58
|
-
}),
|
|
59
|
-
children
|
|
60
|
-
]
|
|
61
|
-
}), {
|
|
62
|
-
...options,
|
|
63
|
-
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
64
|
-
});
|
|
65
|
-
const stream = htmlStream.pipeThrough(injectRSCPayload(rscPayloadStream, {
|
|
66
|
-
injectClosingTags: true
|
|
67
|
-
}));
|
|
68
|
-
return wrapStream(stream, htmlStream);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(error);
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
export {
|
|
75
|
-
renderSSRStream
|
|
76
63
|
};
|
|
64
|
+
export { renderSSRStream };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import { createFromReadableStream, createServerReference, setServerCallback } from 'react-server-dom-rspack/client.browser';
|
|
4
|
-
export { rscStream } from '../rsc-html-stream/client';
|
|
4
|
+
export { rscStream } from '../rsc-html-stream/client.js';
|
|
5
5
|
export { createFromReadableStream, createServerReference };
|
|
6
|
-
export { callServer } from './callServer';
|
|
6
|
+
export { callServer } from './callServer.js';
|
|
7
7
|
export { createFromFetch } from 'react-server-dom-rspack/client.browser';
|
|
8
8
|
declare global {
|
|
9
9
|
interface Window {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './rsc';
|
|
2
|
-
export * from './csr';
|
|
1
|
+
export * from './rsc.js';
|
|
2
|
+
export * from './csr.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './ssr';
|
|
1
|
+
export * from './ssr.js';
|
package/package.json
CHANGED
|
@@ -15,28 +15,26 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.11.
|
|
18
|
+
"version": "3.11.2",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
21
|
"hook.d.ts"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@swc/helpers": "^0.5.17",
|
|
25
|
-
"@modern-js/types": "3.11.
|
|
26
|
-
"@modern-js/utils": "3.11.
|
|
25
|
+
"@modern-js/types": "3.11.2",
|
|
26
|
+
"@modern-js/utils": "3.11.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rslib/core": "1.0.4",
|
|
30
29
|
"@types/react": "^19.3.0",
|
|
31
30
|
"@types/react-dom": "^19.3.0",
|
|
32
31
|
"react": "^19.3.1",
|
|
33
32
|
"react-dom": "^19.3.1",
|
|
34
33
|
"react-server-dom-rspack": "0.1.0",
|
|
35
34
|
"typescript": "^5",
|
|
36
|
-
"@modern-js/rslib": "3.11.
|
|
37
|
-
"@modern-js/server-core": "3.11.
|
|
38
|
-
"@scripts/rstest-config": "2.66.
|
|
39
|
-
"@scripts/build": "2.66.0"
|
|
35
|
+
"@modern-js/rslib": "3.11.2",
|
|
36
|
+
"@modern-js/server-core": "3.11.2",
|
|
37
|
+
"@scripts/rstest-config": "2.66.6"
|
|
40
38
|
},
|
|
41
39
|
"peerDependencies": {
|
|
42
40
|
"react": ">=18.3.1",
|
|
@@ -76,8 +74,9 @@
|
|
|
76
74
|
"access": "public"
|
|
77
75
|
},
|
|
78
76
|
"scripts": {
|
|
79
|
-
"dev": "
|
|
80
|
-
"build": "
|
|
81
|
-
"test": "rstest --passWithNoTests"
|
|
77
|
+
"dev": "rs lib --watch",
|
|
78
|
+
"build": "rs lib",
|
|
79
|
+
"test": "rstest --passWithNoTests",
|
|
80
|
+
"test:build": "pnpm run build && node --test tests/build.test.mjs"
|
|
82
81
|
}
|
|
83
82
|
}
|