@modern-js/runtime 0.0.0-next-20240227075921 → 0.0.0-next-20240228090154
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/core/compatible.js +3 -2
- package/dist/cjs/router/runtime/plugin.node.js +1 -1
- package/dist/cjs/ssr/index.js +2 -4
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +46 -47
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +6 -1
- package/dist/cjs/ssr/serverRender/tracker.js +3 -3
- package/dist/esm/core/compatible.js +3 -2
- package/dist/esm/router/runtime/plugin.node.js +1 -1
- package/dist/esm/ssr/index.js +2 -4
- package/dist/esm/ssr/serverRender/renderToStream/index.js +3 -3
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +47 -48
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +6 -1
- package/dist/esm/ssr/serverRender/tracker.js +3 -3
- package/dist/esm-node/core/compatible.js +3 -2
- package/dist/esm-node/router/runtime/plugin.node.js +1 -1
- package/dist/esm-node/ssr/index.js +2 -4
- package/dist/esm-node/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +46 -47
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +6 -1
- package/dist/esm-node/ssr/serverRender/tracker.js +3 -3
- package/dist/types/ssr/serverRender/renderToStream/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.d.ts +3 -4
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.worker.d.ts +5 -1
- package/package.json +10 -10
|
@@ -228,8 +228,9 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
228
228
|
const redirectUrl = result.headers.get("Location") || "/";
|
|
229
229
|
const { ssrContext } = context;
|
|
230
230
|
if (ssrContext) {
|
|
231
|
-
|
|
232
|
-
ssrContext.res.
|
|
231
|
+
var _ssrContext_res;
|
|
232
|
+
ssrContext.res && (ssrContext.res.statusCode = status);
|
|
233
|
+
(_ssrContext_res = ssrContext.res) === null || _ssrContext_res === void 0 ? void 0 : _ssrContext_res.setHeader("Location", redirectUrl);
|
|
233
234
|
ssrContext.redirection = ssrContext.redirection || {};
|
|
234
235
|
ssrContext.redirection.status = status;
|
|
235
236
|
ssrContext.redirection.url = redirectUrl;
|
|
@@ -112,7 +112,7 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
112
112
|
requestContext
|
|
113
113
|
});
|
|
114
114
|
const cost = end();
|
|
115
|
-
reporter.reportTiming(import_constants.LOADER_REPORTER_NAME, cost);
|
|
115
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(import_constants.LOADER_REPORTER_NAME, cost);
|
|
116
116
|
serverTiming.addServeTiming(import_constants.LOADER_REPORTER_NAME, cost);
|
|
117
117
|
if (routerContext instanceof Response) {
|
|
118
118
|
return routerContext;
|
package/dist/cjs/ssr/index.js
CHANGED
|
@@ -47,10 +47,8 @@ const ssr = (config) => ({
|
|
|
47
47
|
setup: () => {
|
|
48
48
|
const mockResp = (0, import_utils.mockResponse)();
|
|
49
49
|
if (config.inlineScript === false) {
|
|
50
|
-
|
|
51
|
-
window.
|
|
52
|
-
const routeData = (0, import_parsed.parsedJSONFromElement)(import_constants.ROUTER_DATA_JSON_ID);
|
|
53
|
-
window._ROUTER_DATA = routeData || window._ROUTER_DATA;
|
|
50
|
+
window._SSR_DATA = (0, import_parsed.parsedJSONFromElement)(import_constants.SSR_DATA_JSON_ID);
|
|
51
|
+
window._ROUTER_DATA = (0, import_parsed.parsedJSONFromElement)(import_constants.ROUTER_DATA_JSON_ID);
|
|
54
52
|
}
|
|
55
53
|
return {
|
|
56
54
|
client: async ({ App, context, ModernRender, ModernHydrate }) => {
|
|
@@ -49,7 +49,7 @@ const render = ({ App, context, config }) => {
|
|
|
49
49
|
})
|
|
50
50
|
});
|
|
51
51
|
const { tracker } = ssrContext;
|
|
52
|
-
const
|
|
52
|
+
const stream = (0, import_renderToPipe.default)(rootElement, context, config, {
|
|
53
53
|
onShellReady() {
|
|
54
54
|
const cost = end();
|
|
55
55
|
tracker.trackTiming(import_tracker.SSRTimings.RENDER_SHELL, cost);
|
|
@@ -65,7 +65,7 @@ const render = ({ App, context, config }) => {
|
|
|
65
65
|
tracker.trackError(import_tracker.SSRErrors.RENDER_STREAM, error);
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
return
|
|
68
|
+
return stream;
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -36,58 +36,57 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
36
36
|
const onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
37
37
|
const { ssrContext } = context;
|
|
38
38
|
const chunkVec = [];
|
|
39
|
-
const forUserPipe = (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
this.push(chunk);
|
|
66
|
-
}
|
|
67
|
-
callback();
|
|
68
|
-
} catch (e) {
|
|
69
|
-
if (e instanceof Error) {
|
|
70
|
-
callback(e);
|
|
71
|
-
} else {
|
|
72
|
-
callback(new Error("Received unkown error when streaming"));
|
|
39
|
+
const forUserPipe = new Promise((resolve) => {
|
|
40
|
+
let renderToPipeableStream;
|
|
41
|
+
try {
|
|
42
|
+
({ renderToPipeableStream } = require("react-dom/server"));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
}
|
|
45
|
+
const { pipe } = renderToPipeableStream(rootElement, {
|
|
46
|
+
...options,
|
|
47
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
48
|
+
[onReady]() {
|
|
49
|
+
(0, import_template.getTemplates)(context, import_types.RenderLevel.SERVER_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
50
|
+
var _options_onShellReady;
|
|
51
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
52
|
+
const injectableTransform = new import_stream.Transform({
|
|
53
|
+
transform(chunk, _encoding, callback) {
|
|
54
|
+
try {
|
|
55
|
+
if (shellChunkStatus !== 1) {
|
|
56
|
+
chunkVec.push(chunk.toString());
|
|
57
|
+
let concatedChunk = chunkVec.join("");
|
|
58
|
+
if (concatedChunk.endsWith(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
59
|
+
concatedChunk = concatedChunk.replace(import_common.ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
60
|
+
shellChunkStatus = 1;
|
|
61
|
+
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
73
62
|
}
|
|
63
|
+
} else {
|
|
64
|
+
this.push(chunk);
|
|
65
|
+
}
|
|
66
|
+
callback();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
if (e instanceof Error) {
|
|
69
|
+
callback(e);
|
|
70
|
+
} else {
|
|
71
|
+
callback(new Error("Received unkown error when streaming"));
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
}
|
|
77
|
-
resolve(pipe(injectableTransform).pipe(stream));
|
|
74
|
+
}
|
|
78
75
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
pipe(injectableTransform);
|
|
77
|
+
resolve(injectableTransform);
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
onShellError(error) {
|
|
81
|
+
(0, import_template.getTemplates)(context, import_types.RenderLevel.CLIENT_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
82
|
+
var _options_onShellError;
|
|
83
|
+
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
84
|
+
resolve(fallbackHtml);
|
|
85
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
89
88
|
});
|
|
90
|
-
};
|
|
89
|
+
});
|
|
91
90
|
return forUserPipe;
|
|
92
91
|
}
|
|
93
92
|
var renderToPipe_default = renderToPipe;
|
|
@@ -42,7 +42,7 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
42
42
|
}
|
|
43
43
|
const { shellAfter, shellBefore } = await (0, import_template.getTemplates)(context, import_types.RenderLevel.SERVER_RENDER, pluginConfig);
|
|
44
44
|
try {
|
|
45
|
-
var _context_ssrContext;
|
|
45
|
+
var _options_onShellReady, _context_ssrContext;
|
|
46
46
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
47
47
|
...options,
|
|
48
48
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
@@ -51,6 +51,11 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
51
51
|
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
55
|
+
readableOriginal.allReady.then(() => {
|
|
56
|
+
var _options_onAllReady;
|
|
57
|
+
options === null || options === void 0 ? void 0 : (_options_onAllReady = options.onAllReady) === null || _options_onAllReady === void 0 ? void 0 : _options_onAllReady.call(options);
|
|
58
|
+
});
|
|
54
59
|
if ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) {
|
|
55
60
|
await readableOriginal.allReady;
|
|
56
61
|
}
|
|
@@ -81,16 +81,16 @@ const timings = {
|
|
|
81
81
|
function createSSRTracker({ reporter, serverTiming, logger }) {
|
|
82
82
|
const tracker = {
|
|
83
83
|
get sessionId() {
|
|
84
|
-
return reporter.sessionId;
|
|
84
|
+
return reporter === null || reporter === void 0 ? void 0 : reporter.sessionId;
|
|
85
85
|
},
|
|
86
86
|
trackError(key, e) {
|
|
87
87
|
const { reporter: reporterContent, logger: loggerContent } = errors[key];
|
|
88
|
-
reporterContent && reporter.reportError(`SSR Error - ${reporterContent}`, e);
|
|
88
|
+
reporterContent && (reporter === null || reporter === void 0 ? void 0 : reporter.reportError(`SSR Error - ${reporterContent}`, e));
|
|
89
89
|
loggerContent && logger.error(loggerContent, e);
|
|
90
90
|
},
|
|
91
91
|
trackTiming(key, cost) {
|
|
92
92
|
const { reporter: reporterName, serverTiming: serverTimingName, logger: loggerName } = timings[key];
|
|
93
|
-
reporterName && reporter.reportTiming(reporterName, cost);
|
|
93
|
+
reporterName && (reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(reporterName, cost));
|
|
94
94
|
serverTimingName && serverTiming.addServeTiming(serverTimingName, cost);
|
|
95
95
|
loggerName && logger.debug(loggerName, cost);
|
|
96
96
|
}
|
|
@@ -229,8 +229,9 @@ var bootstrap = function() {
|
|
|
229
229
|
var redirectUrl = result.headers.get("Location") || "/";
|
|
230
230
|
var ssrContext = context.ssrContext;
|
|
231
231
|
if (ssrContext) {
|
|
232
|
-
|
|
233
|
-
ssrContext.res.
|
|
232
|
+
var _ssrContext_res;
|
|
233
|
+
ssrContext.res && (ssrContext.res.statusCode = status);
|
|
234
|
+
(_ssrContext_res = ssrContext.res) === null || _ssrContext_res === void 0 ? void 0 : _ssrContext_res.setHeader("Location", redirectUrl);
|
|
234
235
|
ssrContext.redirection = ssrContext.redirection || {};
|
|
235
236
|
ssrContext.redirection.status = status;
|
|
236
237
|
ssrContext.redirection.url = redirectUrl;
|
|
@@ -132,7 +132,7 @@ var routerPlugin = function(param) {
|
|
|
132
132
|
case 1:
|
|
133
133
|
routerContext = _state.sent();
|
|
134
134
|
cost = end();
|
|
135
|
-
reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
135
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
136
136
|
serverTiming.addServeTiming(LOADER_REPORTER_NAME, cost);
|
|
137
137
|
if (_instanceof(routerContext, Response)) {
|
|
138
138
|
return [
|
package/dist/esm/ssr/index.js
CHANGED
|
@@ -16,10 +16,8 @@ var ssr = function(config) {
|
|
|
16
16
|
setup: function() {
|
|
17
17
|
var mockResp = mockResponse();
|
|
18
18
|
if (config.inlineScript === false) {
|
|
19
|
-
|
|
20
|
-
window.
|
|
21
|
-
var routeData = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
22
|
-
window._ROUTER_DATA = routeData || window._ROUTER_DATA;
|
|
19
|
+
window._SSR_DATA = parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
20
|
+
window._ROUTER_DATA = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
23
21
|
}
|
|
24
22
|
return {
|
|
25
23
|
client: function() {
|
|
@@ -12,7 +12,7 @@ var render = function(param) {
|
|
|
12
12
|
throw new Error('The "ssrContext" must not be undefined, but received undefined');
|
|
13
13
|
}
|
|
14
14
|
return run(ssrContext.request.headers, /* @__PURE__ */ _async_to_generator(function() {
|
|
15
|
-
var end, rootElement, tracker,
|
|
15
|
+
var end, rootElement, tracker, stream;
|
|
16
16
|
return _ts_generator(this, function(_state) {
|
|
17
17
|
end = time();
|
|
18
18
|
rootElement = createElement(App, {
|
|
@@ -21,7 +21,7 @@ var render = function(param) {
|
|
|
21
21
|
})
|
|
22
22
|
});
|
|
23
23
|
tracker = ssrContext.tracker;
|
|
24
|
-
|
|
24
|
+
stream = renderToPipe(rootElement, context, config, {
|
|
25
25
|
onShellReady: function onShellReady() {
|
|
26
26
|
var cost = end();
|
|
27
27
|
tracker.trackTiming(SSRTimings.RENDER_SHELL, cost);
|
|
@@ -39,7 +39,7 @@ var render = function(param) {
|
|
|
39
39
|
});
|
|
40
40
|
return [
|
|
41
41
|
2,
|
|
42
|
-
|
|
42
|
+
stream
|
|
43
43
|
];
|
|
44
44
|
});
|
|
45
45
|
}));
|
|
@@ -17,58 +17,57 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
17
17
|
var onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
18
18
|
var ssrContext = context.ssrContext;
|
|
19
19
|
var chunkVec = [];
|
|
20
|
-
var forUserPipe = function(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
this.push(chunk);
|
|
48
|
-
}
|
|
49
|
-
callback();
|
|
50
|
-
} catch (e) {
|
|
51
|
-
if (_instanceof(e, Error)) {
|
|
52
|
-
callback(e);
|
|
53
|
-
} else {
|
|
54
|
-
callback(new Error("Received unkown error when streaming"));
|
|
20
|
+
var forUserPipe = new Promise(function(resolve) {
|
|
21
|
+
var renderToPipeableStream;
|
|
22
|
+
try {
|
|
23
|
+
renderToPipeableStream = require("react-dom/server").renderToPipeableStream;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
}
|
|
26
|
+
var _obj;
|
|
27
|
+
var pipe = renderToPipeableStream(rootElement, _object_spread_props(_object_spread({}, options), (_obj = {
|
|
28
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce
|
|
29
|
+
}, _define_property(_obj, onReady, function() {
|
|
30
|
+
getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig).then(function(param) {
|
|
31
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
32
|
+
var _options_onShellReady;
|
|
33
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
34
|
+
var injectableTransform = new Transform({
|
|
35
|
+
transform: function transform(chunk, _encoding, callback) {
|
|
36
|
+
try {
|
|
37
|
+
if (shellChunkStatus !== 1) {
|
|
38
|
+
chunkVec.push(chunk.toString());
|
|
39
|
+
var concatedChunk = chunkVec.join("");
|
|
40
|
+
if (concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
41
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
42
|
+
shellChunkStatus = 1;
|
|
43
|
+
this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
|
|
55
44
|
}
|
|
45
|
+
} else {
|
|
46
|
+
this.push(chunk);
|
|
47
|
+
}
|
|
48
|
+
callback();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (_instanceof(e, Error)) {
|
|
51
|
+
callback(e);
|
|
52
|
+
} else {
|
|
53
|
+
callback(new Error("Received unkown error when streaming"));
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
}
|
|
59
|
-
resolve(pipe(injectableTransform).pipe(stream));
|
|
60
|
-
});
|
|
61
|
-
}), _define_property(_obj, "onShellError", function onShellError(error) {
|
|
62
|
-
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig).then(function(param) {
|
|
63
|
-
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
64
|
-
var _options_onShellError;
|
|
65
|
-
var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
|
|
66
|
-
resolve(fallbackHtml);
|
|
67
|
-
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
56
|
+
}
|
|
68
57
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
pipe(injectableTransform);
|
|
59
|
+
resolve(injectableTransform);
|
|
60
|
+
});
|
|
61
|
+
}), _define_property(_obj, "onShellError", function onShellError(error) {
|
|
62
|
+
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig).then(function(param) {
|
|
63
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
64
|
+
var _options_onShellError;
|
|
65
|
+
var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
|
|
66
|
+
resolve(fallbackHtml);
|
|
67
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
68
|
+
});
|
|
69
|
+
}), _obj))).pipe;
|
|
70
|
+
});
|
|
72
71
|
return forUserPipe;
|
|
73
72
|
}
|
|
74
73
|
var renderToPipe_default = renderToPipe;
|
|
@@ -17,7 +17,7 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
17
17
|
var ssrContext = context.ssrContext;
|
|
18
18
|
var forUserPipe = function() {
|
|
19
19
|
var _ref = _async_to_generator(function() {
|
|
20
|
-
var renderToReadableStream, _ref2, shellAfter, shellBefore, _context_ssrContext, readableOriginal, reader, injectableStream, err, _ref1, shellAfter1, shellBefore1, fallbackHtml;
|
|
20
|
+
var renderToReadableStream, _ref2, shellAfter, shellBefore, _options_onShellReady, _context_ssrContext, readableOriginal, reader, injectableStream, err, _ref1, shellAfter1, shellBefore1, fallbackHtml;
|
|
21
21
|
return _ts_generator(this, function(_state) {
|
|
22
22
|
switch (_state.label) {
|
|
23
23
|
case 0:
|
|
@@ -51,6 +51,11 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
51
51
|
];
|
|
52
52
|
case 3:
|
|
53
53
|
readableOriginal = _state.sent();
|
|
54
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
55
|
+
readableOriginal.allReady.then(function() {
|
|
56
|
+
var _options_onAllReady;
|
|
57
|
+
options === null || options === void 0 ? void 0 : (_options_onAllReady = options.onAllReady) === null || _options_onAllReady === void 0 ? void 0 : _options_onAllReady.call(options);
|
|
58
|
+
});
|
|
54
59
|
if (!((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider))
|
|
55
60
|
return [
|
|
56
61
|
3,
|
|
@@ -49,16 +49,16 @@ function createSSRTracker(param) {
|
|
|
49
49
|
var reporter = param.reporter, serverTiming = param.serverTiming, logger = param.logger;
|
|
50
50
|
var tracker = {
|
|
51
51
|
get sessionId() {
|
|
52
|
-
return reporter.sessionId;
|
|
52
|
+
return reporter === null || reporter === void 0 ? void 0 : reporter.sessionId;
|
|
53
53
|
},
|
|
54
54
|
trackError: function trackError(key, e) {
|
|
55
55
|
var _errors_key = errors[key], reporterContent = _errors_key.reporter, loggerContent = _errors_key.logger;
|
|
56
|
-
reporterContent && reporter.reportError("SSR Error - ".concat(reporterContent), e);
|
|
56
|
+
reporterContent && (reporter === null || reporter === void 0 ? void 0 : reporter.reportError("SSR Error - ".concat(reporterContent), e));
|
|
57
57
|
loggerContent && logger.error(loggerContent, e);
|
|
58
58
|
},
|
|
59
59
|
trackTiming: function trackTiming(key, cost) {
|
|
60
60
|
var _timings_key = timings[key], reporterName = _timings_key.reporter, serverTimingName = _timings_key.serverTiming, loggerName = _timings_key.logger;
|
|
61
|
-
reporterName && reporter.reportTiming(reporterName, cost);
|
|
61
|
+
reporterName && (reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(reporterName, cost));
|
|
62
62
|
serverTimingName && serverTiming.addServeTiming(serverTimingName, cost);
|
|
63
63
|
loggerName && logger.debug(loggerName, cost);
|
|
64
64
|
}
|
|
@@ -193,8 +193,9 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
193
193
|
const redirectUrl = result.headers.get("Location") || "/";
|
|
194
194
|
const { ssrContext } = context;
|
|
195
195
|
if (ssrContext) {
|
|
196
|
-
|
|
197
|
-
ssrContext.res.
|
|
196
|
+
var _ssrContext_res;
|
|
197
|
+
ssrContext.res && (ssrContext.res.statusCode = status);
|
|
198
|
+
(_ssrContext_res = ssrContext.res) === null || _ssrContext_res === void 0 ? void 0 : _ssrContext_res.setHeader("Location", redirectUrl);
|
|
198
199
|
ssrContext.redirection = ssrContext.redirection || {};
|
|
199
200
|
ssrContext.redirection.status = status;
|
|
200
201
|
ssrContext.redirection.url = redirectUrl;
|
|
@@ -77,7 +77,7 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
77
77
|
requestContext
|
|
78
78
|
});
|
|
79
79
|
const cost = end();
|
|
80
|
-
reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
80
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
81
81
|
serverTiming.addServeTiming(LOADER_REPORTER_NAME, cost);
|
|
82
82
|
if (routerContext instanceof Response) {
|
|
83
83
|
return routerContext;
|
|
@@ -11,10 +11,8 @@ const ssr = (config) => ({
|
|
|
11
11
|
setup: () => {
|
|
12
12
|
const mockResp = mockResponse();
|
|
13
13
|
if (config.inlineScript === false) {
|
|
14
|
-
|
|
15
|
-
window.
|
|
16
|
-
const routeData = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
17
|
-
window._ROUTER_DATA = routeData || window._ROUTER_DATA;
|
|
14
|
+
window._SSR_DATA = parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
15
|
+
window._ROUTER_DATA = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
18
16
|
}
|
|
19
17
|
return {
|
|
20
18
|
client: async ({ App, context, ModernRender, ModernHydrate }) => {
|
|
@@ -16,7 +16,7 @@ const render = ({ App, context, config }) => {
|
|
|
16
16
|
})
|
|
17
17
|
});
|
|
18
18
|
const { tracker } = ssrContext;
|
|
19
|
-
const
|
|
19
|
+
const stream = renderToPipe(rootElement, context, config, {
|
|
20
20
|
onShellReady() {
|
|
21
21
|
const cost = end();
|
|
22
22
|
tracker.trackTiming(SSRTimings.RENDER_SHELL, cost);
|
|
@@ -32,7 +32,7 @@ const render = ({ App, context, config }) => {
|
|
|
32
32
|
tracker.trackError(SSRErrors.RENDER_STREAM, error);
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
return
|
|
35
|
+
return stream;
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
export {
|
|
@@ -13,58 +13,57 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
13
13
|
const onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
14
14
|
const { ssrContext } = context;
|
|
15
15
|
const chunkVec = [];
|
|
16
|
-
const forUserPipe = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
this.push(chunk);
|
|
43
|
-
}
|
|
44
|
-
callback();
|
|
45
|
-
} catch (e) {
|
|
46
|
-
if (e instanceof Error) {
|
|
47
|
-
callback(e);
|
|
48
|
-
} else {
|
|
49
|
-
callback(new Error("Received unkown error when streaming"));
|
|
16
|
+
const forUserPipe = new Promise((resolve) => {
|
|
17
|
+
let renderToPipeableStream;
|
|
18
|
+
try {
|
|
19
|
+
({ renderToPipeableStream } = require("react-dom/server"));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
}
|
|
22
|
+
const { pipe } = renderToPipeableStream(rootElement, {
|
|
23
|
+
...options,
|
|
24
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
25
|
+
[onReady]() {
|
|
26
|
+
getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
27
|
+
var _options_onShellReady;
|
|
28
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
29
|
+
const injectableTransform = new Transform({
|
|
30
|
+
transform(chunk, _encoding, callback) {
|
|
31
|
+
try {
|
|
32
|
+
if (shellChunkStatus !== 1) {
|
|
33
|
+
chunkVec.push(chunk.toString());
|
|
34
|
+
let concatedChunk = chunkVec.join("");
|
|
35
|
+
if (concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
36
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
37
|
+
shellChunkStatus = 1;
|
|
38
|
+
this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
|
|
50
39
|
}
|
|
40
|
+
} else {
|
|
41
|
+
this.push(chunk);
|
|
42
|
+
}
|
|
43
|
+
callback();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (e instanceof Error) {
|
|
46
|
+
callback(e);
|
|
47
|
+
} else {
|
|
48
|
+
callback(new Error("Received unkown error when streaming"));
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
}
|
|
54
|
-
resolve(pipe(injectableTransform).pipe(stream));
|
|
51
|
+
}
|
|
55
52
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
pipe(injectableTransform);
|
|
54
|
+
resolve(injectableTransform);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
onShellError(error) {
|
|
58
|
+
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
59
|
+
var _options_onShellError;
|
|
60
|
+
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
61
|
+
resolve(fallbackHtml);
|
|
62
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
66
65
|
});
|
|
67
|
-
};
|
|
66
|
+
});
|
|
68
67
|
return forUserPipe;
|
|
69
68
|
}
|
|
70
69
|
var renderToPipe_default = renderToPipe;
|
|
@@ -19,7 +19,7 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
19
19
|
}
|
|
20
20
|
const { shellAfter, shellBefore } = await getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig);
|
|
21
21
|
try {
|
|
22
|
-
var _context_ssrContext;
|
|
22
|
+
var _options_onShellReady, _context_ssrContext;
|
|
23
23
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
24
24
|
...options,
|
|
25
25
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
@@ -28,6 +28,11 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
28
28
|
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
32
|
+
readableOriginal.allReady.then(() => {
|
|
33
|
+
var _options_onAllReady;
|
|
34
|
+
options === null || options === void 0 ? void 0 : (_options_onAllReady = options.onAllReady) === null || _options_onAllReady === void 0 ? void 0 : _options_onAllReady.call(options);
|
|
35
|
+
});
|
|
31
36
|
if ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) {
|
|
32
37
|
await readableOriginal.allReady;
|
|
33
38
|
}
|
|
@@ -56,16 +56,16 @@ const timings = {
|
|
|
56
56
|
function createSSRTracker({ reporter, serverTiming, logger }) {
|
|
57
57
|
const tracker = {
|
|
58
58
|
get sessionId() {
|
|
59
|
-
return reporter.sessionId;
|
|
59
|
+
return reporter === null || reporter === void 0 ? void 0 : reporter.sessionId;
|
|
60
60
|
},
|
|
61
61
|
trackError(key, e) {
|
|
62
62
|
const { reporter: reporterContent, logger: loggerContent } = errors[key];
|
|
63
|
-
reporterContent && reporter.reportError(`SSR Error - ${reporterContent}`, e);
|
|
63
|
+
reporterContent && (reporter === null || reporter === void 0 ? void 0 : reporter.reportError(`SSR Error - ${reporterContent}`, e));
|
|
64
64
|
loggerContent && logger.error(loggerContent, e);
|
|
65
65
|
},
|
|
66
66
|
trackTiming(key, cost) {
|
|
67
67
|
const { reporter: reporterName, serverTiming: serverTimingName, logger: loggerName } = timings[key];
|
|
68
|
-
reporterName && reporter.reportTiming(reporterName, cost);
|
|
68
|
+
reporterName && (reporter === null || reporter === void 0 ? void 0 : reporter.reportTiming(reporterName, cost));
|
|
69
69
|
serverTimingName && serverTiming.addServeTiming(serverTimingName, cost);
|
|
70
70
|
loggerName && logger.debug(loggerName, cost);
|
|
71
71
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ServerRenderOptions } from '../types';
|
|
3
|
-
export declare const render: ({ App, context, config }: ServerRenderOptions) => Promise<import("
|
|
3
|
+
export declare const render: ({ App, context, config }: ServerRenderOptions) => Promise<string | import("stream").Readable>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/// <reference types="react" />
|
|
3
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
4
|
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
|
|
5
5
|
import { RuntimeContext, SSRPluginConfig } from '../types';
|
|
6
|
-
|
|
7
|
-
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToPipeableStreamOptions): Pipe<Writable>;
|
|
6
|
+
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToPipeableStreamOptions): Promise<string | Readable>;
|
|
8
7
|
export default renderToPipe;
|
|
@@ -4,5 +4,9 @@ import type { Writable } from 'stream';
|
|
|
4
4
|
import type { RenderToReadableStreamOptions } from 'react-dom/server';
|
|
5
5
|
import { RuntimeContext, SSRPluginConfig } from '../types';
|
|
6
6
|
export type Pipe<T extends Writable> = (output: T) => Promise<T | string>;
|
|
7
|
-
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToReadableStreamOptions
|
|
7
|
+
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, pluginConfig: SSRPluginConfig, options?: RenderToReadableStreamOptions & {
|
|
8
|
+
onShellReady?: () => void;
|
|
9
|
+
onAllReady?: () => void;
|
|
10
|
+
onShellError?: (e: unknown) => void;
|
|
11
|
+
}): Promise<string | ReadableStream<any>>;
|
|
8
12
|
export default renderToPipe;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-next-
|
|
18
|
+
"version": "0.0.0-next-20240228090154",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -171,10 +171,10 @@
|
|
|
171
171
|
"react-side-effect": "^2.1.1",
|
|
172
172
|
"styled-components": "^5.3.1",
|
|
173
173
|
"@swc/helpers": "0.5.3",
|
|
174
|
-
"@modern-js/
|
|
175
|
-
"@modern-js/
|
|
176
|
-
"@modern-js/utils": "0.0.0-next-
|
|
177
|
-
"@modern-js/runtime-utils": "0.0.0-next-
|
|
174
|
+
"@modern-js/types": "0.0.0-next-20240228090154",
|
|
175
|
+
"@modern-js/plugin": "0.0.0-next-20240228090154",
|
|
176
|
+
"@modern-js/utils": "0.0.0-next-20240228090154",
|
|
177
|
+
"@modern-js/runtime-utils": "0.0.0-next-20240228090154"
|
|
178
178
|
},
|
|
179
179
|
"peerDependencies": {
|
|
180
180
|
"react": ">=17",
|
|
@@ -195,11 +195,11 @@
|
|
|
195
195
|
"ts-jest": "^29.1.0",
|
|
196
196
|
"typescript": "^5",
|
|
197
197
|
"webpack": "^5.89.0",
|
|
198
|
-
"@modern-js/app-tools": "0.0.0-next-
|
|
199
|
-
"@modern-js/core": "0.0.0-next-
|
|
200
|
-
"@
|
|
201
|
-
"@
|
|
202
|
-
"@scripts/jest-config": "0.0.0-next-
|
|
198
|
+
"@modern-js/app-tools": "0.0.0-next-20240228090154",
|
|
199
|
+
"@modern-js/core": "0.0.0-next-20240228090154",
|
|
200
|
+
"@modern-js/server-core": "0.0.0-next-20240228090154",
|
|
201
|
+
"@scripts/build": "0.0.0-next-20240228090154",
|
|
202
|
+
"@scripts/jest-config": "0.0.0-next-20240228090154"
|
|
203
203
|
},
|
|
204
204
|
"sideEffects": false,
|
|
205
205
|
"publishConfig": {
|