@modern-js/runtime 2.56.0 → 2.56.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/cli/code.js +5 -1
- package/dist/cjs/cli/constants.js +3 -0
- package/dist/cjs/core/browser/hydrate.js +3 -3
- package/dist/cjs/core/server/stream/createReadableStream.js +3 -3
- package/dist/cjs/core/server/string/loadable.js +1 -1
- package/dist/cjs/router/cli/code/templates.js +11 -1
- package/dist/esm/cli/code.js +7 -3
- package/dist/esm/cli/constants.js +2 -0
- package/dist/esm/core/browser/hydrate.js +3 -3
- package/dist/esm/core/server/stream/createReadableStream.js +99 -78
- package/dist/esm/core/server/string/loadable.js +1 -1
- package/dist/esm/router/cli/code/templates.js +4 -1
- package/dist/esm-node/cli/code.js +6 -2
- package/dist/esm-node/cli/constants.js +2 -0
- package/dist/esm-node/core/browser/hydrate.js +3 -3
- package/dist/esm-node/core/server/stream/createReadableStream.js +2 -2
- package/dist/esm-node/core/server/string/loadable.js +1 -1
- package/dist/esm-node/router/cli/code/templates.js +11 -1
- package/dist/types/cli/constants.d.ts +1 -0
- package/dist/types/exports/server.d.ts +1 -1
- package/package.json +10 -11
package/dist/cjs/cli/code.js
CHANGED
|
@@ -75,11 +75,15 @@ const generateCode = async (entrypoints, appContext, config, onCollectRuntimePlu
|
|
|
75
75
|
});
|
|
76
76
|
const indexFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`);
|
|
77
77
|
import_utils.fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
78
|
+
const ssrMode = getSSRMode(entryName, config);
|
|
78
79
|
if (enableAsyncEntry) {
|
|
79
80
|
const bootstrapFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
80
81
|
import_utils.fs.outputFileSync(bootstrapFile, `import('./${import_constants.INDEX_FILE_NAME}');`, "utf8");
|
|
82
|
+
const bootstrapServerFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_SERVER_BOOTSTRAP_FILE_NAME}`);
|
|
83
|
+
if (ssrMode) {
|
|
84
|
+
import_utils.fs.outputFileSync(bootstrapServerFile, `export const requestHandler = import('./${import_constants.SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler)`, "utf8");
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
|
-
const ssrMode = getSSRMode(entryName, config);
|
|
83
87
|
if (ssrMode) {
|
|
84
88
|
const indexServerCode = serverTemplate.serverIndex({
|
|
85
89
|
entry,
|
|
@@ -24,6 +24,7 @@ __export(constants_exports, {
|
|
|
24
24
|
ENTRY_POINT_REGISTER_FILE_NAME: () => ENTRY_POINT_REGISTER_FILE_NAME,
|
|
25
25
|
ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME: () => ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME,
|
|
26
26
|
ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME: () => ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME,
|
|
27
|
+
ENTRY_SERVER_BOOTSTRAP_FILE_NAME: () => ENTRY_SERVER_BOOTSTRAP_FILE_NAME,
|
|
27
28
|
INDEX_FILE_NAME: () => INDEX_FILE_NAME,
|
|
28
29
|
SERVER_ENTRY_POINT_FILE_NAME: () => SERVER_ENTRY_POINT_FILE_NAME
|
|
29
30
|
});
|
|
@@ -33,6 +34,7 @@ const ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
|
33
34
|
const SERVER_ENTRY_POINT_FILE_NAME = "index.server.jsx";
|
|
34
35
|
const INDEX_FILE_NAME = "index";
|
|
35
36
|
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
37
|
+
const ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
|
|
36
38
|
const ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
|
|
37
39
|
const ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context.js";
|
|
38
40
|
const ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
@@ -44,6 +46,7 @@ const ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
|
44
46
|
ENTRY_POINT_REGISTER_FILE_NAME,
|
|
45
47
|
ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME,
|
|
46
48
|
ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME,
|
|
49
|
+
ENTRY_SERVER_BOOTSTRAP_FILE_NAME,
|
|
47
50
|
INDEX_FILE_NAME,
|
|
48
51
|
SERVER_ENTRY_POINT_FILE_NAME
|
|
49
52
|
});
|
|
@@ -40,7 +40,7 @@ var import_constants = require("../constants");
|
|
|
40
40
|
var import_withCallback = require("./withCallback");
|
|
41
41
|
const isReact18 = () => process.env.IS_REACT18 === "true";
|
|
42
42
|
function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
43
|
-
var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
43
|
+
var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
44
44
|
const hydrateContext = {
|
|
45
45
|
...context,
|
|
46
46
|
get routes() {
|
|
@@ -50,8 +50,8 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
50
50
|
};
|
|
51
51
|
const { ssrContext } = hydrateContext;
|
|
52
52
|
const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
|
|
53
|
-
const initialPathname = (0, import_url.normalizePathname)(ssrContext.request.pathname);
|
|
54
|
-
if (initialPathname !== currentPathname && context.router) {
|
|
53
|
+
const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && (0, import_url.normalizePathname)(ssrContext.request.pathname);
|
|
54
|
+
if (initialPathname && initialPathname !== currentPathname && context.router) {
|
|
55
55
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
56
56
|
console.error(errorMsg);
|
|
57
57
|
window.location.reload();
|
|
@@ -32,7 +32,6 @@ __export(createReadableStream_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(createReadableStream_exports);
|
|
34
34
|
var import_stream = require("stream");
|
|
35
|
-
var import_server = require("react-dom/server");
|
|
36
35
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
37
36
|
var import_styled_components = require("styled-components");
|
|
38
37
|
var import_isbot = __toESM(require("isbot"));
|
|
@@ -40,7 +39,8 @@ var import_common = require("../../../common");
|
|
|
40
39
|
var import_constants = require("../../constants");
|
|
41
40
|
var import_template = require("./template");
|
|
42
41
|
var import_shared = require("./shared");
|
|
43
|
-
const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
42
|
+
const createReadableStreamFromElement = async (request, rootElement, options) => {
|
|
43
|
+
const { renderToPipeableStream } = await Promise.resolve().then(() => __toESM(require("react-dom/server")));
|
|
44
44
|
const { runtimeContext, htmlTemplate, config, ssrConfig } = options;
|
|
45
45
|
let shellChunkStatus = import_shared.ShellChunkStatus.START;
|
|
46
46
|
let renderLevel = import_constants.RenderLevel.SERVER_RENDER;
|
|
@@ -51,7 +51,7 @@ const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
|
51
51
|
const chunkVec = [];
|
|
52
52
|
const root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
|
|
53
53
|
return new Promise((resolve) => {
|
|
54
|
-
const { pipe } =
|
|
54
|
+
const { pipe } = renderToPipeableStream(root, {
|
|
55
55
|
nonce: config.nonce,
|
|
56
56
|
[onReady]() {
|
|
57
57
|
var _options_onReady;
|
|
@@ -144,7 +144,7 @@ class LoadableCollector {
|
|
|
144
144
|
return link;
|
|
145
145
|
}
|
|
146
146
|
}));
|
|
147
|
-
chunkSet.
|
|
147
|
+
chunkSet.cssChunk += css.filter((css2) => Boolean(css2)).join("");
|
|
148
148
|
}
|
|
149
149
|
generateAttributes(extraAtr = {}) {
|
|
150
150
|
const { config } = this.options;
|
|
@@ -360,7 +360,17 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
360
360
|
const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
361
361
|
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
|
|
362
362
|
const combinedModule = `export * from "${(0, import_utils.slash)(serverLoaderRuntime)}"; export * from "${(0, import_utils.slash)(serverLoadersFile)}"`;
|
|
363
|
-
|
|
363
|
+
if (!config.source.enableAsyncEntry) {
|
|
364
|
+
return combinedModule;
|
|
365
|
+
}
|
|
366
|
+
return `export default Promise.all([import("${(0, import_utils.slash)(serverLoaderRuntime)}"),import("${(0, import_utils.slash)(serverLoadersFile)}")]).then(res=>{
|
|
367
|
+
return res.reduce((sum,cur)=>{
|
|
368
|
+
return {
|
|
369
|
+
...sum,
|
|
370
|
+
...cur
|
|
371
|
+
}
|
|
372
|
+
},{})
|
|
373
|
+
})`;
|
|
364
374
|
}
|
|
365
375
|
return null;
|
|
366
376
|
}
|
package/dist/esm/cli/code.js
CHANGED
|
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { MAIN_ENTRY_NAME, fs } from "@modern-js/utils";
|
|
5
|
-
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME } from "./constants";
|
|
5
|
+
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
6
6
|
import * as template from "./template";
|
|
7
7
|
import * as serverTemplate from "./template.server";
|
|
8
8
|
function getSSRMode() {
|
|
@@ -35,7 +35,7 @@ var generateCode = function() {
|
|
|
35
35
|
4,
|
|
36
36
|
Promise.all(entrypoints.map(function() {
|
|
37
37
|
var _ref2 = _async_to_generator(function(entrypoint) {
|
|
38
|
-
var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, indexCode, indexFile, bootstrapFile,
|
|
38
|
+
var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, indexCode, indexFile, ssrMode, bootstrapFile, bootstrapServerFile, indexServerCode, indexServerFile, registerCode, registerFile, registerRuntimeCode, registerRuntimeFile, contextCode, contextFile;
|
|
39
39
|
return _ts_generator(this, function(_state2) {
|
|
40
40
|
switch (_state2.label) {
|
|
41
41
|
case 0:
|
|
@@ -62,11 +62,15 @@ var generateCode = function() {
|
|
|
62
62
|
});
|
|
63
63
|
indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
64
64
|
fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
65
|
+
ssrMode = getSSRMode(entryName, config);
|
|
65
66
|
if (enableAsyncEntry) {
|
|
66
67
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
67
68
|
fs.outputFileSync(bootstrapFile, "import('./".concat(INDEX_FILE_NAME, "');"), "utf8");
|
|
69
|
+
bootstrapServerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_SERVER_BOOTSTRAP_FILE_NAME));
|
|
70
|
+
if (ssrMode) {
|
|
71
|
+
fs.outputFileSync(bootstrapServerFile, "export const requestHandler = import('./".concat(SERVER_ENTRY_POINT_FILE_NAME, "').then((m) => m.requestHandler)"), "utf8");
|
|
72
|
+
}
|
|
68
73
|
}
|
|
69
|
-
ssrMode = getSSRMode(entryName, config);
|
|
70
74
|
if (ssrMode) {
|
|
71
75
|
indexServerCode = serverTemplate.serverIndex({
|
|
72
76
|
entry,
|
|
@@ -3,6 +3,7 @@ var ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
|
3
3
|
var SERVER_ENTRY_POINT_FILE_NAME = "index.server.jsx";
|
|
4
4
|
var INDEX_FILE_NAME = "index";
|
|
5
5
|
var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
6
|
+
var ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
|
|
6
7
|
var ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
|
|
7
8
|
var ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context.js";
|
|
8
9
|
var ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
ENTRY_POINT_REGISTER_FILE_NAME,
|
|
14
15
|
ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME,
|
|
15
16
|
ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME,
|
|
17
|
+
ENTRY_SERVER_BOOTSTRAP_FILE_NAME,
|
|
16
18
|
INDEX_FILE_NAME,
|
|
17
19
|
SERVER_ENTRY_POINT_FILE_NAME
|
|
18
20
|
};
|
|
@@ -10,7 +10,7 @@ var isReact18 = function() {
|
|
|
10
10
|
return process.env.IS_REACT18 === "true";
|
|
11
11
|
};
|
|
12
12
|
function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
13
|
-
var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
13
|
+
var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
14
14
|
var hydrateContext = _object_spread_props(_object_spread({}, context), {
|
|
15
15
|
get routes() {
|
|
16
16
|
return context.routes;
|
|
@@ -19,8 +19,8 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
19
19
|
});
|
|
20
20
|
var ssrContext = hydrateContext.ssrContext;
|
|
21
21
|
var currentPathname = normalizePathname(window.location.pathname);
|
|
22
|
-
var initialPathname = normalizePathname(ssrContext.request.pathname);
|
|
23
|
-
if (initialPathname !== currentPathname && context.router) {
|
|
22
|
+
var initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
|
|
23
|
+
if (initialPathname && initialPathname !== currentPathname && context.router) {
|
|
24
24
|
var errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
|
|
25
25
|
console.error(errorMsg);
|
|
26
26
|
window.location.reload();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
1
2
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
3
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
5
|
import { Transform } from "stream";
|
|
4
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
5
6
|
import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
|
|
6
7
|
import { ServerStyleSheet } from "styled-components";
|
|
7
8
|
import checkIsBot from "isbot";
|
|
@@ -9,84 +10,104 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
9
10
|
import { RenderLevel } from "../../constants";
|
|
10
11
|
import { getTemplates } from "./template";
|
|
11
12
|
import { ShellChunkStatus, getReadableStreamFromString } from "./shared";
|
|
12
|
-
var createReadableStreamFromElement = function(
|
|
13
|
-
var
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
13
|
+
var createReadableStreamFromElement = function() {
|
|
14
|
+
var _ref = _async_to_generator(function(request, rootElement, options) {
|
|
15
|
+
var renderToPipeableStream, runtimeContext, htmlTemplate, config, ssrConfig, shellChunkStatus, renderLevel, forceStream2String, isbot, onReady, sheet, chunkVec, root;
|
|
16
|
+
return _ts_generator(this, function(_state) {
|
|
17
|
+
switch (_state.label) {
|
|
18
|
+
case 0:
|
|
19
|
+
return [
|
|
20
|
+
4,
|
|
21
|
+
import("react-dom/server")
|
|
22
|
+
];
|
|
23
|
+
case 1:
|
|
24
|
+
renderToPipeableStream = _state.sent().renderToPipeableStream;
|
|
25
|
+
runtimeContext = options.runtimeContext, htmlTemplate = options.htmlTemplate, config = options.config, ssrConfig = options.ssrConfig;
|
|
26
|
+
shellChunkStatus = ShellChunkStatus.START;
|
|
27
|
+
renderLevel = RenderLevel.SERVER_RENDER;
|
|
28
|
+
forceStream2String = Boolean(process.env.MODERN_JS_STREAM_TO_STRING);
|
|
29
|
+
isbot = checkIsBot(request.headers.get("user-agent"));
|
|
30
|
+
onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
|
|
31
|
+
sheet = new ServerStyleSheet();
|
|
32
|
+
chunkVec = [];
|
|
33
|
+
root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
|
|
34
|
+
return [
|
|
35
|
+
2,
|
|
36
|
+
new Promise(function(resolve) {
|
|
37
|
+
var _obj;
|
|
38
|
+
var pipe = renderToPipeableStream(root, (_obj = {
|
|
39
|
+
nonce: config.nonce
|
|
40
|
+
}, _define_property(_obj, onReady, function() {
|
|
41
|
+
var _options_onReady;
|
|
42
|
+
var styledComponentsStyleTags = forceStream2String ? sheet.getStyleTags() : "";
|
|
43
|
+
(_options_onReady = options[onReady]) === null || _options_onReady === void 0 ? void 0 : _options_onReady.call(options);
|
|
44
|
+
getTemplates(htmlTemplate, {
|
|
45
|
+
request,
|
|
46
|
+
ssrConfig,
|
|
47
|
+
renderLevel,
|
|
48
|
+
runtimeContext,
|
|
49
|
+
config,
|
|
50
|
+
styledComponentsStyleTags
|
|
51
|
+
}).then(function(param) {
|
|
52
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
53
|
+
var body = new Transform({
|
|
54
|
+
transform: function transform(chunk, _encoding, callback) {
|
|
55
|
+
try {
|
|
56
|
+
if (shellChunkStatus !== ShellChunkStatus.FINISH) {
|
|
57
|
+
chunkVec.push(chunk.toString());
|
|
58
|
+
var concatedChunk = chunkVec.join("");
|
|
59
|
+
if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
60
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
61
|
+
shellChunkStatus = ShellChunkStatus.FINISH;
|
|
62
|
+
this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
this.push(chunk);
|
|
66
|
+
}
|
|
67
|
+
callback();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (_instanceof(e, Error)) {
|
|
70
|
+
callback(e);
|
|
71
|
+
} else {
|
|
72
|
+
callback(new Error("Received unkown error when streaming"));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var stream = createReadableStreamFromReadable(body);
|
|
78
|
+
resolve(stream);
|
|
79
|
+
pipe(body);
|
|
80
|
+
});
|
|
81
|
+
}), _define_property(_obj, "onShellError", function onShellError(error) {
|
|
82
|
+
renderLevel = RenderLevel.CLIENT_RENDER;
|
|
83
|
+
getTemplates(htmlTemplate, {
|
|
84
|
+
request,
|
|
85
|
+
ssrConfig,
|
|
86
|
+
renderLevel,
|
|
87
|
+
runtimeContext,
|
|
88
|
+
config
|
|
89
|
+
}).then(function(param) {
|
|
90
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
91
|
+
var _options_onShellError;
|
|
92
|
+
var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
|
|
93
|
+
var readableStream = getReadableStreamFromString(fallbackHtml);
|
|
94
|
+
resolve(readableStream);
|
|
95
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
96
|
+
});
|
|
97
|
+
}), _define_property(_obj, "onError", function onError(error) {
|
|
98
|
+
var _options_onError;
|
|
99
|
+
renderLevel = RenderLevel.CLIENT_RENDER;
|
|
100
|
+
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
101
|
+
}), _obj)).pipe;
|
|
102
|
+
})
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
88
106
|
});
|
|
89
|
-
|
|
107
|
+
return function createReadableStreamFromElement2(request, rootElement, options) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
90
111
|
export {
|
|
91
112
|
createReadableStreamFromElement
|
|
92
113
|
};
|
|
@@ -243,7 +243,7 @@ var LoadableCollector = /* @__PURE__ */ function() {
|
|
|
243
243
|
];
|
|
244
244
|
case 1:
|
|
245
245
|
css = _state.sent();
|
|
246
|
-
chunkSet.
|
|
246
|
+
chunkSet.cssChunk += css.filter(function(css2) {
|
|
247
247
|
return Boolean(css2);
|
|
248
248
|
}).join("");
|
|
249
249
|
return [
|
|
@@ -406,7 +406,10 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
406
406
|
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
407
407
|
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
408
408
|
var combinedModule = 'export * from "'.concat(slash(serverLoaderRuntime), '"; export * from "').concat(slash(serverLoadersFile), '"');
|
|
409
|
-
|
|
409
|
+
if (!config.source.enableAsyncEntry) {
|
|
410
|
+
return combinedModule;
|
|
411
|
+
}
|
|
412
|
+
return 'export default Promise.all([import("'.concat(slash(serverLoaderRuntime), '"),import("').concat(slash(serverLoadersFile), '")]).then(res=>{\n return res.reduce((sum,cur)=>{\n return {\n ...sum,\n ...cur\n }\n },{})\n })');
|
|
410
413
|
}
|
|
411
414
|
return null;
|
|
412
415
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { MAIN_ENTRY_NAME, fs } from "@modern-js/utils";
|
|
3
|
-
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME } from "./constants";
|
|
3
|
+
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
4
4
|
import * as template from "./template";
|
|
5
5
|
import * as serverTemplate from "./template.server";
|
|
6
6
|
function getSSRMode(entry = MAIN_ENTRY_NAME, config) {
|
|
@@ -42,11 +42,15 @@ const generateCode = async (entrypoints, appContext, config, onCollectRuntimePlu
|
|
|
42
42
|
});
|
|
43
43
|
const indexFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
44
44
|
fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
45
|
+
const ssrMode = getSSRMode(entryName, config);
|
|
45
46
|
if (enableAsyncEntry) {
|
|
46
47
|
const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
47
48
|
fs.outputFileSync(bootstrapFile, `import('./${INDEX_FILE_NAME}');`, "utf8");
|
|
49
|
+
const bootstrapServerFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_SERVER_BOOTSTRAP_FILE_NAME}`);
|
|
50
|
+
if (ssrMode) {
|
|
51
|
+
fs.outputFileSync(bootstrapServerFile, `export const requestHandler = import('./${SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler)`, "utf8");
|
|
52
|
+
}
|
|
48
53
|
}
|
|
49
|
-
const ssrMode = getSSRMode(entryName, config);
|
|
50
54
|
if (ssrMode) {
|
|
51
55
|
const indexServerCode = serverTemplate.serverIndex({
|
|
52
56
|
entry,
|
|
@@ -3,6 +3,7 @@ const ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
|
3
3
|
const SERVER_ENTRY_POINT_FILE_NAME = "index.server.jsx";
|
|
4
4
|
const INDEX_FILE_NAME = "index";
|
|
5
5
|
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
6
|
+
const ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
|
|
6
7
|
const ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
|
|
7
8
|
const ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context.js";
|
|
8
9
|
const ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
ENTRY_POINT_REGISTER_FILE_NAME,
|
|
14
15
|
ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME,
|
|
15
16
|
ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME,
|
|
17
|
+
ENTRY_SERVER_BOOTSTRAP_FILE_NAME,
|
|
16
18
|
INDEX_FILE_NAME,
|
|
17
19
|
SERVER_ENTRY_POINT_FILE_NAME
|
|
18
20
|
};
|
|
@@ -6,7 +6,7 @@ import { RenderLevel } from "../constants";
|
|
|
6
6
|
import { WithCallback } from "./withCallback";
|
|
7
7
|
const isReact18 = () => process.env.IS_REACT18 === "true";
|
|
8
8
|
function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
9
|
-
var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
9
|
+
var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
|
|
10
10
|
const hydrateContext = {
|
|
11
11
|
...context,
|
|
12
12
|
get routes() {
|
|
@@ -16,8 +16,8 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
16
16
|
};
|
|
17
17
|
const { ssrContext } = hydrateContext;
|
|
18
18
|
const currentPathname = normalizePathname(window.location.pathname);
|
|
19
|
-
const initialPathname = normalizePathname(ssrContext.request.pathname);
|
|
20
|
-
if (initialPathname !== currentPathname && context.router) {
|
|
19
|
+
const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
|
|
20
|
+
if (initialPathname && initialPathname !== currentPathname && context.router) {
|
|
21
21
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
22
22
|
console.error(errorMsg);
|
|
23
23
|
window.location.reload();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Transform } from "stream";
|
|
2
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
3
2
|
import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
|
|
4
3
|
import { ServerStyleSheet } from "styled-components";
|
|
5
4
|
import checkIsBot from "isbot";
|
|
@@ -7,7 +6,8 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
7
6
|
import { RenderLevel } from "../../constants";
|
|
8
7
|
import { getTemplates } from "./template";
|
|
9
8
|
import { ShellChunkStatus, getReadableStreamFromString } from "./shared";
|
|
10
|
-
const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
9
|
+
const createReadableStreamFromElement = async (request, rootElement, options) => {
|
|
10
|
+
const { renderToPipeableStream } = await import("react-dom/server");
|
|
11
11
|
const { runtimeContext, htmlTemplate, config, ssrConfig } = options;
|
|
12
12
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
13
13
|
let renderLevel = RenderLevel.SERVER_RENDER;
|
|
@@ -111,7 +111,7 @@ class LoadableCollector {
|
|
|
111
111
|
return link;
|
|
112
112
|
}
|
|
113
113
|
}));
|
|
114
|
-
chunkSet.
|
|
114
|
+
chunkSet.cssChunk += css.filter((css2) => Boolean(css2)).join("");
|
|
115
115
|
}
|
|
116
116
|
generateAttributes(extraAtr = {}) {
|
|
117
117
|
const { config } = this.options;
|
|
@@ -324,7 +324,17 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
324
324
|
const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
325
325
|
const serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
326
326
|
const combinedModule = `export * from "${slash(serverLoaderRuntime)}"; export * from "${slash(serverLoadersFile)}"`;
|
|
327
|
-
|
|
327
|
+
if (!config.source.enableAsyncEntry) {
|
|
328
|
+
return combinedModule;
|
|
329
|
+
}
|
|
330
|
+
return `export default Promise.all([import("${slash(serverLoaderRuntime)}"),import("${slash(serverLoadersFile)}")]).then(res=>{
|
|
331
|
+
return res.reduce((sum,cur)=>{
|
|
332
|
+
return {
|
|
333
|
+
...sum,
|
|
334
|
+
...cur
|
|
335
|
+
}
|
|
336
|
+
},{})
|
|
337
|
+
})`;
|
|
328
338
|
}
|
|
329
339
|
return null;
|
|
330
340
|
}
|
|
@@ -3,6 +3,7 @@ export declare const ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
|
3
3
|
export declare const SERVER_ENTRY_POINT_FILE_NAME = "index.server.jsx";
|
|
4
4
|
export declare const INDEX_FILE_NAME = "index";
|
|
5
5
|
export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
6
|
+
export declare const ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
|
|
6
7
|
export declare const ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
|
|
7
8
|
export declare const ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context.js";
|
|
8
9
|
export declare const ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AfterMatchContext, AfterRenderContext, MiddlewareContext, NextFunction } from '@modern-js/types';
|
|
2
|
-
export type { Container, CacheControl, CacheOptionProvider, CacheOption, UnstableMiddlewareContext, UnstableMiddleware, UnstableNext, } from '@modern-js/types';
|
|
2
|
+
export type { Container, CacheControl, CacheOptionProvider, CacheOption, UnstableMiddlewareContext, UnstableMiddleware, UnstableNext, MonitorEvent, Monitors, CoreMonitor, LogEvent, LogLevel, TimingEvent, } from '@modern-js/types';
|
|
3
3
|
export declare const hook: (attacher: ({ addMiddleware, afterMatch, afterRender, }: {
|
|
4
4
|
addMiddleware: (mid: Middleware) => void;
|
|
5
5
|
afterRender: (hook: AfterRenderHook) => void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.56.
|
|
18
|
+
"version": "2.56.2",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -182,7 +182,6 @@
|
|
|
182
182
|
"@loadable/babel-plugin": "5.15.3",
|
|
183
183
|
"@loadable/component": "5.15.3",
|
|
184
184
|
"@loadable/server": "5.15.3",
|
|
185
|
-
"@loadable/webpack-plugin": "5.15.2",
|
|
186
185
|
"@modern-js-reduck/plugin-auto-actions": "^1.1.10",
|
|
187
186
|
"@modern-js-reduck/plugin-devtools": "^1.1.10",
|
|
188
187
|
"@modern-js-reduck/plugin-effects": "^1.1.10",
|
|
@@ -200,11 +199,11 @@
|
|
|
200
199
|
"react-side-effect": "^2.1.1",
|
|
201
200
|
"styled-components": "^5.3.1",
|
|
202
201
|
"@swc/helpers": "0.5.3",
|
|
203
|
-
"@modern-js/plugin": "2.56.
|
|
204
|
-
"@modern-js/
|
|
205
|
-
"@modern-js/utils": "2.56.
|
|
206
|
-
"@modern-js/
|
|
207
|
-
"@modern-js/plugin-data-loader": "2.56.
|
|
202
|
+
"@modern-js/plugin": "2.56.2",
|
|
203
|
+
"@modern-js/utils": "2.56.2",
|
|
204
|
+
"@modern-js/runtime-utils": "2.56.2",
|
|
205
|
+
"@modern-js/types": "2.56.2",
|
|
206
|
+
"@modern-js/plugin-data-loader": "2.56.2"
|
|
208
207
|
},
|
|
209
208
|
"peerDependencies": {
|
|
210
209
|
"react": ">=17",
|
|
@@ -227,10 +226,10 @@
|
|
|
227
226
|
"ts-jest": "^29.1.0",
|
|
228
227
|
"typescript": "^5",
|
|
229
228
|
"webpack": "^5.93.0",
|
|
230
|
-
"@modern-js/app-tools": "2.56.
|
|
231
|
-
"@modern-js/core": "2.56.
|
|
232
|
-
"@scripts/
|
|
233
|
-
"@scripts/
|
|
229
|
+
"@modern-js/app-tools": "2.56.2",
|
|
230
|
+
"@modern-js/core": "2.56.2",
|
|
231
|
+
"@scripts/jest-config": "2.56.2",
|
|
232
|
+
"@scripts/build": "2.56.2"
|
|
234
233
|
},
|
|
235
234
|
"sideEffects": false,
|
|
236
235
|
"publishConfig": {
|