@modern-js/runtime 2.48.1 → 2.48.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/ssr/index.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +2 -3
- package/dist/cjs/ssr/serverRender/renderToString/render.js +7 -3
- package/dist/esm/ssr/index.js +2 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm/ssr/serverRender/renderToString/entry.js +2 -3
- package/dist/esm/ssr/serverRender/renderToString/render.js +8 -4
- package/dist/esm-node/ssr/index.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +2 -3
- package/dist/esm-node/ssr/serverRender/renderToString/render.js +7 -3
- package/dist/types/ssr/serverRender/renderToString/render.d.ts +4 -2
- package/dist/types/ssr/serverRender/types.d.ts +2 -0
- package/package.json +10 -10
package/dist/cjs/ssr/index.js
CHANGED
|
@@ -64,8 +64,8 @@ const ssr = (config) => ({
|
|
|
64
64
|
_hydration: true
|
|
65
65
|
};
|
|
66
66
|
const { ssrContext } = hydrateContext;
|
|
67
|
-
const { pathname: initialPathname } = ssrContext.request;
|
|
68
67
|
const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
|
|
68
|
+
const initialPathname = (0, import_url.normalizePathname)(ssrContext.request.pathname);
|
|
69
69
|
if (initialPathname !== currentPathname) {
|
|
70
70
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
71
71
|
console.error(errorMsg);
|
|
@@ -55,9 +55,9 @@ const checkIsInline = (chunk, enableInline) => {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
function getHeadTemplate(beforeEntryTemplate, context, pluginConfig) {
|
|
58
|
+
const helmetData = import_react_helmet.default.renderStatic();
|
|
58
59
|
const callbacks = [
|
|
59
60
|
(headTemplate2) => {
|
|
60
|
-
const helmetData = import_react_helmet.default.renderStatic();
|
|
61
61
|
return helmetData ? (0, import_helmet.default)(headTemplate2, helmetData) : headTemplate2;
|
|
62
62
|
},
|
|
63
63
|
// @TODO: prefetch scripts of lazy component
|
|
@@ -33,7 +33,6 @@ __export(entry_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(entry_exports);
|
|
34
34
|
var import_react = __toESM(require("react"));
|
|
35
35
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
36
|
-
var import_react_helmet = __toESM(require("react-helmet"));
|
|
37
36
|
var import_time = require("@modern-js/runtime-utils/time");
|
|
38
37
|
var import_utils = require("../../../router/runtime/utils");
|
|
39
38
|
var import_helmet = __toESM(require("../helmet"));
|
|
@@ -102,7 +101,7 @@ class Entry {
|
|
|
102
101
|
(0, import_buildHtml.createReplaceHtml)(this.result.html || ""),
|
|
103
102
|
...this.htmlModifiers
|
|
104
103
|
]);
|
|
105
|
-
const helmetData =
|
|
104
|
+
const helmetData = this.result.helmet;
|
|
106
105
|
return helmetData ? (0, import_helmet.default)(html, helmetData) : html;
|
|
107
106
|
}
|
|
108
107
|
async prefetch(context) {
|
|
@@ -125,7 +124,7 @@ class Entry {
|
|
|
125
124
|
ssr: true
|
|
126
125
|
})
|
|
127
126
|
});
|
|
128
|
-
html = await (0, import_render.createRender)(App).addCollector((0, import_styledComponent.createStyledCollector)(this.result)).addCollector((0, import_loadable.createLoadableCollector)({
|
|
127
|
+
html = await (0, import_render.createRender)(App, this.result).addCollector((0, import_styledComponent.createStyledCollector)(this.result)).addCollector((0, import_loadable.createLoadableCollector)({
|
|
129
128
|
stats: ssrContext.loadableStats,
|
|
130
129
|
result: this.result,
|
|
131
130
|
entryName: this.entryName,
|
|
@@ -32,6 +32,7 @@ __export(render_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(render_exports);
|
|
34
34
|
var import_server = __toESM(require("react-dom/server"));
|
|
35
|
+
var import_react_helmet = __toESM(require("react-helmet"));
|
|
35
36
|
class Render {
|
|
36
37
|
addCollector(collector) {
|
|
37
38
|
this.collectors.push(collector);
|
|
@@ -40,16 +41,19 @@ class Render {
|
|
|
40
41
|
async finish() {
|
|
41
42
|
const App = this.collectors.reduce((pre, collector) => collector.collect(pre), this.App);
|
|
42
43
|
const html = import_server.default.renderToString(App);
|
|
44
|
+
const helmetData = import_react_helmet.default.renderStatic();
|
|
45
|
+
this.renderResult.helmet = helmetData;
|
|
43
46
|
await Promise.all(this.collectors.map((component) => component.effect()));
|
|
44
47
|
return html;
|
|
45
48
|
}
|
|
46
|
-
constructor(App) {
|
|
49
|
+
constructor(App, result) {
|
|
47
50
|
this.collectors = [];
|
|
48
51
|
this.App = App;
|
|
52
|
+
this.renderResult = result;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
function createRender(App) {
|
|
52
|
-
return new Render(App);
|
|
55
|
+
function createRender(App, result) {
|
|
56
|
+
return new Render(App, result);
|
|
53
57
|
}
|
|
54
58
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
59
|
0 && (module.exports = {
|
package/dist/esm/ssr/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var ssr = function(config) {
|
|
|
25
25
|
return {
|
|
26
26
|
client: function() {
|
|
27
27
|
var _ref = _async_to_generator(function(param) {
|
|
28
|
-
var App, context, ModernRender, ModernHydrate, _window__SSR_DATA, _window, hydrateContext, ssrContext,
|
|
28
|
+
var App, context, ModernRender, ModernHydrate, _window__SSR_DATA, _window, hydrateContext, ssrContext, currentPathname, initialPathname, errorMsg, callback, renderLevel;
|
|
29
29
|
function stringSSRHydrate() {
|
|
30
30
|
if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
|
|
31
31
|
ModernRender(/* @__PURE__ */ _jsx(App, {
|
|
@@ -89,8 +89,8 @@ var ssr = function(config) {
|
|
|
89
89
|
_hydration: true
|
|
90
90
|
});
|
|
91
91
|
ssrContext = hydrateContext.ssrContext;
|
|
92
|
-
_ssrContext_request = ssrContext.request, initialPathname = _ssrContext_request.pathname;
|
|
93
92
|
currentPathname = normalizePathname(window.location.pathname);
|
|
93
|
+
initialPathname = normalizePathname(ssrContext.request.pathname);
|
|
94
94
|
if (initialPathname !== currentPathname) {
|
|
95
95
|
errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
|
|
96
96
|
console.error(errorMsg);
|
|
@@ -51,9 +51,9 @@ var checkIsInline = function(chunk, enableInline) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
function getHeadTemplate(beforeEntryTemplate, context, pluginConfig) {
|
|
54
|
+
var helmetData = ReactHelmet.renderStatic();
|
|
54
55
|
var callbacks = [
|
|
55
56
|
function(headTemplate2) {
|
|
56
|
-
var helmetData = ReactHelmet.renderStatic();
|
|
57
57
|
return helmetData ? helmetReplace(headTemplate2, helmetData) : headTemplate2;
|
|
58
58
|
},
|
|
59
59
|
// @TODO: prefetch scripts of lazy component
|
|
@@ -5,7 +5,6 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
8
|
-
import ReactHelmet from "react-helmet";
|
|
9
8
|
import { time } from "@modern-js/runtime-utils/time";
|
|
10
9
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
11
10
|
import helmetReplace from "../helmet";
|
|
@@ -129,7 +128,7 @@ var Entry = /* @__PURE__ */ function() {
|
|
|
129
128
|
createReplaceSSRDataScript(ssrDataScripts),
|
|
130
129
|
createReplaceHtml(_this.result.html || "")
|
|
131
130
|
].concat(_to_consumable_array(_this.htmlModifiers)));
|
|
132
|
-
helmetData =
|
|
131
|
+
helmetData = _this.result.helmet;
|
|
133
132
|
return [
|
|
134
133
|
2,
|
|
135
134
|
helmetData ? helmetReplace(html, helmetData) : html
|
|
@@ -203,7 +202,7 @@ var Entry = /* @__PURE__ */ function() {
|
|
|
203
202
|
});
|
|
204
203
|
return [
|
|
205
204
|
4,
|
|
206
|
-
createRender(App).addCollector(createStyledCollector(_this.result)).addCollector(createLoadableCollector({
|
|
205
|
+
createRender(App, _this.result).addCollector(createStyledCollector(_this.result)).addCollector(createLoadableCollector({
|
|
207
206
|
stats: ssrContext.loadableStats,
|
|
208
207
|
result: _this.result,
|
|
209
208
|
entryName: _this.entryName,
|
|
@@ -2,12 +2,14 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import ReactDomServer from "react-dom/server";
|
|
5
|
+
import ReactHelmet from "react-helmet";
|
|
5
6
|
var Render = /* @__PURE__ */ function() {
|
|
6
7
|
"use strict";
|
|
7
|
-
function Render2(App) {
|
|
8
|
+
function Render2(App, result) {
|
|
8
9
|
_class_call_check(this, Render2);
|
|
9
10
|
this.collectors = [];
|
|
10
11
|
this.App = App;
|
|
12
|
+
this.renderResult = result;
|
|
11
13
|
}
|
|
12
14
|
var _proto = Render2.prototype;
|
|
13
15
|
_proto.addCollector = function addCollector(collector) {
|
|
@@ -17,7 +19,7 @@ var Render = /* @__PURE__ */ function() {
|
|
|
17
19
|
_proto.finish = function finish() {
|
|
18
20
|
var _this = this;
|
|
19
21
|
return _async_to_generator(function() {
|
|
20
|
-
var App, html;
|
|
22
|
+
var App, html, helmetData;
|
|
21
23
|
return _ts_generator(this, function(_state) {
|
|
22
24
|
switch (_state.label) {
|
|
23
25
|
case 0:
|
|
@@ -25,6 +27,8 @@ var Render = /* @__PURE__ */ function() {
|
|
|
25
27
|
return collector.collect(pre);
|
|
26
28
|
}, _this.App);
|
|
27
29
|
html = ReactDomServer.renderToString(App);
|
|
30
|
+
helmetData = ReactHelmet.renderStatic();
|
|
31
|
+
_this.renderResult.helmet = helmetData;
|
|
28
32
|
return [
|
|
29
33
|
4,
|
|
30
34
|
Promise.all(_this.collectors.map(function(component) {
|
|
@@ -43,8 +47,8 @@ var Render = /* @__PURE__ */ function() {
|
|
|
43
47
|
};
|
|
44
48
|
return Render2;
|
|
45
49
|
}();
|
|
46
|
-
function createRender(App) {
|
|
47
|
-
return new Render(App);
|
|
50
|
+
function createRender(App, result) {
|
|
51
|
+
return new Render(App, result);
|
|
48
52
|
}
|
|
49
53
|
export {
|
|
50
54
|
createRender
|
|
@@ -28,8 +28,8 @@ const ssr = (config) => ({
|
|
|
28
28
|
_hydration: true
|
|
29
29
|
};
|
|
30
30
|
const { ssrContext } = hydrateContext;
|
|
31
|
-
const { pathname: initialPathname } = ssrContext.request;
|
|
32
31
|
const currentPathname = normalizePathname(window.location.pathname);
|
|
32
|
+
const initialPathname = normalizePathname(ssrContext.request.pathname);
|
|
33
33
|
if (initialPathname !== currentPathname) {
|
|
34
34
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
35
35
|
console.error(errorMsg);
|
|
@@ -22,9 +22,9 @@ const checkIsInline = (chunk, enableInline) => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
function getHeadTemplate(beforeEntryTemplate, context, pluginConfig) {
|
|
25
|
+
const helmetData = ReactHelmet.renderStatic();
|
|
25
26
|
const callbacks = [
|
|
26
27
|
(headTemplate2) => {
|
|
27
|
-
const helmetData = ReactHelmet.renderStatic();
|
|
28
28
|
return helmetData ? helmetReplace(headTemplate2, helmetData) : headTemplate2;
|
|
29
29
|
},
|
|
30
30
|
// @TODO: prefetch scripts of lazy component
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
3
|
-
import ReactHelmet from "react-helmet";
|
|
4
3
|
import { time } from "@modern-js/runtime-utils/time";
|
|
5
4
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
6
5
|
import helmetReplace from "../helmet";
|
|
@@ -69,7 +68,7 @@ class Entry {
|
|
|
69
68
|
createReplaceHtml(this.result.html || ""),
|
|
70
69
|
...this.htmlModifiers
|
|
71
70
|
]);
|
|
72
|
-
const helmetData =
|
|
71
|
+
const helmetData = this.result.helmet;
|
|
73
72
|
return helmetData ? helmetReplace(html, helmetData) : html;
|
|
74
73
|
}
|
|
75
74
|
async prefetch(context) {
|
|
@@ -92,7 +91,7 @@ class Entry {
|
|
|
92
91
|
ssr: true
|
|
93
92
|
})
|
|
94
93
|
});
|
|
95
|
-
html = await createRender(App).addCollector(createStyledCollector(this.result)).addCollector(createLoadableCollector({
|
|
94
|
+
html = await createRender(App, this.result).addCollector(createStyledCollector(this.result)).addCollector(createLoadableCollector({
|
|
96
95
|
stats: ssrContext.loadableStats,
|
|
97
96
|
result: this.result,
|
|
98
97
|
entryName: this.entryName,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ReactDomServer from "react-dom/server";
|
|
2
|
+
import ReactHelmet from "react-helmet";
|
|
2
3
|
class Render {
|
|
3
4
|
addCollector(collector) {
|
|
4
5
|
this.collectors.push(collector);
|
|
@@ -7,16 +8,19 @@ class Render {
|
|
|
7
8
|
async finish() {
|
|
8
9
|
const App = this.collectors.reduce((pre, collector) => collector.collect(pre), this.App);
|
|
9
10
|
const html = ReactDomServer.renderToString(App);
|
|
11
|
+
const helmetData = ReactHelmet.renderStatic();
|
|
12
|
+
this.renderResult.helmet = helmetData;
|
|
10
13
|
await Promise.all(this.collectors.map((component) => component.effect()));
|
|
11
14
|
return html;
|
|
12
15
|
}
|
|
13
|
-
constructor(App) {
|
|
16
|
+
constructor(App, result) {
|
|
14
17
|
this.collectors = [];
|
|
15
18
|
this.App = App;
|
|
19
|
+
this.renderResult = result;
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
|
-
function createRender(App) {
|
|
19
|
-
return new Render(App);
|
|
22
|
+
function createRender(App, result) {
|
|
23
|
+
return new Render(App, result);
|
|
20
24
|
}
|
|
21
25
|
export {
|
|
22
26
|
createRender
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
|
+
import { RenderResult } from '../types';
|
|
2
3
|
export interface Collector {
|
|
3
4
|
collect: (comopnent: ReactElement) => ReactElement;
|
|
4
5
|
effect: () => void | Promise<void>;
|
|
5
6
|
}
|
|
6
7
|
declare class Render {
|
|
7
8
|
private App;
|
|
9
|
+
private renderResult;
|
|
8
10
|
private collectors;
|
|
9
|
-
constructor(App: ReactElement);
|
|
11
|
+
constructor(App: ReactElement, result: RenderResult);
|
|
10
12
|
addCollector(collector: Collector): this;
|
|
11
13
|
finish(): Promise<string>;
|
|
12
14
|
}
|
|
13
|
-
export declare function createRender(App: ReactElement): Render;
|
|
15
|
+
export declare function createRender(App: ReactElement, result: RenderResult): Render;
|
|
14
16
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ServerUserConfig } from '@modern-js/app-tools';
|
|
3
3
|
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
4
|
+
import type { HelmetData } from 'react-helmet';
|
|
4
5
|
import type { RuntimeContext } from '../../core';
|
|
5
6
|
import type { BuildHtmlCb } from './renderToString/buildHtml';
|
|
6
7
|
import type { SSRTracker } from './tracker';
|
|
@@ -12,6 +13,7 @@ export declare enum RenderLevel {
|
|
|
12
13
|
export type RenderResult = {
|
|
13
14
|
renderLevel: RenderLevel;
|
|
14
15
|
html?: string;
|
|
16
|
+
helmet?: HelmetData;
|
|
15
17
|
chunksMap: {
|
|
16
18
|
js: string;
|
|
17
19
|
css: string;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.48.
|
|
18
|
+
"version": "2.48.2",
|
|
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/
|
|
177
|
-
"@modern-js/
|
|
174
|
+
"@modern-js/utils": "2.48.2",
|
|
175
|
+
"@modern-js/plugin": "2.48.2",
|
|
176
|
+
"@modern-js/types": "2.48.2",
|
|
177
|
+
"@modern-js/runtime-utils": "2.48.2"
|
|
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/
|
|
199
|
-
"@modern-js/
|
|
200
|
-
"@modern-js/
|
|
201
|
-
"@scripts/
|
|
202
|
-
"@scripts/
|
|
198
|
+
"@modern-js/app-tools": "2.48.2",
|
|
199
|
+
"@modern-js/core": "2.48.2",
|
|
200
|
+
"@modern-js/server-core": "2.48.2",
|
|
201
|
+
"@scripts/jest-config": "2.48.2",
|
|
202
|
+
"@scripts/build": "2.48.2"
|
|
203
203
|
},
|
|
204
204
|
"sideEffects": false,
|
|
205
205
|
"publishConfig": {
|