@modern-js/runtime 2.45.0 → 2.45.1-alpha.0
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/router/runtime/plugin.node.js +3 -0
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +3 -1
- package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -0
- package/dist/esm/router/runtime/plugin.node.js +3 -0
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +42 -40
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +19 -6
- package/dist/esm-node/router/runtime/plugin.node.js +3 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +3 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -0
- package/package.json +4 -4
|
@@ -111,6 +111,9 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
111
111
|
const routerContext = await query(remixRequest, {
|
|
112
112
|
requestContext
|
|
113
113
|
});
|
|
114
|
+
if ("errors" in routerContext && routerContext.errors && Object.keys(routerContext.errors).length > 0) {
|
|
115
|
+
throw new Error(Object.values(routerContext.errors)[0]);
|
|
116
|
+
}
|
|
114
117
|
const cost = end();
|
|
115
118
|
reporter.reportTiming(import_constants.LOADER_REPORTER_NAME, cost);
|
|
116
119
|
serverTiming.addServeTiming(import_constants.LOADER_REPORTER_NAME, cost);
|
|
@@ -31,7 +31,9 @@ var ShellChunkStatus;
|
|
|
31
31
|
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
32
32
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
33
33
|
function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
34
|
+
var _context_ssrContext;
|
|
34
35
|
let shellChunkStatus = 0;
|
|
36
|
+
const onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
35
37
|
const { ssrContext } = context;
|
|
36
38
|
const chunkVec = [];
|
|
37
39
|
const forUserPipe = (stream) => {
|
|
@@ -44,7 +46,7 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
44
46
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
45
47
|
...options,
|
|
46
48
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
47
|
-
|
|
49
|
+
[onReady]() {
|
|
48
50
|
(0, import_template.getTemplates)(context, import_types.RenderLevel.SERVER_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
49
51
|
var _options_onShellReady;
|
|
50
52
|
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
@@ -42,6 +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
46
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
46
47
|
...options,
|
|
47
48
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
@@ -50,6 +51,9 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
50
51
|
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
51
52
|
}
|
|
52
53
|
});
|
|
54
|
+
if ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) {
|
|
55
|
+
await readableOriginal.allReady;
|
|
56
|
+
}
|
|
53
57
|
const reader = readableOriginal.getReader();
|
|
54
58
|
const injectableStream = new ReadableStream({
|
|
55
59
|
start(controller) {
|
|
@@ -131,6 +131,9 @@ var routerPlugin = function(param) {
|
|
|
131
131
|
];
|
|
132
132
|
case 1:
|
|
133
133
|
routerContext = _state.sent();
|
|
134
|
+
if ("errors" in routerContext && routerContext.errors && Object.keys(routerContext.errors).length > 0) {
|
|
135
|
+
throw new Error(Object.values(routerContext.errors)[0]);
|
|
136
|
+
}
|
|
134
137
|
cost = end();
|
|
135
138
|
reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
136
139
|
serverTiming.addServeTiming(LOADER_REPORTER_NAME, cost);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
1
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
2
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
@@ -11,7 +12,9 @@ var ShellChunkStatus;
|
|
|
11
12
|
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
12
13
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
13
14
|
function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
15
|
+
var _context_ssrContext;
|
|
14
16
|
var shellChunkStatus = 0;
|
|
17
|
+
var onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
15
18
|
var ssrContext = context.ssrContext;
|
|
16
19
|
var chunkVec = [];
|
|
17
20
|
var forUserPipe = function(stream) {
|
|
@@ -21,50 +24,49 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
21
24
|
renderToPipeableStream = require("react-dom/server").renderToPipeableStream;
|
|
22
25
|
} catch (e) {
|
|
23
26
|
}
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} else {
|
|
43
|
-
this.push(chunk);
|
|
44
|
-
}
|
|
45
|
-
callback();
|
|
46
|
-
} catch (e) {
|
|
47
|
-
if (_instanceof(e, Error)) {
|
|
48
|
-
callback(e);
|
|
49
|
-
} else {
|
|
50
|
-
callback(new Error("Received unkown error when streaming"));
|
|
27
|
+
var _obj;
|
|
28
|
+
var pipe = renderToPipeableStream(rootElement, _object_spread_props(_object_spread({}, options), (_obj = {
|
|
29
|
+
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce
|
|
30
|
+
}, _define_property(_obj, onReady, function() {
|
|
31
|
+
getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig).then(function(param) {
|
|
32
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
33
|
+
var _options_onShellReady;
|
|
34
|
+
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
35
|
+
var injectableTransform = new Transform({
|
|
36
|
+
transform: function transform(chunk, _encoding, callback) {
|
|
37
|
+
try {
|
|
38
|
+
if (shellChunkStatus !== 1) {
|
|
39
|
+
chunkVec.push(chunk.toString());
|
|
40
|
+
var concatedChunk = chunkVec.join("");
|
|
41
|
+
if (concatedChunk.endsWith(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
42
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
43
|
+
shellChunkStatus = 1;
|
|
44
|
+
this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
|
|
51
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"));
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
}
|
|
55
|
-
resolve(pipe(injectableTransform).pipe(stream));
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
onShellError: function onShellError(error) {
|
|
59
|
-
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig).then(function(param) {
|
|
60
|
-
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
61
|
-
var _options_onShellError;
|
|
62
|
-
var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
|
|
63
|
-
resolve(fallbackHtml);
|
|
64
|
-
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
57
|
+
}
|
|
65
58
|
});
|
|
66
|
-
|
|
67
|
-
|
|
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);
|
|
68
|
+
});
|
|
69
|
+
}), _obj))).pipe;
|
|
68
70
|
});
|
|
69
71
|
};
|
|
70
72
|
return forUserPipe;
|
|
@@ -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, readableOriginal, reader, injectableStream, err, _ref1, shellAfter1, shellBefore1, fallbackHtml;
|
|
20
|
+
var renderToReadableStream, _ref2, shellAfter, shellBefore, _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:
|
|
@@ -35,9 +35,9 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
35
35
|
case 2:
|
|
36
36
|
_state.trys.push([
|
|
37
37
|
2,
|
|
38
|
-
|
|
38
|
+
6,
|
|
39
39
|
,
|
|
40
|
-
|
|
40
|
+
8
|
|
41
41
|
]);
|
|
42
42
|
return [
|
|
43
43
|
4,
|
|
@@ -51,6 +51,19 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
51
51
|
];
|
|
52
52
|
case 3:
|
|
53
53
|
readableOriginal = _state.sent();
|
|
54
|
+
if (!((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider))
|
|
55
|
+
return [
|
|
56
|
+
3,
|
|
57
|
+
5
|
|
58
|
+
];
|
|
59
|
+
return [
|
|
60
|
+
4,
|
|
61
|
+
readableOriginal.allReady
|
|
62
|
+
];
|
|
63
|
+
case 4:
|
|
64
|
+
_state.sent();
|
|
65
|
+
_state.label = 5;
|
|
66
|
+
case 5:
|
|
54
67
|
reader = readableOriginal.getReader();
|
|
55
68
|
injectableStream = new ReadableStream({
|
|
56
69
|
start: function start(controller) {
|
|
@@ -103,21 +116,21 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
103
116
|
2,
|
|
104
117
|
injectableStream
|
|
105
118
|
];
|
|
106
|
-
case
|
|
119
|
+
case 6:
|
|
107
120
|
err = _state.sent();
|
|
108
121
|
ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.tracker.trackError(SSRErrors.RENDER_SHELL, err);
|
|
109
122
|
return [
|
|
110
123
|
4,
|
|
111
124
|
getTemplates(context, RenderLevel.CLIENT_RENDER, pluginConfig)
|
|
112
125
|
];
|
|
113
|
-
case
|
|
126
|
+
case 7:
|
|
114
127
|
_ref1 = _state.sent(), shellAfter1 = _ref1.shellAfter, shellBefore1 = _ref1.shellBefore;
|
|
115
128
|
fallbackHtml = "".concat(shellBefore1).concat(shellAfter1);
|
|
116
129
|
return [
|
|
117
130
|
2,
|
|
118
131
|
fallbackHtml
|
|
119
132
|
];
|
|
120
|
-
case
|
|
133
|
+
case 8:
|
|
121
134
|
return [
|
|
122
135
|
2
|
|
123
136
|
];
|
|
@@ -76,6 +76,9 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
76
76
|
const routerContext = await query(remixRequest, {
|
|
77
77
|
requestContext
|
|
78
78
|
});
|
|
79
|
+
if ("errors" in routerContext && routerContext.errors && Object.keys(routerContext.errors).length > 0) {
|
|
80
|
+
throw new Error(Object.values(routerContext.errors)[0]);
|
|
81
|
+
}
|
|
79
82
|
const cost = end();
|
|
80
83
|
reporter.reportTiming(LOADER_REPORTER_NAME, cost);
|
|
81
84
|
serverTiming.addServeTiming(LOADER_REPORTER_NAME, cost);
|
|
@@ -8,7 +8,9 @@ var ShellChunkStatus;
|
|
|
8
8
|
ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 1] = "FINIESH";
|
|
9
9
|
})(ShellChunkStatus || (ShellChunkStatus = {}));
|
|
10
10
|
function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
11
|
+
var _context_ssrContext;
|
|
11
12
|
let shellChunkStatus = 0;
|
|
13
|
+
const onReady = ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) ? "onAllReady" : "onShellReady";
|
|
12
14
|
const { ssrContext } = context;
|
|
13
15
|
const chunkVec = [];
|
|
14
16
|
const forUserPipe = (stream) => {
|
|
@@ -21,7 +23,7 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
21
23
|
const { pipe } = renderToPipeableStream(rootElement, {
|
|
22
24
|
...options,
|
|
23
25
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
24
|
-
|
|
26
|
+
[onReady]() {
|
|
25
27
|
getTemplates(context, RenderLevel.SERVER_RENDER, pluginConfig).then(({ shellAfter, shellBefore }) => {
|
|
26
28
|
var _options_onShellReady;
|
|
27
29
|
options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
|
|
@@ -19,6 +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
23
|
const readableOriginal = await renderToReadableStream(rootElement, {
|
|
23
24
|
...options,
|
|
24
25
|
nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
|
|
@@ -27,6 +28,9 @@ function renderToPipe(rootElement, context, pluginConfig, options) {
|
|
|
27
28
|
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
if ((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.isSpider) {
|
|
32
|
+
await readableOriginal.allReady;
|
|
33
|
+
}
|
|
30
34
|
const reader = readableOriginal.getReader();
|
|
31
35
|
const injectableStream = new ReadableStream({
|
|
32
36
|
start(controller) {
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.45.0",
|
|
18
|
+
"version": "2.45.1-alpha.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -171,8 +171,8 @@
|
|
|
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/plugin": "2.45.0",
|
|
175
174
|
"@modern-js/types": "2.45.0",
|
|
175
|
+
"@modern-js/plugin": "2.45.0",
|
|
176
176
|
"@modern-js/utils": "2.45.0",
|
|
177
177
|
"@modern-js/runtime-utils": "2.45.0"
|
|
178
178
|
},
|
|
@@ -195,10 +195,10 @@
|
|
|
195
195
|
"ts-jest": "^29.1.0",
|
|
196
196
|
"typescript": "^5",
|
|
197
197
|
"webpack": "^5.89.0",
|
|
198
|
-
"@
|
|
198
|
+
"@scripts/build": "2.45.0",
|
|
199
199
|
"@modern-js/core": "2.45.0",
|
|
200
200
|
"@modern-js/server-core": "2.45.0",
|
|
201
|
-
"@
|
|
201
|
+
"@modern-js/app-tools": "2.45.0",
|
|
202
202
|
"@scripts/jest-config": "2.45.0"
|
|
203
203
|
},
|
|
204
204
|
"sideEffects": false,
|