@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,69 +1,56 @@
|
|
|
1
|
-
import { renderToReadableStream } from "react-server-dom-rspack/server.node";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { registerClientReference, registerServerReference } from "react-server-dom-rspack/server.node";
|
|
6
|
-
const renderRsc = (options) => {
|
|
7
|
-
const readable = renderToReadableStream2(options.element);
|
|
8
|
-
return readable;
|
|
1
|
+
import { decodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream } from "react-server-dom-rspack/server.node";
|
|
2
|
+
const renderRsc = (options)=>{
|
|
3
|
+
const readable = renderToReadableStream(options.element);
|
|
4
|
+
return readable;
|
|
9
5
|
};
|
|
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;
|
|
6
|
+
const handleAction = async (req)=>{
|
|
27
7
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
const serverReference = req.headers.get('x-rsc-action');
|
|
9
|
+
if (!serverReference) return new Response('Cannot find server reference', {
|
|
10
|
+
status: 404
|
|
11
|
+
});
|
|
12
|
+
const action = loadServerAction(serverReference);
|
|
13
|
+
if ('function' != typeof action) {
|
|
14
|
+
console.error('[RSC] Invalid action: server reference is not a function, serverReference:', serverReference);
|
|
15
|
+
return new Response('Invalid action', {
|
|
16
|
+
status: 400
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const contentType = req.headers.get('content-type');
|
|
20
|
+
let args;
|
|
21
|
+
try {
|
|
22
|
+
if (contentType?.includes('multipart/form-data')) {
|
|
23
|
+
const formData = await req.formData();
|
|
24
|
+
args = await decodeReply(formData);
|
|
25
|
+
} else {
|
|
26
|
+
const text = await req.text();
|
|
27
|
+
args = await decodeReply(text);
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('[RSC] Failed to decode request arguments, error:', error instanceof Error ? error.message : String(error), 'contentType:', contentType || 'unknown');
|
|
31
|
+
return new Response('Failed to decode request arguments', {
|
|
32
|
+
status: 400
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const result = await Promise.resolve(action.apply(null, args));
|
|
36
|
+
const stream = renderRsc({
|
|
37
|
+
element: result
|
|
38
|
+
});
|
|
39
|
+
const response = new Response(stream, {
|
|
40
|
+
status: 200,
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': 'text/html'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return response;
|
|
35
46
|
} catch (error) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
48
|
+
const errorStack = error instanceof Error ? error.stack : void 0;
|
|
49
|
+
console.error('[RSC] Error handling server action, error:', errorMessage, errorStack ? `\n${errorStack}` : '');
|
|
50
|
+
return new Response('Internal server error', {
|
|
51
|
+
status: 500
|
|
52
|
+
});
|
|
40
53
|
}
|
|
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
54
|
};
|
|
55
|
+
export { createFromReadableStream } from "react-server-dom-rspack/client.node";
|
|
56
|
+
export { handleAction, registerClientReference, registerServerReference, renderRsc, renderToReadableStream };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./ssr";
|
|
1
|
+
export * from "./ssr.js";
|
|
@@ -1,76 +1,63 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
3
3
|
import { renderToReadableStream } from "react-dom/server.edge";
|
|
4
|
-
import { ServerElementsProvider } from "../../client/index";
|
|
4
|
+
import { ServerElementsProvider } from "../../client/index.js";
|
|
5
5
|
function CSSLinks({ cssFiles }) {
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, css))
|
|
14
|
-
});
|
|
6
|
+
if (0 === cssFiles.length) return null;
|
|
7
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
8
|
+
children: cssFiles.map((css)=>/*#__PURE__*/ jsx("link", {
|
|
9
|
+
href: css,
|
|
10
|
+
rel: "stylesheet"
|
|
11
|
+
}, css))
|
|
12
|
+
});
|
|
15
13
|
}
|
|
16
14
|
function wrapStream(stream, originalStream) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
wrappedStream[prop] = originalStream[prop];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return wrappedStream;
|
|
15
|
+
const wrappedStream = Object.create(stream);
|
|
16
|
+
for (const prop of Object.keys(originalStream))if (!(prop in wrappedStream)) wrappedStream[prop] = originalStream[prop];
|
|
17
|
+
return wrappedStream;
|
|
24
18
|
}
|
|
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"),
|
|
41
|
-
import("react-server-dom-rspack/client.edge"),
|
|
42
|
-
import("../../rsc-html-stream/server")
|
|
43
|
-
]);
|
|
44
|
-
const rscStream = await renderRsc({
|
|
45
|
-
element: rscRoot || children
|
|
19
|
+
const renderSSRStream = async (children, options)=>{
|
|
20
|
+
const { rscRoot, routes } = options;
|
|
21
|
+
const clientManifest = __rspack_rsc_manifest__?.clientManifest;
|
|
22
|
+
const serverConsumerModuleMap = __rspack_rsc_manifest__?.serverConsumerModuleMap;
|
|
23
|
+
const entryCssFiles = __rspack_rsc_manifest__?.entryCssFiles;
|
|
24
|
+
const hasRoutes = Boolean(routes && routes.length > 0);
|
|
25
|
+
if (!clientManifest || !serverConsumerModuleMap) return renderToReadableStream(children, {
|
|
26
|
+
...options,
|
|
27
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
46
28
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
try {
|
|
30
|
+
const [{ renderRsc }, { createFromReadableStream }, { injectRSCPayload }] = await Promise.all([
|
|
31
|
+
import("../rsc/index.js"),
|
|
32
|
+
import("react-server-dom-rspack/client.edge"),
|
|
33
|
+
import("../../rsc-html-stream/server.js")
|
|
34
|
+
]);
|
|
35
|
+
const rscStream = await renderRsc({
|
|
36
|
+
element: rscRoot || children
|
|
37
|
+
});
|
|
38
|
+
const [rscElementStream, rscPayloadStream] = rscStream.tee();
|
|
39
|
+
const elements = createFromReadableStream(rscElementStream);
|
|
40
|
+
let cssFiles = [];
|
|
41
|
+
if (!hasRoutes && entryCssFiles) cssFiles = Object.values(entryCssFiles).flat();
|
|
42
|
+
const htmlStream = await renderToReadableStream(/*#__PURE__*/ jsxs(ServerElementsProvider, {
|
|
43
|
+
elements: elements,
|
|
44
|
+
children: [
|
|
45
|
+
/*#__PURE__*/ jsx(CSSLinks, {
|
|
46
|
+
cssFiles: cssFiles
|
|
47
|
+
}),
|
|
48
|
+
children
|
|
49
|
+
]
|
|
50
|
+
}), {
|
|
51
|
+
...options,
|
|
52
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
53
|
+
});
|
|
54
|
+
const stream = htmlStream.pipeThrough(injectRSCPayload(rscPayloadStream, {
|
|
55
|
+
injectClosingTags: true
|
|
56
|
+
}));
|
|
57
|
+
return wrapStream(stream, htmlStream);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(error);
|
|
60
|
+
throw error;
|
|
52
61
|
}
|
|
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
62
|
};
|
|
63
|
+
export { renderSSRStream };
|
|
@@ -1,83 +1,104 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { _ as _class_private_field_init } from "@swc/helpers/_/_class_private_field_init";
|
|
3
|
-
import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_field_set";
|
|
1
|
+
import "node:module";
|
|
4
2
|
import { createFromFetch, encodeReply } from "react-server-dom-rspack/client.browser";
|
|
5
|
-
|
|
3
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
4
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
5
|
+
}
|
|
6
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
7
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
8
|
+
return descriptor.value;
|
|
9
|
+
}
|
|
10
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
11
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
12
|
+
else {
|
|
13
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
14
|
+
descriptor.value = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
18
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
19
|
+
return privateMap.get(receiver);
|
|
20
|
+
}
|
|
21
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
22
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
23
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
24
|
+
}
|
|
25
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
26
|
+
_check_private_redeclaration(obj, privateMap);
|
|
27
|
+
privateMap.set(obj, value);
|
|
28
|
+
}
|
|
29
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
30
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
31
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
var _statusCode = /*#__PURE__*/ new WeakMap(), _url = /*#__PURE__*/ new WeakMap(), _details = /*#__PURE__*/ new WeakMap();
|
|
6
35
|
class CallServerError extends Error {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
36
|
+
get statusCode() {
|
|
37
|
+
return _class_private_field_get(this, _statusCode);
|
|
38
|
+
}
|
|
39
|
+
get url() {
|
|
40
|
+
return _class_private_field_get(this, _url);
|
|
41
|
+
}
|
|
42
|
+
get details() {
|
|
43
|
+
return {
|
|
44
|
+
..._class_private_field_get(this, _details)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
name: this.name,
|
|
50
|
+
message: this.message,
|
|
51
|
+
statusCode: _class_private_field_get(this, _statusCode),
|
|
52
|
+
url: _class_private_field_get(this, _url),
|
|
53
|
+
details: _class_private_field_get(this, _details)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
constructor(message, statusCode, url = '', details = {}){
|
|
57
|
+
const formattedMessage = `Call Server Action failed (${statusCode}): ${message}\nURL: ${url}`;
|
|
58
|
+
super(formattedMessage), _class_private_field_init(this, _statusCode, {
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
}), _class_private_field_init(this, _url, {
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
}), _class_private_field_init(this, _details, {
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
this.name = 'CallServerError';
|
|
69
|
+
_class_private_field_set(this, _statusCode, statusCode);
|
|
70
|
+
_class_private_field_set(this, _url, url);
|
|
71
|
+
_class_private_field_set(this, _details, details);
|
|
72
|
+
}
|
|
45
73
|
}
|
|
46
74
|
async function requestCallServer(id, args) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
const entryName = window.__MODERN_JS_ENTRY_NAME;
|
|
76
|
+
const url = 'main' === entryName || 'index' === entryName ? '/' : `/${entryName}`;
|
|
77
|
+
try {
|
|
78
|
+
const response = await fetch(url, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers: {
|
|
81
|
+
Accept: 'text/x-component',
|
|
82
|
+
'x-rsc-action': id
|
|
83
|
+
},
|
|
84
|
+
body: await encodeReply(args)
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) throw new CallServerError(response.statusText, response.status, url, {
|
|
87
|
+
id,
|
|
88
|
+
args
|
|
89
|
+
});
|
|
90
|
+
return response;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof CallServerError) throw error;
|
|
93
|
+
throw new CallServerError(error instanceof Error ? error.message : 'Unknown error', 1, url, {
|
|
94
|
+
id,
|
|
95
|
+
args
|
|
96
|
+
});
|
|
68
97
|
}
|
|
69
|
-
throw new CallServerError(error instanceof Error ? error.message : "Unknown error", 1, url, {
|
|
70
|
-
id,
|
|
71
|
-
args
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
98
|
}
|
|
75
99
|
async function callServer(id, args) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
100
|
+
const response = requestCallServer(id, args);
|
|
101
|
+
const res = createFromFetch(response);
|
|
102
|
+
return res;
|
|
79
103
|
}
|
|
80
|
-
export {
|
|
81
|
-
callServer,
|
|
82
|
-
requestCallServer
|
|
83
|
-
};
|
|
104
|
+
export { callServer, requestCallServer };
|
|
@@ -1,44 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { createContext, useState } from "react";
|
|
4
|
-
|
|
5
|
-
import { rscStream } from "../rsc-html-stream/client.mjs";
|
|
6
|
-
import { callServer } from "./callServer.mjs";
|
|
7
|
-
import { createFromFetch } from "react-server-dom-rspack/client.browser";
|
|
8
|
-
const ResetRootContext = /* @__PURE__ */ createContext(void 0);
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import react, { createContext, useState } from "react";
|
|
4
|
+
const ResetRootContext = /*#__PURE__*/ createContext(void 0);
|
|
9
5
|
function RscClientRoot({ rscPayload }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const elements = react.use(rscPayload);
|
|
7
|
+
const [root, setRoot] = useState(elements);
|
|
8
|
+
return /*#__PURE__*/ jsx(ResetRootContext.Provider, {
|
|
9
|
+
value: {
|
|
10
|
+
setRoot
|
|
11
|
+
},
|
|
12
|
+
children: root
|
|
13
|
+
});
|
|
18
14
|
}
|
|
19
|
-
const ElementsContext =
|
|
20
|
-
const ServerElementsProvider = ({ elements, children })
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const elements = React.use(ElementsContext);
|
|
30
|
-
return elements;
|
|
31
|
-
};
|
|
32
|
-
export {
|
|
33
|
-
ElementsContext,
|
|
34
|
-
RSCServerSlot,
|
|
35
|
-
ResetRootContext,
|
|
36
|
-
RscClientRoot,
|
|
37
|
-
ServerElementsProvider,
|
|
38
|
-
callServer,
|
|
39
|
-
createFromFetch,
|
|
40
|
-
createFromReadableStream,
|
|
41
|
-
createServerReference,
|
|
42
|
-
rscStream,
|
|
43
|
-
setServerCallback
|
|
15
|
+
const ElementsContext = /*#__PURE__*/ createContext(null);
|
|
16
|
+
const ServerElementsProvider = ({ elements, children })=>/*#__PURE__*/ jsx(Fragment, {
|
|
17
|
+
children: /*#__PURE__*/ jsx(ElementsContext.Provider, {
|
|
18
|
+
value: elements,
|
|
19
|
+
children: children
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
const RSCServerSlot = ()=>{
|
|
23
|
+
const elements = react.use(ElementsContext);
|
|
24
|
+
return elements;
|
|
44
25
|
};
|
|
26
|
+
export { createFromFetch, createFromReadableStream, createServerReference, setServerCallback } from "react-server-dom-rspack/client.browser";
|
|
27
|
+
export { rscStream } from "../rsc-html-stream/client.mjs";
|
|
28
|
+
export { callServer } from "./callServer.mjs";
|
|
29
|
+
export { ElementsContext, RSCServerSlot, ResetRootContext, RscClientRoot, ServerElementsProvider };
|
|
@@ -1,32 +1,23 @@
|
|
|
1
|
+
import "node:module";
|
|
1
2
|
const encoder = new TextEncoder();
|
|
2
3
|
let streamController;
|
|
3
4
|
const rscStream = new ReadableStream({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
start (controller) {
|
|
6
|
+
if ("u" < typeof window) return;
|
|
7
|
+
const handleChunk = (chunk)=>{
|
|
8
|
+
if ('string' == typeof chunk) controller.enqueue(encoder.encode(chunk));
|
|
9
|
+
else controller.enqueue(chunk);
|
|
10
|
+
};
|
|
11
|
+
window.__FLIGHT_DATA = window.__FLIGHT_DATA || [];
|
|
12
|
+
window.__FLIGHT_DATA.forEach(handleChunk);
|
|
13
|
+
window.__FLIGHT_DATA.push = (chunk)=>{
|
|
14
|
+
handleChunk(chunk);
|
|
15
|
+
};
|
|
16
|
+
streamController = controller;
|
|
7
17
|
}
|
|
8
|
-
const handleChunk = (chunk) => {
|
|
9
|
-
if (typeof chunk === "string") {
|
|
10
|
-
controller.enqueue(encoder.encode(chunk));
|
|
11
|
-
} else {
|
|
12
|
-
controller.enqueue(chunk);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
window.__FLIGHT_DATA = window.__FLIGHT_DATA || [];
|
|
16
|
-
window.__FLIGHT_DATA.forEach(handleChunk);
|
|
17
|
-
window.__FLIGHT_DATA.push = (chunk) => {
|
|
18
|
-
handleChunk(chunk);
|
|
19
|
-
};
|
|
20
|
-
streamController = controller;
|
|
21
|
-
}
|
|
22
18
|
});
|
|
23
|
-
if (typeof document
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
streamController === null || streamController === void 0 ? void 0 : streamController.close();
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
rscStream
|
|
32
|
-
};
|
|
19
|
+
if ("u" > typeof document && 'loading' === document.readyState) document.addEventListener('DOMContentLoaded', ()=>{
|
|
20
|
+
streamController?.close();
|
|
21
|
+
});
|
|
22
|
+
else streamController?.close();
|
|
23
|
+
export { rscStream };
|