@modern-js/runtime 2.3.1-alpha.0 → 2.4.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/CHANGELOG.md +12 -0
- package/README.md +14 -18
- package/dist/js/modern/document/Body.js +2 -2
- package/dist/js/modern/document/{DocumentStructrueContext.js → DocumentStructureContext.js} +2 -2
- package/dist/js/modern/document/Head.js +2 -2
- package/dist/js/modern/document/Html.js +2 -2
- package/dist/js/modern/document/index.js +1 -1
- package/dist/js/modern/router/runtime/plugin.node.js +0 -12
- package/dist/js/modern/ssr/serverRender/renderToStream/renderToPipe.js +5 -3
- package/dist/js/modern/ssr/serverRender/renderToString/entry.js +1 -3
- package/dist/js/node/document/Body.js +2 -2
- package/dist/js/node/document/{DocumentStructrueContext.js → DocumentStructureContext.js} +6 -6
- package/dist/js/node/document/Head.js +2 -2
- package/dist/js/node/document/Html.js +2 -2
- package/dist/js/node/document/index.js +1 -1
- package/dist/js/node/router/runtime/plugin.node.js +0 -12
- package/dist/js/node/ssr/serverRender/renderToStream/renderToPipe.js +6 -2
- package/dist/js/node/ssr/serverRender/renderToString/entry.js +1 -3
- package/dist/js/treeshaking/document/Body.js +2 -2
- package/dist/js/treeshaking/document/{DocumentStructrueContext.js → DocumentStructureContext.js} +2 -2
- package/dist/js/treeshaking/document/Head.js +2 -2
- package/dist/js/treeshaking/document/Html.js +2 -2
- package/dist/js/treeshaking/document/index.js +1 -1
- package/dist/js/treeshaking/router/runtime/plugin.node.js +0 -9
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/renderToPipe.js +4 -1
- package/dist/js/treeshaking/ssr/serverRender/renderToString/entry.js +2 -4
- package/dist/types/document/{DocumentStructrueContext.d.ts → DocumentStructureContext.d.ts} +2 -2
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/renderToStream/renderToPipe.d.ts +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9e907ec: chore: catch react-dom/server require for react 17
|
|
8
|
+
chore: 捕获引入 react-dom/server 的逻辑,避免在 react 17 下报错
|
|
9
|
+
- Updated dependencies [98a2733]
|
|
10
|
+
- Updated dependencies [8c2db5f]
|
|
11
|
+
- @modern-js/utils@2.4.0
|
|
12
|
+
- @modern-js/plugin@2.4.0
|
|
13
|
+
- @modern-js/types@2.4.0
|
|
14
|
+
|
|
3
15
|
## 2.3.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
1
|
<p align="center">
|
|
3
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
5
7
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
<a href="https://modernjs.dev" target="blank">
|
|
9
|
-
modernjs.dev
|
|
10
|
-
</a>
|
|
11
|
-
</p>
|
|
12
|
-
<p align="center">
|
|
13
|
-
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
14
9
|
</p>
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
11
|
+
## Getting Started
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Documentation
|
|
23
16
|
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [API References](https://modernjs.dev/docs/apis)
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
27
19
|
|
|
28
20
|
## Contributing
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
DOCUMENT_CHUNKSMAP_PLACEHOLDER,
|
|
5
5
|
DOCUMENT_SSRDATASCRIPT_PLACEHOLDER
|
|
6
6
|
} from "./constants";
|
|
7
|
-
import {
|
|
7
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
8
8
|
import { DefaultRoot } from "./Root";
|
|
9
9
|
function Body(props) {
|
|
10
|
-
const { hasSetRoot } = useContext(
|
|
10
|
+
const { hasSetRoot } = useContext(DocumentStructureContext);
|
|
11
11
|
const { children } = props;
|
|
12
12
|
return /* @__PURE__ */ jsxs("body", {
|
|
13
13
|
children: [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
const
|
|
2
|
+
const DocumentStructureContext = React.createContext({
|
|
3
3
|
hasSetHead: false,
|
|
4
4
|
hasSetScripts: false,
|
|
5
5
|
hasSetBody: false,
|
|
@@ -7,5 +7,5 @@ const DocumentStructrueContext = React.createContext({
|
|
|
7
7
|
hasSetLinks: false
|
|
8
8
|
});
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
DocumentStructureContext
|
|
11
11
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
4
|
import { Scripts } from "./Scripts";
|
|
5
5
|
import { Links } from "./Links";
|
|
6
6
|
import { DOCUMENT_META_PLACEHOLDER } from "./constants";
|
|
7
7
|
function Head(props) {
|
|
8
|
-
const { hasSetScripts, hasSetLinks } = useContext(
|
|
8
|
+
const { hasSetScripts, hasSetLinks } = useContext(DocumentStructureContext);
|
|
9
9
|
const { children } = props;
|
|
10
10
|
return /* @__PURE__ */ jsxs("head", {
|
|
11
11
|
children: [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Body } from "./Body";
|
|
3
|
-
import {
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
4
|
import { Head } from "./Head";
|
|
5
5
|
function findTargetChild(tag, children) {
|
|
6
6
|
return children.find((item) => getEleType(item) === tag);
|
|
@@ -56,7 +56,7 @@ function Html(props) {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
return /* @__PURE__ */ jsx("html", {
|
|
59
|
-
children: /* @__PURE__ */ jsxs(
|
|
59
|
+
children: /* @__PURE__ */ jsxs(DocumentStructureContext.Provider, {
|
|
60
60
|
value: {
|
|
61
61
|
hasSetHead,
|
|
62
62
|
hasSetScripts,
|
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
48
48
|
import { installGlobals } from "@remix-run/node";
|
|
49
49
|
import { createRoutesFromElements } from "react-router-dom";
|
|
50
|
-
import serialize from "serialize-javascript";
|
|
51
50
|
import { RuntimeReactContext } from "../../core";
|
|
52
51
|
import { renderRoutes, urlJoin } from "./utils";
|
|
53
52
|
installGlobals();
|
|
@@ -103,17 +102,6 @@ const routerPlugin = ({
|
|
|
103
102
|
if (routerContext instanceof Response) {
|
|
104
103
|
return routerContext;
|
|
105
104
|
}
|
|
106
|
-
if (routerContext.loaderData) {
|
|
107
|
-
routerContext.loaderData = JSON.parse(
|
|
108
|
-
JSON.stringify(routerContext.loaderData),
|
|
109
|
-
(k, v) => {
|
|
110
|
-
if (typeof v === "string") {
|
|
111
|
-
return serialize(v);
|
|
112
|
-
}
|
|
113
|
-
return v;
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
105
|
const router = createStaticRouter(routes, routerContext);
|
|
118
106
|
context.router = router;
|
|
119
107
|
context.routerContext = routerContext;
|
|
@@ -18,9 +18,6 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { Transform } from "stream";
|
|
21
|
-
import {
|
|
22
|
-
renderToPipeableStream
|
|
23
|
-
} from "react-dom/server";
|
|
24
21
|
import { RenderLevel } from "../types";
|
|
25
22
|
import { getTemplates } from "./template";
|
|
26
23
|
function renderToPipe(rootElement, context, options) {
|
|
@@ -28,6 +25,11 @@ function renderToPipe(rootElement, context, options) {
|
|
|
28
25
|
const { ssrContext } = context;
|
|
29
26
|
const forUserPipe = (stream) => {
|
|
30
27
|
return new Promise((resolve) => {
|
|
28
|
+
let renderToPipeableStream;
|
|
29
|
+
try {
|
|
30
|
+
({ renderToPipeableStream } = require("react-dom/server"));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
}
|
|
31
33
|
const { pipe } = renderToPipeableStream(rootElement, __spreadProps(__spreadValues({}, options), {
|
|
32
34
|
onShellReady() {
|
|
33
35
|
var _a;
|
|
@@ -101,9 +101,7 @@ class Entry {
|
|
|
101
101
|
if (fragment.isVariable && fragment.content === "SSRDataScript") {
|
|
102
102
|
html += fragment.getValue(SSRData);
|
|
103
103
|
} else {
|
|
104
|
-
|
|
105
|
-
value = value.replace(/\\\\\\u/g, `u`);
|
|
106
|
-
html += value;
|
|
104
|
+
html += fragment.getValue(this.result);
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
const helmetData = ReactHelmet.renderStatic();
|
|
@@ -23,10 +23,10 @@ module.exports = __toCommonJS(Body_exports);
|
|
|
23
23
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
24
|
var import_react = require("react");
|
|
25
25
|
var import_constants = require("./constants");
|
|
26
|
-
var
|
|
26
|
+
var import_DocumentStructureContext = require("./DocumentStructureContext");
|
|
27
27
|
var import_Root = require("./Root");
|
|
28
28
|
function Body(props) {
|
|
29
|
-
const { hasSetRoot } = (0, import_react.useContext)(
|
|
29
|
+
const { hasSetRoot } = (0, import_react.useContext)(import_DocumentStructureContext.DocumentStructureContext);
|
|
30
30
|
const { children } = props;
|
|
31
31
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", {
|
|
32
32
|
children: [
|
|
@@ -21,13 +21,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
26
|
-
|
|
24
|
+
var DocumentStructureContext_exports = {};
|
|
25
|
+
__export(DocumentStructureContext_exports, {
|
|
26
|
+
DocumentStructureContext: () => DocumentStructureContext
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(DocumentStructureContext_exports);
|
|
29
29
|
var import_react = __toESM(require("react"));
|
|
30
|
-
const
|
|
30
|
+
const DocumentStructureContext = import_react.default.createContext({
|
|
31
31
|
hasSetHead: false,
|
|
32
32
|
hasSetScripts: false,
|
|
33
33
|
hasSetBody: false,
|
|
@@ -36,5 +36,5 @@ const DocumentStructrueContext = import_react.default.createContext({
|
|
|
36
36
|
});
|
|
37
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
38
|
0 && (module.exports = {
|
|
39
|
-
|
|
39
|
+
DocumentStructureContext
|
|
40
40
|
});
|
|
@@ -23,12 +23,12 @@ __export(Head_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(Head_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_react = require("react");
|
|
26
|
-
var
|
|
26
|
+
var import_DocumentStructureContext = require("./DocumentStructureContext");
|
|
27
27
|
var import_Scripts = require("./Scripts");
|
|
28
28
|
var import_Links = require("./Links");
|
|
29
29
|
var import_constants = require("./constants");
|
|
30
30
|
function Head(props) {
|
|
31
|
-
const { hasSetScripts, hasSetLinks } = (0, import_react.useContext)(
|
|
31
|
+
const { hasSetScripts, hasSetLinks } = (0, import_react.useContext)(import_DocumentStructureContext.DocumentStructureContext);
|
|
32
32
|
const { children } = props;
|
|
33
33
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("head", {
|
|
34
34
|
children: [
|
|
@@ -22,7 +22,7 @@ __export(Html_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(Html_exports);
|
|
23
23
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
24
|
var import_Body = require("./Body");
|
|
25
|
-
var
|
|
25
|
+
var import_DocumentStructureContext = require("./DocumentStructureContext");
|
|
26
26
|
var import_Head = require("./Head");
|
|
27
27
|
function findTargetChild(tag, children) {
|
|
28
28
|
return children.find((item) => getEleType(item) === tag);
|
|
@@ -78,7 +78,7 @@ function Html(props) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("html", {
|
|
81
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
81
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DocumentStructureContext.DocumentStructureContext.Provider, {
|
|
82
82
|
value: {
|
|
83
83
|
hasSetHead,
|
|
84
84
|
hasSetScripts,
|
|
@@ -16,7 +16,7 @@ var document_exports = {};
|
|
|
16
16
|
module.exports = __toCommonJS(document_exports);
|
|
17
17
|
__reExport(document_exports, require("./Html"), module.exports);
|
|
18
18
|
__reExport(document_exports, require("./DocumentContext"), module.exports);
|
|
19
|
-
__reExport(document_exports, require("./
|
|
19
|
+
__reExport(document_exports, require("./DocumentStructureContext"), module.exports);
|
|
20
20
|
__reExport(document_exports, require("./Head"), module.exports);
|
|
21
21
|
__reExport(document_exports, require("./Body"), module.exports);
|
|
22
22
|
__reExport(document_exports, require("./Root"), module.exports);
|
|
@@ -72,7 +72,6 @@ var import_server = require("react-router-dom/server");
|
|
|
72
72
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
73
73
|
var import_node = require("@remix-run/node");
|
|
74
74
|
var import_react_router_dom = require("react-router-dom");
|
|
75
|
-
var import_serialize_javascript = __toESM(require("serialize-javascript"));
|
|
76
75
|
var import_core = require("../../core");
|
|
77
76
|
var import_utils = require("./utils");
|
|
78
77
|
(0, import_node.installGlobals)();
|
|
@@ -128,17 +127,6 @@ const routerPlugin = ({
|
|
|
128
127
|
if (routerContext instanceof Response) {
|
|
129
128
|
return routerContext;
|
|
130
129
|
}
|
|
131
|
-
if (routerContext.loaderData) {
|
|
132
|
-
routerContext.loaderData = JSON.parse(
|
|
133
|
-
JSON.stringify(routerContext.loaderData),
|
|
134
|
-
(k, v) => {
|
|
135
|
-
if (typeof v === "string") {
|
|
136
|
-
return (0, import_serialize_javascript.default)(v);
|
|
137
|
-
}
|
|
138
|
-
return v;
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
130
|
const router = (0, import_server.createStaticRouter)(routes, routerContext);
|
|
143
131
|
context.router = router;
|
|
144
132
|
context.routerContext = routerContext;
|
|
@@ -38,7 +38,6 @@ __export(renderToPipe_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(renderToPipe_exports);
|
|
40
40
|
var import_stream = require("stream");
|
|
41
|
-
var import_server = require("react-dom/server");
|
|
42
41
|
var import_types = require("../types");
|
|
43
42
|
var import_template = require("./template");
|
|
44
43
|
function renderToPipe(rootElement, context, options) {
|
|
@@ -46,7 +45,12 @@ function renderToPipe(rootElement, context, options) {
|
|
|
46
45
|
const { ssrContext } = context;
|
|
47
46
|
const forUserPipe = (stream) => {
|
|
48
47
|
return new Promise((resolve) => {
|
|
49
|
-
|
|
48
|
+
let renderToPipeableStream;
|
|
49
|
+
try {
|
|
50
|
+
({ renderToPipeableStream } = require("react-dom/server"));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
}
|
|
53
|
+
const { pipe } = renderToPipeableStream(rootElement, __spreadProps(__spreadValues({}, options), {
|
|
50
54
|
onShellReady() {
|
|
51
55
|
var _a;
|
|
52
56
|
const { shellAfter, shellBefore } = (0, import_template.getTemplates)(
|
|
@@ -127,9 +127,7 @@ class Entry {
|
|
|
127
127
|
if (fragment.isVariable && fragment.content === "SSRDataScript") {
|
|
128
128
|
html += fragment.getValue(SSRData);
|
|
129
129
|
} else {
|
|
130
|
-
|
|
131
|
-
value = value.replace(/\\\\\\u/g, `u`);
|
|
132
|
-
html += value;
|
|
130
|
+
html += fragment.getValue(this.result);
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
const helmetData = import_react_helmet.default.renderStatic();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER } from "./constants";
|
|
4
|
-
import {
|
|
4
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
5
5
|
import { DefaultRoot } from "./Root";
|
|
6
6
|
function Body(props) {
|
|
7
|
-
var hasSetRoot = useContext(
|
|
7
|
+
var hasSetRoot = useContext(DocumentStructureContext).hasSetRoot;
|
|
8
8
|
var children = props.children;
|
|
9
9
|
return /* @__PURE__ */ jsxs("body", {
|
|
10
10
|
children: [
|
package/dist/js/treeshaking/document/{DocumentStructrueContext.js → DocumentStructureContext.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
var
|
|
2
|
+
var DocumentStructureContext = React.createContext({
|
|
3
3
|
hasSetHead: false,
|
|
4
4
|
hasSetScripts: false,
|
|
5
5
|
hasSetBody: false,
|
|
6
6
|
hasSetRoot: false,
|
|
7
7
|
hasSetLinks: false
|
|
8
8
|
});
|
|
9
|
-
export {
|
|
9
|
+
export { DocumentStructureContext };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
4
|
import { Scripts } from "./Scripts";
|
|
5
5
|
import { Links } from "./Links";
|
|
6
6
|
import { DOCUMENT_META_PLACEHOLDER } from "./constants";
|
|
7
7
|
function Head(props) {
|
|
8
|
-
var ref = useContext(
|
|
8
|
+
var ref = useContext(DocumentStructureContext), hasSetScripts = ref.hasSetScripts, hasSetLinks = ref.hasSetLinks;
|
|
9
9
|
var children = props.children;
|
|
10
10
|
return /* @__PURE__ */ jsxs("head", {
|
|
11
11
|
children: [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Body } from "./Body";
|
|
3
|
-
import {
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
4
|
import { Head } from "./Head";
|
|
5
5
|
function findTargetChild(tag, children) {
|
|
6
6
|
return children.find(function(item) {
|
|
@@ -79,7 +79,7 @@ function Html(props) {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
return /* @__PURE__ */ jsx("html", {
|
|
82
|
-
children: /* @__PURE__ */ jsxs(
|
|
82
|
+
children: /* @__PURE__ */ jsxs(DocumentStructureContext.Provider, {
|
|
83
83
|
value: {
|
|
84
84
|
hasSetHead: hasSetHead,
|
|
85
85
|
hasSetScripts: hasSetScripts,
|
|
@@ -234,7 +234,6 @@ import { createStaticRouter, StaticRouterProvider } from "react-router-dom/serve
|
|
|
234
234
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
235
235
|
import { installGlobals } from "@remix-run/node";
|
|
236
236
|
import { createRoutesFromElements } from "react-router-dom";
|
|
237
|
-
import serialize from "serialize-javascript";
|
|
238
237
|
import { RuntimeReactContext } from "../../core";
|
|
239
238
|
import { renderRoutes, urlJoin } from "./utils";
|
|
240
239
|
installGlobals();
|
|
@@ -339,14 +338,6 @@ var routerPlugin = function(param) {
|
|
|
339
338
|
routerContext
|
|
340
339
|
];
|
|
341
340
|
}
|
|
342
|
-
if (routerContext.loaderData) {
|
|
343
|
-
routerContext.loaderData = JSON.parse(JSON.stringify(routerContext.loaderData), function(k, v) {
|
|
344
|
-
if (typeof v === "string") {
|
|
345
|
-
return serialize(v);
|
|
346
|
-
}
|
|
347
|
-
return v;
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
341
|
router = createStaticRouter(routes, routerContext);
|
|
351
342
|
context.router = router;
|
|
352
343
|
context.routerContext = routerContext;
|
|
@@ -58,7 +58,6 @@ function _objectSpreadProps(target, source) {
|
|
|
58
58
|
return target;
|
|
59
59
|
}
|
|
60
60
|
import { Transform } from "stream";
|
|
61
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
62
61
|
import { RenderLevel } from "../types";
|
|
63
62
|
import { getTemplates } from "./template";
|
|
64
63
|
function renderToPipe(rootElement, context, options) {
|
|
@@ -70,6 +69,10 @@ function renderToPipe(rootElement, context, options) {
|
|
|
70
69
|
var ssrContext = context.ssrContext;
|
|
71
70
|
var forUserPipe = function(stream) {
|
|
72
71
|
return new Promise(function(resolve) {
|
|
72
|
+
var renderToPipeableStream;
|
|
73
|
+
try {
|
|
74
|
+
renderToPipeableStream = require("react-dom/server").renderToPipeableStream;
|
|
75
|
+
} catch (e) {}
|
|
73
76
|
var pipe = renderToPipeableStream(rootElement, _objectSpreadProps(_objectSpread({}, options), {
|
|
74
77
|
onShellReady: function onShellReady() {
|
|
75
78
|
var ref;
|
|
@@ -220,7 +220,7 @@ var Entry = /*#__PURE__*/ function() {
|
|
|
220
220
|
value: function renderToHtml(context) {
|
|
221
221
|
var _this = this;
|
|
222
222
|
return _asyncToGenerator(function() {
|
|
223
|
-
var ssrContext, prefetchData, html, templateData, SSRData, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, fragment,
|
|
223
|
+
var ssrContext, prefetchData, html, templateData, SSRData, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, fragment, helmetData;
|
|
224
224
|
return __generator(this, function(_state) {
|
|
225
225
|
switch(_state.label){
|
|
226
226
|
case 0:
|
|
@@ -262,9 +262,7 @@ var Entry = /*#__PURE__*/ function() {
|
|
|
262
262
|
if (fragment.isVariable && fragment.content === "SSRDataScript") {
|
|
263
263
|
html += fragment.getValue(SSRData);
|
|
264
264
|
} else {
|
|
265
|
-
|
|
266
|
-
value = value.replace(/\\\\\\u/g, "u");
|
|
267
|
-
html += value;
|
|
265
|
+
html += fragment.getValue(_this.result);
|
|
268
266
|
}
|
|
269
267
|
}
|
|
270
268
|
} catch (err) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
type
|
|
2
|
+
type DocumentStructureContextProps = {
|
|
3
3
|
hasSetHead?: boolean;
|
|
4
4
|
hasSetScripts?: boolean;
|
|
5
5
|
hasSetLinks?: boolean;
|
|
@@ -7,5 +7,5 @@ type DocumentStructrueContextProps = {
|
|
|
7
7
|
hasSetRoot?: boolean;
|
|
8
8
|
docChild?: ReactNode;
|
|
9
9
|
};
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const DocumentStructureContext: React.Context<DocumentStructureContextProps>;
|
|
11
11
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="react" />
|
|
3
3
|
import { Writable } from 'stream';
|
|
4
|
-
import { RenderToPipeableStreamOptions } from 'react-dom/server';
|
|
4
|
+
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
|
|
5
5
|
import { RuntimeContext } from '../types';
|
|
6
6
|
export type Pipe<T extends Writable> = (output: T) => Promise<T | string>;
|
|
7
7
|
declare function renderToPipe(rootElement: React.ReactElement, context: RuntimeContext, options?: RenderToPipeableStreamOptions): Pipe<Writable>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/runtime",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
6
6
|
"repository": "modern-js-dev/modern.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.4.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -131,9 +131,6 @@
|
|
|
131
131
|
"@modern-js-reduck/plugin-immutable": "^1.1.4",
|
|
132
132
|
"@modern-js-reduck/react": "^1.1.4",
|
|
133
133
|
"@modern-js-reduck/store": "^1.1.4",
|
|
134
|
-
"@modern-js/plugin": "2.3.0",
|
|
135
|
-
"@modern-js/types": "2.3.0",
|
|
136
|
-
"@modern-js/utils": "2.3.0",
|
|
137
134
|
"@remix-run/node": "^1.9.0",
|
|
138
135
|
"@remix-run/router": "^1.2.0",
|
|
139
136
|
"@types/loadable__component": "^5.13.4",
|
|
@@ -149,19 +146,17 @@
|
|
|
149
146
|
"redux-logger": "^3.0.6",
|
|
150
147
|
"serialize-javascript": "^6.0.0",
|
|
151
148
|
"styled-components": "^5.3.1",
|
|
152
|
-
"esbuild": "0.15.7"
|
|
149
|
+
"esbuild": "0.15.7",
|
|
150
|
+
"@modern-js/plugin": "2.4.0",
|
|
151
|
+
"@modern-js/types": "2.4.0",
|
|
152
|
+
"@modern-js/utils": "2.4.0"
|
|
153
153
|
},
|
|
154
154
|
"peerDependencies": {
|
|
155
155
|
"react": ">=17",
|
|
156
156
|
"react-dom": ">=17"
|
|
157
157
|
},
|
|
158
158
|
"devDependencies": {
|
|
159
|
-
"@modern-js/app-tools": "2.3.0",
|
|
160
|
-
"@modern-js/core": "2.3.0",
|
|
161
|
-
"@modern-js/server-core": "2.3.0",
|
|
162
159
|
"@remix-run/web-fetch": "^4.1.3",
|
|
163
|
-
"@scripts/build": "2.3.0",
|
|
164
|
-
"@scripts/jest-config": "2.3.0",
|
|
165
160
|
"@testing-library/react": "^13.4.0",
|
|
166
161
|
"@testing-library/react-hooks": "^8.0.1",
|
|
167
162
|
"@types/invariant": "^2.2.30",
|
|
@@ -174,7 +169,12 @@
|
|
|
174
169
|
"react": "^18",
|
|
175
170
|
"react-dom": "^18",
|
|
176
171
|
"ts-jest": "^27.0.4",
|
|
177
|
-
"typescript": "^4"
|
|
172
|
+
"typescript": "^4",
|
|
173
|
+
"@modern-js/app-tools": "2.4.0",
|
|
174
|
+
"@modern-js/core": "2.4.0",
|
|
175
|
+
"@modern-js/server-core": "2.4.0",
|
|
176
|
+
"@scripts/jest-config": "2.4.0",
|
|
177
|
+
"@scripts/build": "2.4.0"
|
|
178
178
|
},
|
|
179
179
|
"sideEffects": false,
|
|
180
180
|
"modernConfig": {},
|