@modern-js/runtime 2.5.0 → 2.6.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 +27 -0
- package/dist/cjs/cli/index.js +9 -0
- package/dist/cjs/core/app-config.js +5 -1
- package/dist/cjs/core/compatible.js +8 -7
- package/dist/cjs/core/loader/index.js +4 -0
- package/dist/cjs/core/loader/loaderManager.js +6 -0
- package/dist/cjs/core/loader/useLoader.js +4 -0
- package/dist/cjs/document/Body.js +6 -8
- package/dist/cjs/document/DocumentContext.js +4 -0
- package/dist/cjs/document/DocumentStructureContext.js +4 -0
- package/dist/cjs/document/Head.js +7 -11
- package/dist/cjs/document/Html.js +24 -22
- package/dist/cjs/document/Links.js +1 -3
- package/dist/cjs/document/Root.js +8 -14
- package/dist/cjs/document/Script.js +5 -7
- package/dist/cjs/document/Scripts.js +1 -3
- package/dist/cjs/document/cli/index.js +8 -2
- package/dist/cjs/exports/head.js +4 -0
- package/dist/cjs/exports/loadable.js +4 -0
- package/dist/cjs/exports/styled.js +4 -0
- package/dist/cjs/router/cli/index.js +3 -7
- package/dist/cjs/router/index.js +4 -0
- package/dist/cjs/router/runtime/DefaultNotFound.js +13 -10
- package/dist/cjs/router/runtime/plugin.js +5 -6
- package/dist/cjs/router/runtime/plugin.node.js +16 -9
- package/dist/cjs/router/runtime/utils.js +15 -36
- package/dist/cjs/router/runtime/withRouter.js +9 -6
- package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +4 -0
- package/dist/cjs/ssr/cli/index.js +4 -0
- package/dist/cjs/ssr/index.js +10 -24
- package/dist/cjs/ssr/index.node.js +4 -0
- package/dist/cjs/ssr/prefetch.js +3 -6
- package/dist/cjs/ssr/react/nossr/index.js +4 -0
- package/dist/cjs/ssr/react/prerender/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +10 -4
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -0
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +10 -4
- package/dist/cjs/ssr/serverRender/renderToString/index.js +4 -0
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/cjs/ssr/serverRender/time.worker.js +1 -1
- package/dist/cjs/ssr/serverRender/utils.js +1 -1
- package/dist/cjs/ssr/utils.js +16 -4
- package/dist/cjs/state/index.js +4 -0
- package/dist/cjs/state/plugins.js +4 -0
- package/dist/cjs/state/runtime/index.js +4 -0
- package/dist/cjs/state/runtime/plugin.js +5 -7
- package/dist/esm/cli/index.js +5 -1
- package/dist/esm/core/app-config.js +3 -1
- package/dist/esm/core/compatible.js +3 -1
- package/dist/esm/core/loader/loaderManager.js +3 -1
- package/dist/esm/document/cli/index.js +4 -2
- package/dist/esm/router/cli/index.js +1 -5
- package/dist/esm/ssr/prefetch.js +1 -0
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +35 -6
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
- package/dist/esm/ssr/serverRender/renderToString/entry.js +22 -6
- package/dist/esm/ssr/serverRender/time.worker.js +1 -1
- package/dist/esm/ssr/utils.js +6 -4
- package/dist/esm-node/cli/index.js +5 -0
- package/dist/esm-node/core/app-config.js +5 -1
- package/dist/esm-node/core/compatible.js +4 -7
- package/dist/esm-node/core/loader/loaderManager.js +2 -0
- package/dist/esm-node/document/Body.js +6 -8
- package/dist/esm-node/document/Head.js +7 -11
- package/dist/esm-node/document/Html.js +24 -22
- package/dist/esm-node/document/Links.js +1 -3
- package/dist/esm-node/document/Root.js +8 -14
- package/dist/esm-node/document/Script.js +5 -7
- package/dist/esm-node/document/Scripts.js +1 -3
- package/dist/esm-node/document/cli/index.js +4 -2
- package/dist/esm-node/router/cli/index.js +2 -5
- package/dist/esm-node/router/runtime/DefaultNotFound.js +13 -10
- package/dist/esm-node/router/runtime/plugin.js +1 -6
- package/dist/esm-node/router/runtime/plugin.node.js +12 -9
- package/dist/esm-node/router/runtime/utils.js +15 -36
- package/dist/esm-node/router/runtime/withRouter.js +9 -6
- package/dist/esm-node/ssr/index.js +6 -24
- package/dist/esm-node/ssr/prefetch.js +3 -6
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +6 -4
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +6 -4
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/esm-node/ssr/serverRender/time.worker.js +1 -1
- package/dist/esm-node/ssr/serverRender/utils.js +1 -1
- package/dist/esm-node/ssr/utils.js +6 -4
- package/dist/esm-node/state/runtime/plugin.js +1 -7
- package/dist/types/ssr/serverRender/renderToString/type.d.ts +1 -0
- package/package.json +11 -9
- package/dist/cjs/ssr/prefetch.worker.js +0 -67
- package/dist/cjs/ssr/serverRender/renderToStream/index.worker.js +0 -64
- package/dist/cjs/ssr/serverRender/renderToString/index.worker.js +0 -58
- package/dist/esm/ssr/prefetch.worker.js +0 -191
- package/dist/esm/ssr/serverRender/renderToStream/index.worker.js +0 -32
- package/dist/esm/ssr/serverRender/renderToString/index.worker.js +0 -167
- package/dist/esm-node/ssr/prefetch.worker.js +0 -46
- package/dist/esm-node/ssr/serverRender/renderToStream/index.worker.js +0 -35
- package/dist/esm-node/ssr/serverRender/renderToString/index.worker.js +0 -29
- package/dist/types/ssr/prefetch.worker.d.ts +0 -13
- package/dist/types/ssr/serverRender/renderToStream/index.worker.d.ts +0 -6
- package/dist/types/ssr/serverRender/renderToString/index.worker.d.ts +0 -6
|
@@ -27,22 +27,14 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
27
27
|
if (parent == null ? void 0 : parent.loading) {
|
|
28
28
|
const Loading = parent.loading;
|
|
29
29
|
if (isLoadableComponent(Component)) {
|
|
30
|
-
element = /* @__PURE__ */ jsx(Component, {
|
|
31
|
-
fallback: /* @__PURE__ */ jsx(Loading, {})
|
|
32
|
-
});
|
|
30
|
+
element = /* @__PURE__ */ jsx(Component, { fallback: /* @__PURE__ */ jsx(Loading, {}) });
|
|
33
31
|
} else {
|
|
34
|
-
element = /* @__PURE__ */ jsx(Suspense, {
|
|
35
|
-
fallback: /* @__PURE__ */ jsx(Loading, {}),
|
|
36
|
-
children: /* @__PURE__ */ jsx(Component, {})
|
|
37
|
-
});
|
|
32
|
+
element = /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Loading, {}), children: /* @__PURE__ */ jsx(Component, {}) });
|
|
38
33
|
}
|
|
39
34
|
} else if (isLoadableComponent(Component) || isRoot) {
|
|
40
35
|
element = /* @__PURE__ */ jsx(Component, {});
|
|
41
36
|
} else {
|
|
42
|
-
element = /* @__PURE__ */ jsx(Suspense, {
|
|
43
|
-
fallback: null,
|
|
44
|
-
children: /* @__PURE__ */ jsx(Component, {})
|
|
45
|
-
});
|
|
37
|
+
element = /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Component, {}) });
|
|
46
38
|
}
|
|
47
39
|
} else {
|
|
48
40
|
nestedRoute.loading = parent == null ? void 0 : parent.loading;
|
|
@@ -53,28 +45,16 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
53
45
|
const childElements = children == null ? void 0 : children.map((childRoute) => {
|
|
54
46
|
return renderNestedRoute(childRoute, nestedRoute);
|
|
55
47
|
});
|
|
56
|
-
const routeElement = index ? /* @__PURE__ */ jsx(Route, {
|
|
57
|
-
...routeProps,
|
|
58
|
-
index: true
|
|
59
|
-
}, id) : /* @__PURE__ */ jsx(Route, {
|
|
60
|
-
...routeProps,
|
|
61
|
-
index: false,
|
|
62
|
-
children: childElements
|
|
63
|
-
}, id);
|
|
48
|
+
const routeElement = index ? /* @__PURE__ */ jsx(Route, { ...routeProps, index: true }, id) : /* @__PURE__ */ jsx(Route, { ...routeProps, index: false, children: childElements }, id);
|
|
64
49
|
return routeElement;
|
|
65
50
|
};
|
|
66
51
|
function getRouteComponents(routes, globalApp) {
|
|
67
52
|
const Layout = ({ Component, ...props }) => {
|
|
68
53
|
const GlobalLayout = globalApp;
|
|
69
54
|
if (!GlobalLayout) {
|
|
70
|
-
return /* @__PURE__ */ jsx(Component, {
|
|
71
|
-
...props
|
|
72
|
-
});
|
|
55
|
+
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
73
56
|
}
|
|
74
|
-
return /* @__PURE__ */ jsx(GlobalLayout, {
|
|
75
|
-
Component,
|
|
76
|
-
...props
|
|
77
|
-
});
|
|
57
|
+
return /* @__PURE__ */ jsx(GlobalLayout, { Component, ...props });
|
|
78
58
|
};
|
|
79
59
|
const routeElements = [];
|
|
80
60
|
for (const route of routes) {
|
|
@@ -82,19 +62,18 @@ function getRouteComponents(routes, globalApp) {
|
|
|
82
62
|
const routeElement = renderNestedRoute(route);
|
|
83
63
|
routeElements.push(routeElement);
|
|
84
64
|
} else {
|
|
85
|
-
const routeElement = /* @__PURE__ */ jsx(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
const routeElement = /* @__PURE__ */ jsx(
|
|
66
|
+
Route,
|
|
67
|
+
{
|
|
68
|
+
path: route.path,
|
|
69
|
+
element: /* @__PURE__ */ jsx(Layout, { Component: route.component })
|
|
70
|
+
},
|
|
71
|
+
route.path
|
|
72
|
+
);
|
|
91
73
|
routeElements.push(routeElement);
|
|
92
74
|
}
|
|
93
75
|
}
|
|
94
|
-
routeElements.push(/* @__PURE__ */ jsx(Route, {
|
|
95
|
-
path: "*",
|
|
96
|
-
element: /* @__PURE__ */ jsx(DefaultNotFound, {})
|
|
97
|
-
}, "*"));
|
|
76
|
+
routeElements.push(/* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(DefaultNotFound, {}) }, "*"));
|
|
98
77
|
return routeElements;
|
|
99
78
|
}
|
|
100
79
|
function renderRoutes(routesConfig) {
|
|
@@ -5,12 +5,15 @@ const withRouter = (Component) => {
|
|
|
5
5
|
const location = useLocation();
|
|
6
6
|
const params = useParams();
|
|
7
7
|
const navigate = useNavigate();
|
|
8
|
-
return /* @__PURE__ */ jsx(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
return /* @__PURE__ */ jsx(
|
|
9
|
+
Component,
|
|
10
|
+
{
|
|
11
|
+
...props,
|
|
12
|
+
location,
|
|
13
|
+
params,
|
|
14
|
+
navigate
|
|
15
|
+
}
|
|
16
|
+
);
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
export {
|
|
@@ -27,51 +27,33 @@ const ssr = (config) => ({
|
|
|
27
27
|
return stringSSRHydrate();
|
|
28
28
|
function stringSSRHydrate() {
|
|
29
29
|
if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
|
|
30
|
-
ModernRender(/* @__PURE__ */ jsx(App, {
|
|
31
|
-
context
|
|
32
|
-
}));
|
|
30
|
+
ModernRender(/* @__PURE__ */ jsx(App, { context }));
|
|
33
31
|
} else if (renderLevel === RenderLevel.SERVER_RENDER) {
|
|
34
32
|
if (isReact18()) {
|
|
35
33
|
loadableReady(() => {
|
|
36
|
-
let SSRApp = () => /* @__PURE__ */ jsx(WithCallback, {
|
|
37
|
-
callback,
|
|
38
|
-
children: /* @__PURE__ */ jsx(App, {
|
|
39
|
-
context: hydrateContext
|
|
40
|
-
})
|
|
41
|
-
});
|
|
34
|
+
let SSRApp = () => /* @__PURE__ */ jsx(WithCallback, { callback, children: /* @__PURE__ */ jsx(App, { context: hydrateContext }) });
|
|
42
35
|
SSRApp = hoistNonReactStatics(SSRApp, App);
|
|
43
36
|
ModernHydrate(/* @__PURE__ */ jsx(SSRApp, {}));
|
|
44
37
|
});
|
|
45
38
|
} else {
|
|
46
39
|
loadableReady(() => {
|
|
47
|
-
ModernHydrate(/* @__PURE__ */ jsx(App, {
|
|
48
|
-
context: hydrateContext
|
|
49
|
-
}), callback);
|
|
40
|
+
ModernHydrate(/* @__PURE__ */ jsx(App, { context: hydrateContext }), callback);
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
43
|
} else {
|
|
53
44
|
console.warn(
|
|
54
45
|
`unknow render level: ${renderLevel}, execute render()`
|
|
55
46
|
);
|
|
56
|
-
ModernRender(/* @__PURE__ */ jsx(App, {
|
|
57
|
-
context
|
|
58
|
-
}));
|
|
47
|
+
ModernRender(/* @__PURE__ */ jsx(App, { context }));
|
|
59
48
|
}
|
|
60
49
|
}
|
|
61
50
|
function streamSSRHydrate() {
|
|
62
51
|
if (renderLevel === RenderLevel.SERVER_RENDER) {
|
|
63
|
-
let SSRApp = () => /* @__PURE__ */ jsx(WithCallback, {
|
|
64
|
-
callback,
|
|
65
|
-
children: /* @__PURE__ */ jsx(App, {
|
|
66
|
-
context: hydrateContext
|
|
67
|
-
})
|
|
68
|
-
});
|
|
52
|
+
let SSRApp = () => /* @__PURE__ */ jsx(WithCallback, { callback, children: /* @__PURE__ */ jsx(App, { context: hydrateContext }) });
|
|
69
53
|
SSRApp = hoistNonReactStatics(SSRApp, App);
|
|
70
54
|
ModernHydrate(/* @__PURE__ */ jsx(SSRApp, {}));
|
|
71
55
|
} else {
|
|
72
|
-
ModernRender(/* @__PURE__ */ jsx(App, {
|
|
73
|
-
context
|
|
74
|
-
}));
|
|
56
|
+
ModernRender(/* @__PURE__ */ jsx(App, { context }));
|
|
75
57
|
}
|
|
76
58
|
}
|
|
77
59
|
},
|
|
@@ -11,13 +11,9 @@ const prefetch = async (App, context) => run(context.ssrContext.request.headers,
|
|
|
11
11
|
stats: loadableStats,
|
|
12
12
|
entrypoints: [ssrContext.entryName].filter(Boolean)
|
|
13
13
|
});
|
|
14
|
-
renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ jsx(App, {
|
|
15
|
-
context
|
|
16
|
-
})));
|
|
14
|
+
renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ jsx(App, { context })));
|
|
17
15
|
} else {
|
|
18
|
-
renderToStaticMarkup(/* @__PURE__ */ jsx(App, {
|
|
19
|
-
context
|
|
20
|
-
}));
|
|
16
|
+
renderToStaticMarkup(/* @__PURE__ */ jsx(App, { context }));
|
|
21
17
|
}
|
|
22
18
|
if (!context.loaderManager.hasPendingLoaders()) {
|
|
23
19
|
return {
|
|
@@ -38,6 +34,7 @@ const prefetch = async (App, context) => run(context.ssrContext.request.headers,
|
|
|
38
34
|
loadersData,
|
|
39
35
|
initialData: context.initialData,
|
|
40
36
|
i18nData: context.__i18nData__,
|
|
37
|
+
// todo: move to plugin state
|
|
41
38
|
storeState: (_a = context == null ? void 0 : context.store) == null ? void 0 : _a.getState()
|
|
42
39
|
};
|
|
43
40
|
});
|
|
@@ -8,7 +8,10 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
8
8
|
return template.replace("<!--<?- SSRDataScript ?>-->", ssrDataScript);
|
|
9
9
|
function buildSSRDataScript() {
|
|
10
10
|
const { ssrContext, renderLevel } = options;
|
|
11
|
-
const { request } = ssrContext;
|
|
11
|
+
const { request, enableUnsafeCtx } = ssrContext;
|
|
12
|
+
const unsafeContext = {
|
|
13
|
+
headers: request.headers
|
|
14
|
+
};
|
|
12
15
|
const SSRData = {
|
|
13
16
|
context: {
|
|
14
17
|
request: {
|
|
@@ -17,8 +20,7 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
17
20
|
pathname: request.pathname,
|
|
18
21
|
host: request.host,
|
|
19
22
|
url: request.url,
|
|
20
|
-
|
|
21
|
-
cookieMap: request.cookieMap
|
|
23
|
+
...enableUnsafeCtx ? unsafeContext : {}
|
|
22
24
|
}
|
|
23
25
|
},
|
|
24
26
|
renderLevel
|
|
@@ -26,7 +28,7 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
26
28
|
return `
|
|
27
29
|
<script>window._SSR_DATA = ${serialize(SSRData, {
|
|
28
30
|
isJSON: true
|
|
29
|
-
})}
|
|
31
|
+
})}</script>
|
|
30
32
|
`;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -12,6 +12,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
12
12
|
const helmetData = ReactHelmet.renderStatic();
|
|
13
13
|
return helmetData ? helmetReplace(headTemplate2, helmetData) : headTemplate2;
|
|
14
14
|
},
|
|
15
|
+
// @TODO: prefetch scripts of lazy component
|
|
15
16
|
injectCss
|
|
16
17
|
];
|
|
17
18
|
const [headTemplate = ""] = beforeEntryTemplate.match(HEAD_REG_EXP) || [];
|
|
@@ -13,7 +13,10 @@ import { reduce } from "./reduce";
|
|
|
13
13
|
import * as loadableRenderer from "./loadable";
|
|
14
14
|
import * as styledComponentRenderer from "./styledComponent";
|
|
15
15
|
const buildTemplateData = (context, data, renderLevel) => {
|
|
16
|
-
const { request } = context;
|
|
16
|
+
const { request, enableUnsafeCtx } = context;
|
|
17
|
+
const unsafeContext = {
|
|
18
|
+
headers: request.headers
|
|
19
|
+
};
|
|
17
20
|
return {
|
|
18
21
|
data,
|
|
19
22
|
context: {
|
|
@@ -23,8 +26,7 @@ const buildTemplateData = (context, data, renderLevel) => {
|
|
|
23
26
|
pathname: request.pathname,
|
|
24
27
|
host: request.host,
|
|
25
28
|
url: request.url,
|
|
26
|
-
|
|
27
|
-
cookieMap: request.cookieMap
|
|
29
|
+
...enableUnsafeCtx ? unsafeContext : {}
|
|
28
30
|
}
|
|
29
31
|
},
|
|
30
32
|
renderLevel
|
|
@@ -138,7 +140,7 @@ class Entry {
|
|
|
138
140
|
SSRDataScript: `
|
|
139
141
|
<script>window._SSR_DATA = ${serialize(templateData, {
|
|
140
142
|
isJSON: true
|
|
141
|
-
})}
|
|
143
|
+
})}</script>
|
|
142
144
|
`
|
|
143
145
|
};
|
|
144
146
|
}
|
|
@@ -36,7 +36,7 @@ const toHtml = (jsx, renderer, next) => {
|
|
|
36
36
|
}
|
|
37
37
|
chunksMap[fileType] += `<script src="${v.url}" ${props.join(
|
|
38
38
|
" "
|
|
39
|
-
)}
|
|
39
|
+
)}></script>`;
|
|
40
40
|
} else if (fileType === "css") {
|
|
41
41
|
chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
|
|
42
42
|
}
|
|
@@ -4,7 +4,7 @@ function getLoadableScripts(extractor) {
|
|
|
4
4
|
if (!check(scripts)) {
|
|
5
5
|
return "";
|
|
6
6
|
}
|
|
7
|
-
return scripts.split("
|
|
7
|
+
return scripts.split("</script>").slice(0, 2).map((i) => `${i}</script>`).join("");
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
10
|
getLoadableScripts
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import cookieTool from "cookie";
|
|
1
2
|
const isReact18 = () => process.env.IS_REACT18 === "true";
|
|
2
3
|
const formatServer = (request) => {
|
|
3
4
|
const {
|
|
@@ -7,6 +8,7 @@ const formatServer = (request) => {
|
|
|
7
8
|
} = request.headers || {};
|
|
8
9
|
return {
|
|
9
10
|
cookie,
|
|
11
|
+
cookieMap: cookieTool.parse(cookie || "") || {},
|
|
10
12
|
userAgent,
|
|
11
13
|
referer,
|
|
12
14
|
...request
|
|
@@ -20,15 +22,15 @@ const getQuery = () => window.location.search.substring(1).split("&").reduce((re
|
|
|
20
22
|
return res;
|
|
21
23
|
}, {});
|
|
22
24
|
const formatClient = (request) => {
|
|
23
|
-
var _a
|
|
25
|
+
var _a;
|
|
24
26
|
return {
|
|
25
27
|
params: request.params || {},
|
|
26
28
|
host: request.host || location.host,
|
|
27
29
|
pathname: request.pathname || location.pathname,
|
|
28
30
|
headers: request.headers || {},
|
|
29
|
-
cookieMap:
|
|
30
|
-
cookie:
|
|
31
|
-
userAgent: ((
|
|
31
|
+
cookieMap: cookieTool.parse(document.cookie || "") || {},
|
|
32
|
+
cookie: document.cookie || "",
|
|
33
|
+
userAgent: ((_a = request.headers) == null ? void 0 : _a["user-agent"]) || navigator.userAgent,
|
|
32
34
|
referer: request.referer || document.referrer,
|
|
33
35
|
query: request.query || getQuery(),
|
|
34
36
|
url: location.href
|
|
@@ -42,13 +42,7 @@ const state = (config) => ({
|
|
|
42
42
|
hoc({ App }, next) {
|
|
43
43
|
const getStateApp = (props) => {
|
|
44
44
|
const context = useContext(RuntimeReactContext);
|
|
45
|
-
return /* @__PURE__ */ jsx(Provider, {
|
|
46
|
-
store: context.store,
|
|
47
|
-
config: storeConfig,
|
|
48
|
-
children: /* @__PURE__ */ jsx(App, {
|
|
49
|
-
...props
|
|
50
|
-
})
|
|
51
|
-
});
|
|
45
|
+
return /* @__PURE__ */ jsx(Provider, { store: context.store, config: storeConfig, children: /* @__PURE__ */ jsx(App, { ...props }) });
|
|
52
46
|
};
|
|
53
47
|
return next({
|
|
54
48
|
App: hoistNonReactStatics(getStateApp, App)
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.6.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
"@babel/core": "^7.18.0",
|
|
134
134
|
"@babel/runtime": "^7.18.0",
|
|
135
135
|
"@babel/types": "^7.18.0",
|
|
136
|
+
"cookie": "0.5.0",
|
|
136
137
|
"@loadable/babel-plugin": "^5.13.2",
|
|
137
138
|
"@loadable/component": "^5.15.0",
|
|
138
139
|
"@loadable/server": "^5.15.1",
|
|
@@ -159,15 +160,16 @@
|
|
|
159
160
|
"serialize-javascript": "^6.0.0",
|
|
160
161
|
"styled-components": "^5.3.1",
|
|
161
162
|
"esbuild": "0.15.7",
|
|
162
|
-
"@modern-js/plugin": "2.
|
|
163
|
-
"@modern-js/types": "2.
|
|
164
|
-
"@modern-js/utils": "2.
|
|
163
|
+
"@modern-js/plugin": "2.6.0",
|
|
164
|
+
"@modern-js/types": "2.6.0",
|
|
165
|
+
"@modern-js/utils": "2.6.0"
|
|
165
166
|
},
|
|
166
167
|
"peerDependencies": {
|
|
167
168
|
"react": ">=17",
|
|
168
169
|
"react-dom": ">=17"
|
|
169
170
|
},
|
|
170
171
|
"devDependencies": {
|
|
172
|
+
"@types/cookie": "0.5.1",
|
|
171
173
|
"@remix-run/web-fetch": "^4.1.3",
|
|
172
174
|
"@testing-library/react": "^13.4.0",
|
|
173
175
|
"@testing-library/react-hooks": "^8.0.1",
|
|
@@ -182,11 +184,11 @@
|
|
|
182
184
|
"react-dom": "^18",
|
|
183
185
|
"ts-jest": "^27.0.4",
|
|
184
186
|
"typescript": "^4",
|
|
185
|
-
"@modern-js/app-tools": "2.
|
|
186
|
-
"@modern-js/core": "2.
|
|
187
|
-
"@modern-js/server-core": "2.
|
|
188
|
-
"@scripts/
|
|
189
|
-
"@scripts/
|
|
187
|
+
"@modern-js/app-tools": "2.6.0",
|
|
188
|
+
"@modern-js/core": "2.6.0",
|
|
189
|
+
"@modern-js/server-core": "2.6.0",
|
|
190
|
+
"@scripts/build": "2.6.0",
|
|
191
|
+
"@scripts/jest-config": "2.6.0"
|
|
190
192
|
},
|
|
191
193
|
"sideEffects": false,
|
|
192
194
|
"modernConfig": {},
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var prefetch_worker_exports = {};
|
|
19
|
-
__export(prefetch_worker_exports, {
|
|
20
|
-
default: () => prefetch_worker_default
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(prefetch_worker_exports);
|
|
23
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
-
var import_server = require("react-dom/server");
|
|
25
|
-
var import_server2 = require("@loadable/server");
|
|
26
|
-
const prefetch = async (App, context) => {
|
|
27
|
-
var _a;
|
|
28
|
-
const { ssrContext } = context;
|
|
29
|
-
const { loadableStats } = ssrContext;
|
|
30
|
-
if (loadableStats) {
|
|
31
|
-
const extractor = new import_server2.ChunkExtractor({
|
|
32
|
-
stats: loadableStats,
|
|
33
|
-
entrypoints: [ssrContext.entryName].filter(Boolean)
|
|
34
|
-
});
|
|
35
|
-
(0, import_server.renderToStaticMarkup)(extractor.collectChunks(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
36
|
-
context
|
|
37
|
-
})));
|
|
38
|
-
} else {
|
|
39
|
-
(0, import_server.renderToStaticMarkup)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
40
|
-
context
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
if (!context.loaderManager.hasPendingLoaders()) {
|
|
44
|
-
return {
|
|
45
|
-
initialData: context.initialData,
|
|
46
|
-
i18nData: context.__i18nData__
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const loadersData = await context.loaderManager.awaitPendingLoaders();
|
|
50
|
-
Object.keys(loadersData).forEach((id) => {
|
|
51
|
-
const data = loadersData[id];
|
|
52
|
-
if (data._error) {
|
|
53
|
-
ssrContext.logger.error("App Prefetch Loader", data._error);
|
|
54
|
-
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
55
|
-
delete data._error;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
loadersData,
|
|
60
|
-
initialData: context.initialData,
|
|
61
|
-
i18nData: context.__i18nData__,
|
|
62
|
-
storeState: (_a = context == null ? void 0 : context.store) == null ? void 0 : _a.getState()
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
var prefetch_worker_default = prefetch;
|
|
66
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
-
0 && (module.exports = {});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var index_worker_exports = {};
|
|
25
|
-
__export(index_worker_exports, {
|
|
26
|
-
render: () => render
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_worker_exports);
|
|
29
|
-
var import_react = require("react");
|
|
30
|
-
var import_prerender = require("../../react/prerender");
|
|
31
|
-
var import_time = require("../time");
|
|
32
|
-
var import_renderToPipe = __toESM(require("./renderToPipe"));
|
|
33
|
-
const render = ({ App, context }) => {
|
|
34
|
-
const { ssrContext } = context;
|
|
35
|
-
if (!ssrContext) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
'The "ssrContext" must not be undefined, but received undefined'
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
const end = (0, import_time.time)();
|
|
41
|
-
const rootElement = (0, import_react.createElement)(App, {
|
|
42
|
-
context: Object.assign(context || {}, {
|
|
43
|
-
ssr: true
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
const pipe = (0, import_renderToPipe.default)(rootElement, context, {
|
|
47
|
-
onShellReady() {
|
|
48
|
-
const cacheConfig = import_prerender.PreRender.config();
|
|
49
|
-
if (cacheConfig) {
|
|
50
|
-
ssrContext.cacheConfig = cacheConfig;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
onAllReady() {
|
|
54
|
-
const cost = end();
|
|
55
|
-
ssrContext.logger.debug("App Render To HTML cost = %d ms", cost);
|
|
56
|
-
ssrContext.metrics.emitTimer("app.render.html.cost", cost);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return pipe;
|
|
60
|
-
};
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
render
|
|
64
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var index_worker_exports = {};
|
|
25
|
-
__export(index_worker_exports, {
|
|
26
|
-
render: () => render
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_worker_exports);
|
|
29
|
-
var import_prerender = require("../../react/prerender");
|
|
30
|
-
var import_time = require("../time");
|
|
31
|
-
var import_entry = __toESM(require("./entry"));
|
|
32
|
-
const render = async ({
|
|
33
|
-
App,
|
|
34
|
-
context,
|
|
35
|
-
config
|
|
36
|
-
}) => {
|
|
37
|
-
const ssrContext = context.ssrContext;
|
|
38
|
-
const entry = new import_entry.default({
|
|
39
|
-
ctx: ssrContext,
|
|
40
|
-
App,
|
|
41
|
-
config
|
|
42
|
-
});
|
|
43
|
-
entry.metrics.emitCounter("app.visit.count", 1);
|
|
44
|
-
const end = (0, import_time.time)();
|
|
45
|
-
const html = await entry.renderToHtml(context);
|
|
46
|
-
const cost = end();
|
|
47
|
-
entry.logger.info("App Render Total cost = %d ms", cost);
|
|
48
|
-
entry.metrics.emitTimer("app.render.cost", cost);
|
|
49
|
-
const cacheConfig = import_prerender.PreRender.config();
|
|
50
|
-
if (cacheConfig) {
|
|
51
|
-
context.ssrContext.cacheConfig = cacheConfig;
|
|
52
|
-
}
|
|
53
|
-
return html;
|
|
54
|
-
};
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
render
|
|
58
|
-
});
|