@modern-js/runtime 2.48.0 → 2.48.1
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/ssr/cli/loadable-bundler-plugin.js +0 -3
- package/dist/cjs/ssr/index.js +2 -1
- package/dist/cjs/ssr/react/prerender/index.js +5 -7
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +0 -10
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +0 -3
- package/dist/cjs/ssr/serverRender/renderToString/render.js +1 -3
- package/dist/cjs/ssr/serverRender/renderToString/styledComponent.js +1 -3
- package/dist/esm/ssr/cli/loadable-bundler-plugin.js +63 -77
- package/dist/esm/ssr/index.js +2 -1
- package/dist/esm/ssr/react/prerender/index.js +20 -27
- package/dist/esm/ssr/serverRender/renderToString/entry.js +177 -201
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +197 -217
- package/dist/esm/ssr/serverRender/renderToString/render.js +33 -43
- package/dist/esm/ssr/serverRender/renderToString/styledComponent.js +9 -19
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +0 -3
- package/dist/esm-node/ssr/index.js +2 -1
- package/dist/esm-node/ssr/react/prerender/index.js +5 -7
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +0 -10
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +0 -3
- package/dist/esm-node/ssr/serverRender/renderToString/render.js +1 -3
- package/dist/esm-node/ssr/serverRender/renderToString/styledComponent.js +1 -3
- package/package.json +10 -10
|
@@ -21,7 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
24
|
var import_path = __toESM(require("path"));
|
|
26
25
|
var import_utils = require("@modern-js/utils");
|
|
27
26
|
class LoadablePlugin {
|
|
@@ -99,8 +98,6 @@ class LoadablePlugin {
|
|
|
99
98
|
outputAsset: true,
|
|
100
99
|
chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
|
|
101
100
|
}) {
|
|
102
|
-
(0, import_define_property._)(this, "opts", void 0);
|
|
103
|
-
(0, import_define_property._)(this, "compiler", void 0);
|
|
104
101
|
this.opts = {
|
|
105
102
|
filename,
|
|
106
103
|
path: path2,
|
package/dist/cjs/ssr/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
37
37
|
var import_component = require("@loadable/component");
|
|
38
38
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
39
39
|
var import_parsed = require("@modern-js/runtime-utils/parsed");
|
|
40
|
+
var import_url = require("@modern-js/runtime-utils/url");
|
|
40
41
|
var import_types = require("./serverRender/types");
|
|
41
42
|
var import_withCallback = require("./react/withCallback");
|
|
42
43
|
var import_utils = require("./utils");
|
|
@@ -64,7 +65,7 @@ const ssr = (config) => ({
|
|
|
64
65
|
};
|
|
65
66
|
const { ssrContext } = hydrateContext;
|
|
66
67
|
const { pathname: initialPathname } = ssrContext.request;
|
|
67
|
-
const currentPathname = window.location.pathname;
|
|
68
|
+
const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
|
|
68
69
|
if (initialPathname !== currentPathname) {
|
|
69
70
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
70
71
|
console.error(errorMsg);
|
|
@@ -31,7 +31,6 @@ __export(prerender_exports, {
|
|
|
31
31
|
PreRender: () => PreRender
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(prerender_exports);
|
|
34
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
34
|
var import_react_side_effect = __toESM(require("react-side-effect"));
|
|
36
35
|
var import_react = __toESM(require("react"));
|
|
37
36
|
var import_util = require("./util");
|
|
@@ -82,8 +81,7 @@ const reducePropsToState = (propsList) => {
|
|
|
82
81
|
return reduceProps;
|
|
83
82
|
};
|
|
84
83
|
function factory(Component) {
|
|
85
|
-
|
|
86
|
-
class Spr extends (_React_Component = import_react.default.Component) {
|
|
84
|
+
class Spr extends import_react.default.Component {
|
|
87
85
|
static set canUseDOM(canUseDOM) {
|
|
88
86
|
Component.canUseDOM = canUseDOM;
|
|
89
87
|
}
|
|
@@ -107,12 +105,12 @@ function factory(Component) {
|
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
Spr.peek = Component.peek;
|
|
109
|
+
Spr.rewind = Component.rewind;
|
|
110
|
+
Spr.config = () => {
|
|
113
111
|
const mappedState = Component.rewind();
|
|
114
112
|
return mappedState;
|
|
115
|
-
}
|
|
113
|
+
};
|
|
116
114
|
return Spr;
|
|
117
115
|
}
|
|
118
116
|
const NullComponent = () => null;
|
|
@@ -31,7 +31,6 @@ __export(entry_exports, {
|
|
|
31
31
|
default: () => Entry
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(entry_exports);
|
|
34
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
34
|
var import_react = __toESM(require("react"));
|
|
36
35
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
37
36
|
var import_react_helmet = __toESM(require("react-helmet"));
|
|
@@ -159,15 +158,6 @@ class Entry {
|
|
|
159
158
|
return ssrDataScripts;
|
|
160
159
|
}
|
|
161
160
|
constructor(options) {
|
|
162
|
-
(0, import_define_property._)(this, "entryName", void 0);
|
|
163
|
-
(0, import_define_property._)(this, "result", void 0);
|
|
164
|
-
(0, import_define_property._)(this, "tracker", void 0);
|
|
165
|
-
(0, import_define_property._)(this, "template", void 0);
|
|
166
|
-
(0, import_define_property._)(this, "App", void 0);
|
|
167
|
-
(0, import_define_property._)(this, "pluginConfig", void 0);
|
|
168
|
-
(0, import_define_property._)(this, "htmlModifiers", void 0);
|
|
169
|
-
(0, import_define_property._)(this, "nonce", void 0);
|
|
170
|
-
(0, import_define_property._)(this, "routeManifest", void 0);
|
|
171
161
|
const { ctx, config } = options;
|
|
172
162
|
const { entryName, template, nonce } = ctx;
|
|
173
163
|
this.template = template;
|
|
@@ -31,7 +31,6 @@ __export(loadable_exports, {
|
|
|
31
31
|
createLoadableCollector: () => createLoadableCollector
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(loadable_exports);
|
|
34
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
34
|
var import_server = require("@loadable/server");
|
|
36
35
|
var import_utils = require("../utils");
|
|
37
36
|
const extname = (uri) => {
|
|
@@ -160,8 +159,6 @@ class LoadableCollector {
|
|
|
160
159
|
};
|
|
161
160
|
}
|
|
162
161
|
constructor(options) {
|
|
163
|
-
(0, import_define_property._)(this, "options", void 0);
|
|
164
|
-
(0, import_define_property._)(this, "extractor", void 0);
|
|
165
162
|
this.options = options;
|
|
166
163
|
}
|
|
167
164
|
}
|
|
@@ -31,7 +31,6 @@ __export(render_exports, {
|
|
|
31
31
|
createRender: () => createRender
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(render_exports);
|
|
34
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
34
|
var import_server = __toESM(require("react-dom/server"));
|
|
36
35
|
class Render {
|
|
37
36
|
addCollector(collector) {
|
|
@@ -45,8 +44,7 @@ class Render {
|
|
|
45
44
|
return html;
|
|
46
45
|
}
|
|
47
46
|
constructor(App) {
|
|
48
|
-
|
|
49
|
-
(0, import_define_property._)(this, "collectors", []);
|
|
47
|
+
this.collectors = [];
|
|
50
48
|
this.App = App;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
@@ -21,7 +21,6 @@ __export(styledComponent_exports, {
|
|
|
21
21
|
createStyledCollector: () => createStyledCollector
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(styledComponent_exports);
|
|
24
|
-
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
24
|
var import_styled_components = require("styled-components");
|
|
26
25
|
class StyledCollector {
|
|
27
26
|
collect(comopnent) {
|
|
@@ -32,8 +31,7 @@ class StyledCollector {
|
|
|
32
31
|
this.result.chunksMap.css += css;
|
|
33
32
|
}
|
|
34
33
|
constructor(result) {
|
|
35
|
-
|
|
36
|
-
(0, import_define_property._)(this, "result", void 0);
|
|
34
|
+
this.sheet = new import_styled_components.ServerStyleSheet();
|
|
37
35
|
this.result = result;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -3,8 +3,6 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
3
3
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
4
|
};
|
|
5
5
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
6
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
7
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
8
6
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
9
7
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
10
8
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
@@ -21,8 +19,6 @@ var require_loadable_bundler_plugin = __commonJS({
|
|
|
21
19
|
chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
|
|
22
20
|
}, _ref_filename = _ref.filename, filename = _ref_filename === void 0 ? "loadable-stats.json" : _ref_filename, path2 = _ref.path, writeToDisk = _ref.writeToDisk, _ref_outputAsset = _ref.outputAsset, outputAsset = _ref_outputAsset === void 0 ? true : _ref_outputAsset, _ref_chunkLoadingGlobal = _ref.chunkLoadingGlobal, chunkLoadingGlobal = _ref_chunkLoadingGlobal === void 0 ? "__LOADABLE_LOADED_CHUNKS__" : _ref_chunkLoadingGlobal;
|
|
23
21
|
_class_call_check(this, LoadablePlugin2);
|
|
24
|
-
_define_property(this, "opts", void 0);
|
|
25
|
-
_define_property(this, "compiler", void 0);
|
|
26
22
|
this.opts = {
|
|
27
23
|
filename,
|
|
28
24
|
path: path2,
|
|
@@ -32,82 +28,72 @@ var require_loadable_bundler_plugin = __commonJS({
|
|
|
32
28
|
};
|
|
33
29
|
this.compiler = null;
|
|
34
30
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
compilation.emitAsset(_this.opts.filename, asset);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
key: "handleEmit",
|
|
59
|
-
value: function handleEmit(compilation) {
|
|
60
|
-
var stats = compilation.getStats().toJson({
|
|
61
|
-
all: false,
|
|
62
|
-
assets: true,
|
|
63
|
-
// rspack not support cachedAssets,
|
|
64
|
-
cachedAssets: true,
|
|
65
|
-
chunks: true,
|
|
66
|
-
chunkGroups: true,
|
|
67
|
-
entrypoints: true,
|
|
68
|
-
// rspack not support chunkGroupChildren.
|
|
69
|
-
chunkGroupChildren: true,
|
|
70
|
-
hash: true,
|
|
71
|
-
ids: true,
|
|
72
|
-
outputPath: true,
|
|
73
|
-
publicPath: true
|
|
74
|
-
});
|
|
75
|
-
var output = _object_spread_props(_object_spread({}, stats), {
|
|
76
|
-
generator: "loadable-components",
|
|
77
|
-
chunks: _to_consumable_array(stats.chunks || []).map(function(chunk) {
|
|
78
|
-
return {
|
|
79
|
-
id: chunk.id,
|
|
80
|
-
files: _to_consumable_array(chunk.files || [])
|
|
81
|
-
};
|
|
82
|
-
})
|
|
31
|
+
var _proto = LoadablePlugin2.prototype;
|
|
32
|
+
_proto.apply = function apply(compiler) {
|
|
33
|
+
var _this = this;
|
|
34
|
+
this.compiler = compiler;
|
|
35
|
+
compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
|
|
36
|
+
if (this.opts.outputAsset || this.opts.writeToDisk) {
|
|
37
|
+
compiler.hooks.make.tap(LoadablePlugin2.name, function(compilation) {
|
|
38
|
+
compilation.hooks.processAssets.tap({
|
|
39
|
+
name: LoadablePlugin2.name,
|
|
40
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
41
|
+
}, function() {
|
|
42
|
+
var asset = _this.handleEmit(compilation);
|
|
43
|
+
if (asset) {
|
|
44
|
+
compilation.emitAsset(_this.opts.filename, asset);
|
|
45
|
+
}
|
|
83
46
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
_proto.handleEmit = function handleEmit(compilation) {
|
|
51
|
+
var stats = compilation.getStats().toJson({
|
|
52
|
+
all: false,
|
|
53
|
+
assets: true,
|
|
54
|
+
// rspack not support cachedAssets,
|
|
55
|
+
cachedAssets: true,
|
|
56
|
+
chunks: true,
|
|
57
|
+
chunkGroups: true,
|
|
58
|
+
entrypoints: true,
|
|
59
|
+
// rspack not support chunkGroupChildren.
|
|
60
|
+
chunkGroupChildren: true,
|
|
61
|
+
hash: true,
|
|
62
|
+
ids: true,
|
|
63
|
+
outputPath: true,
|
|
64
|
+
publicPath: true
|
|
65
|
+
});
|
|
66
|
+
var output = _object_spread_props(_object_spread({}, stats), {
|
|
67
|
+
generator: "loadable-components",
|
|
68
|
+
chunks: _to_consumable_array(stats.chunks || []).map(function(chunk) {
|
|
69
|
+
return {
|
|
70
|
+
id: chunk.id,
|
|
71
|
+
files: _to_consumable_array(chunk.files || [])
|
|
72
|
+
};
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
var result = JSON.stringify(output, null, 2);
|
|
76
|
+
if (this.opts.writeToDisk) {
|
|
77
|
+
this.writeAssetsFile(result);
|
|
78
|
+
}
|
|
79
|
+
if (this.opts.outputAsset) {
|
|
80
|
+
return {
|
|
81
|
+
source: function source() {
|
|
82
|
+
return result;
|
|
83
|
+
},
|
|
84
|
+
size: function size() {
|
|
85
|
+
return result.length;
|
|
97
86
|
}
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
key: "writeAssetsFile",
|
|
103
|
-
value: function writeAssetsFile(manifest) {
|
|
104
|
-
var _this_compiler;
|
|
105
|
-
var outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
|
|
106
|
-
var outputFile = path.resolve(outputFolder || "", this.opts.filename);
|
|
107
|
-
fs.outputFileSync(outputFile, manifest);
|
|
108
|
-
}
|
|
87
|
+
};
|
|
109
88
|
}
|
|
110
|
-
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
_proto.writeAssetsFile = function writeAssetsFile(manifest) {
|
|
92
|
+
var _this_compiler;
|
|
93
|
+
var outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
|
|
94
|
+
var outputFile = path.resolve(outputFolder || "", this.opts.filename);
|
|
95
|
+
fs.outputFileSync(outputFile, manifest);
|
|
96
|
+
};
|
|
111
97
|
return LoadablePlugin2;
|
|
112
98
|
}();
|
|
113
99
|
module.exports = LoadablePlugin;
|
package/dist/esm/ssr/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
6
6
|
import { loadableReady } from "@loadable/component";
|
|
7
7
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
8
8
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
9
|
+
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
9
10
|
import { RenderLevel } from "./serverRender/types";
|
|
10
11
|
import { WithCallback } from "./react/withCallback";
|
|
11
12
|
import { formatClient, mockResponse, isReact18 } from "./utils";
|
|
@@ -89,7 +90,7 @@ var ssr = function(config) {
|
|
|
89
90
|
});
|
|
90
91
|
ssrContext = hydrateContext.ssrContext;
|
|
91
92
|
_ssrContext_request = ssrContext.request, initialPathname = _ssrContext_request.pathname;
|
|
92
|
-
currentPathname = window.location.pathname;
|
|
93
|
+
currentPathname = normalizePathname(window.location.pathname);
|
|
93
94
|
if (initialPathname !== currentPathname) {
|
|
94
95
|
errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
|
|
95
96
|
console.error(errorMsg);
|
|
@@ -52,35 +52,28 @@ var reducePropsToState = function(propsList) {
|
|
|
52
52
|
return reduceProps;
|
|
53
53
|
};
|
|
54
54
|
function factory(Component) {
|
|
55
|
-
var _React_Component
|
|
56
|
-
var Spr = /* @__PURE__ */ function(_superClass) {
|
|
55
|
+
var Spr = /* @__PURE__ */ function(_React_Component) {
|
|
57
56
|
"use strict";
|
|
58
|
-
_inherits(Spr2,
|
|
57
|
+
_inherits(Spr2, _React_Component);
|
|
59
58
|
var _super = _create_super(Spr2);
|
|
60
59
|
function Spr2() {
|
|
61
60
|
_class_call_check(this, Spr2);
|
|
62
61
|
return _super.apply(this, arguments);
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
value: function render() {
|
|
74
|
-
var newProps = _object_spread({}, this.props);
|
|
75
|
-
var validate = this.verify();
|
|
76
|
-
if (!validate) {
|
|
77
|
-
throw new Error("invalid props, check usage");
|
|
78
|
-
}
|
|
79
|
-
console.error("[Warn] PreRender has been deprecated, please use SSR Cache instead. reference to docs: https://modernjs.dev/guides/advanced-features/ssr.html");
|
|
80
|
-
return createElement(Component, _object_spread({}, newProps));
|
|
81
|
-
}
|
|
63
|
+
var _proto = Spr2.prototype;
|
|
64
|
+
_proto.verify = function verify() {
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
_proto.render = function render() {
|
|
68
|
+
var newProps = _object_spread({}, this.props);
|
|
69
|
+
var validate = this.verify();
|
|
70
|
+
if (!validate) {
|
|
71
|
+
throw new Error("invalid props, check usage");
|
|
82
72
|
}
|
|
83
|
-
|
|
73
|
+
console.error("[Warn] PreRender has been deprecated, please use SSR Cache instead. reference to docs: https://modernjs.dev/guides/advanced-features/ssr.html");
|
|
74
|
+
return createElement(Component, _object_spread({}, newProps));
|
|
75
|
+
};
|
|
76
|
+
_create_class(Spr2, null, [
|
|
84
77
|
{
|
|
85
78
|
key: "canUseDOM",
|
|
86
79
|
get: function get() {
|
|
@@ -92,13 +85,13 @@ function factory(Component) {
|
|
|
92
85
|
}
|
|
93
86
|
]);
|
|
94
87
|
return Spr2;
|
|
95
|
-
}(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
}(React.Component);
|
|
89
|
+
Spr.peek = Component.peek;
|
|
90
|
+
Spr.rewind = Component.rewind;
|
|
91
|
+
Spr.config = function() {
|
|
99
92
|
var mappedState = Component.rewind();
|
|
100
93
|
return mappedState;
|
|
101
|
-
}
|
|
94
|
+
};
|
|
102
95
|
return Spr;
|
|
103
96
|
}
|
|
104
97
|
var NullComponent = function() {
|