@bleedingdev/modern-js-runtime 3.2.0-ultramodern.83 → 3.2.0-ultramodern.85
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/core/react/wrapper.js +9 -3
- package/dist/cjs/core/server/helmet.js +6 -0
- package/dist/cjs/core/server/stream/beforeTemplate.js +1 -12
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +1 -12
- package/dist/cjs/core/server/stream/createReadableStream.js +3 -0
- package/dist/cjs/core/server/string/index.js +8 -10
- package/dist/cjs/exports/head.js +196 -5
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +9 -8
- package/dist/esm/core/react/wrapper.mjs +9 -3
- package/dist/esm/core/server/helmet.mjs +4 -1
- package/dist/esm/core/server/stream/beforeTemplate.mjs +2 -3
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +2 -3
- package/dist/esm/core/server/stream/createReadableStream.mjs +3 -0
- package/dist/esm/core/server/string/index.mjs +9 -10
- package/dist/esm/exports/head.mjs +189 -4
- package/dist/esm/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/esm-node/core/react/wrapper.mjs +9 -3
- package/dist/esm-node/core/server/helmet.mjs +4 -1
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +2 -3
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +2 -3
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +3 -0
- package/dist/esm-node/core/server/string/index.mjs +9 -10
- package/dist/esm-node/exports/head.mjs +189 -4
- package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/types/core/context/runtime.d.ts +4 -0
- package/dist/types/core/server/helmet.d.ts +5 -3
- package/dist/types/exports/head.d.ts +10 -3
- package/package.json +10 -11
|
@@ -27,9 +27,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
wrapRuntimeContextProvider: ()=>wrapRuntimeContextProvider
|
|
28
28
|
});
|
|
29
29
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
const external_react_helmet_async_namespaceObject = require("react-helmet-async");
|
|
30
31
|
const index_js_namespaceObject = require("../context/index.js");
|
|
31
32
|
function wrapRuntimeContextProvider(App, contextValue) {
|
|
32
|
-
const { isBrowser, initialData, routes, routerFramework, context, routeManifest, routerRuntime, routerInstance, routerHydrationScript, routerMatchedRouteIds, routerServerSnapshot, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
|
|
33
|
+
const { isBrowser, initialData, routes, routerFramework, context, routeManifest, routerRuntime, routerInstance, routerHydrationScript, routerMatchedRouteIds, routerServerSnapshot, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, _helmetContext, ...rest } = contextValue;
|
|
34
|
+
const internalContextValue = contextValue;
|
|
35
|
+
internalContextValue._helmetContext ??= {};
|
|
33
36
|
const runtimeContextValue = {
|
|
34
37
|
isBrowser,
|
|
35
38
|
initialData,
|
|
@@ -39,10 +42,13 @@ function wrapRuntimeContextProvider(App, contextValue) {
|
|
|
39
42
|
...rest
|
|
40
43
|
};
|
|
41
44
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.InternalRuntimeContext.Provider, {
|
|
42
|
-
value:
|
|
45
|
+
value: internalContextValue,
|
|
43
46
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.RuntimeContext.Provider, {
|
|
44
47
|
value: runtimeContextValue,
|
|
45
|
-
children:
|
|
48
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_helmet_async_namespaceObject.HelmetProvider, {
|
|
49
|
+
context: internalContextValue._helmetContext,
|
|
50
|
+
children: App
|
|
51
|
+
})
|
|
46
52
|
})
|
|
47
53
|
});
|
|
48
54
|
}
|
|
@@ -25,6 +25,7 @@ var __webpack_exports__ = {};
|
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
createReplaceHelemt: ()=>createReplaceHelemt,
|
|
28
|
+
getHelmetData: ()=>getHelmetData,
|
|
28
29
|
helmetReplace: ()=>helmetReplace
|
|
29
30
|
});
|
|
30
31
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
@@ -34,6 +35,9 @@ const RE_BODY_ATTR = /<body[^>]*>/;
|
|
|
34
35
|
const RE_LAST_IN_HEAD = /<\/head>/;
|
|
35
36
|
const RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title>/;
|
|
36
37
|
const TEST_TITLE_CONTENT = /(?<=<title[^>]*>)([\s\S\n\r]*?)([.|\S])([\s\S\n\r]*?)(?=<\/title>)/;
|
|
38
|
+
function getHelmetData(runtimeContext) {
|
|
39
|
+
return runtimeContext._helmetContext?.helmet ?? void 0;
|
|
40
|
+
}
|
|
37
41
|
function createReplaceHelemt(helmetData) {
|
|
38
42
|
return helmetData ? (template)=>helmetReplace(template, helmetData) : (tempalte)=>tempalte;
|
|
39
43
|
}
|
|
@@ -65,9 +69,11 @@ function helmetReplace(content, helmetData) {
|
|
|
65
69
|
return (0, external_utils_js_namespaceObject.safeReplace)(result, RE_LAST_IN_HEAD, `${helmetStr}</head>`);
|
|
66
70
|
}
|
|
67
71
|
exports.createReplaceHelemt = __webpack_exports__.createReplaceHelemt;
|
|
72
|
+
exports.getHelmetData = __webpack_exports__.getHelmetData;
|
|
68
73
|
exports.helmetReplace = __webpack_exports__.helmetReplace;
|
|
69
74
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
70
75
|
"createReplaceHelemt",
|
|
76
|
+
"getHelmetData",
|
|
71
77
|
"helmetReplace"
|
|
72
78
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
73
79
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, definition)=>{
|
|
14
5
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -36,8 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
27
|
buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
|
|
37
28
|
});
|
|
38
29
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
39
|
-
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
40
|
-
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
41
30
|
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
42
31
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
43
32
|
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
@@ -57,7 +46,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
57
46
|
};
|
|
58
47
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
59
48
|
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
60
|
-
const helmetData =
|
|
49
|
+
const helmetData = (0, external_helmet_js_namespaceObject.getHelmetData)(runtimeContext);
|
|
61
50
|
const callbacks = [
|
|
62
51
|
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
63
52
|
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, definition)=>{
|
|
14
5
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -36,8 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
27
|
buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
|
|
37
28
|
});
|
|
38
29
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
39
|
-
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
40
|
-
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
41
30
|
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
42
31
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
43
32
|
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
@@ -51,7 +40,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
51
40
|
};
|
|
52
41
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
53
42
|
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
54
|
-
const helmetData =
|
|
43
|
+
const helmetData = (0, external_helmet_js_namespaceObject.getHelmetData)(runtimeContext);
|
|
55
44
|
const callbacks = [
|
|
56
45
|
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
57
46
|
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
@@ -63,11 +63,14 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
63
63
|
if (extender.modifyRootElement) processedRootElement = extender.modifyRootElement(processedRootElement);
|
|
64
64
|
});
|
|
65
65
|
const chunkVec = [];
|
|
66
|
+
let hasStartedPipe = false;
|
|
66
67
|
return new Promise((resolve)=>{
|
|
67
68
|
const { pipe: reactStreamingPipe } = renderToPipeableStream(processedRootElement, {
|
|
68
69
|
nonce: config.nonce,
|
|
69
70
|
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX,
|
|
70
71
|
[onReady] () {
|
|
72
|
+
if (hasStartedPipe) return;
|
|
73
|
+
hasStartedPipe = true;
|
|
71
74
|
let styledComponentsStyleTags = '';
|
|
72
75
|
extenders.forEach((extender)=>{
|
|
73
76
|
if (extender.getStyleTags) styledComponentsStyleTags += extender.getStyleTags();
|
|
@@ -39,8 +39,6 @@ const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
|
39
39
|
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
40
40
|
const server_namespaceObject = require("react-dom/server");
|
|
41
41
|
var server_default = /*#__PURE__*/ __webpack_require__.n(server_namespaceObject);
|
|
42
|
-
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
43
|
-
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
44
42
|
const external_constants_js_namespaceObject = require("../../constants.js");
|
|
45
43
|
const index_js_namespaceObject = require("../../context/index.js");
|
|
46
44
|
const wrapper_js_namespaceObject = require("../../react/wrapper.js");
|
|
@@ -52,12 +50,12 @@ const external_utils_js_namespaceObject = require("../utils.js");
|
|
|
52
50
|
const external_loadable_js_namespaceObject = require("./loadable.js");
|
|
53
51
|
const external_ssrData_js_namespaceObject = require("./ssrData.js");
|
|
54
52
|
const renderString = async (request, serverRoot, options)=>{
|
|
55
|
-
const { resource, runtimeContext, config, onError, onTiming } = options;
|
|
53
|
+
const { resource, runtimeContext: runtimeContext1, config, onError, onTiming } = options;
|
|
56
54
|
const tracer = {
|
|
57
55
|
onError,
|
|
58
56
|
onTiming
|
|
59
57
|
};
|
|
60
|
-
const routerContext =
|
|
58
|
+
const routerContext = runtimeContext1.routerContext;
|
|
61
59
|
const { htmlTemplate, entryName, loadableStats, routeManifest, moduleFederationCssAssets } = resource;
|
|
62
60
|
const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
63
61
|
const chunkSet = {
|
|
@@ -71,7 +69,7 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
71
69
|
stats: loadableStats,
|
|
72
70
|
nonce: config.nonce,
|
|
73
71
|
routeManifest,
|
|
74
|
-
runtimeContext,
|
|
72
|
+
runtimeContext: runtimeContext1,
|
|
75
73
|
template: htmlTemplate,
|
|
76
74
|
entryName,
|
|
77
75
|
moduleFederationCssAssets,
|
|
@@ -79,10 +77,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
79
77
|
config
|
|
80
78
|
}),
|
|
81
79
|
new external_ssrData_js_namespaceObject.SSRDataCollector({
|
|
82
|
-
runtimeContext,
|
|
80
|
+
runtimeContext: runtimeContext1,
|
|
83
81
|
request,
|
|
84
82
|
ssrConfig,
|
|
85
|
-
ssrContext:
|
|
83
|
+
ssrContext: runtimeContext1.ssrContext,
|
|
86
84
|
chunkSet,
|
|
87
85
|
routerContext,
|
|
88
86
|
nonce: config.nonce,
|
|
@@ -95,10 +93,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
95
93
|
chunkSet
|
|
96
94
|
});
|
|
97
95
|
for (const c of extraCollectors)if (c) collectors.unshift(c);
|
|
98
|
-
const rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(serverRoot, Object.assign(
|
|
96
|
+
const rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(serverRoot, Object.assign(runtimeContext1, {
|
|
99
97
|
ssr: true
|
|
100
98
|
}));
|
|
101
|
-
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors,
|
|
99
|
+
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext1.ssrContext?.htmlModifiers || [], tracer);
|
|
102
100
|
return html;
|
|
103
101
|
};
|
|
104
102
|
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }) {
|
|
@@ -111,7 +109,7 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
|
|
|
111
109
|
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
112
110
|
});
|
|
113
111
|
chunkSet.renderLevel = external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER;
|
|
114
|
-
helmetData =
|
|
112
|
+
helmetData = (0, external_helmet_js_namespaceObject.getHelmetData)(runtimeContext);
|
|
115
113
|
const cost = end();
|
|
116
114
|
onTiming(external_tracer_js_namespaceObject.SSRTimings.RENDER_HTML, cost);
|
|
117
115
|
} catch (e) {
|
package/dist/cjs/exports/head.js
CHANGED
|
@@ -34,16 +34,207 @@ var __webpack_require__ = {};
|
|
|
34
34
|
var __webpack_exports__ = {};
|
|
35
35
|
__webpack_require__.r(__webpack_exports__);
|
|
36
36
|
__webpack_require__.d(__webpack_exports__, {
|
|
37
|
-
Helmet: ()=>
|
|
38
|
-
|
|
37
|
+
Helmet: ()=>Helmet,
|
|
38
|
+
HelmetData: ()=>external_react_helmet_async_namespaceObject.HelmetData,
|
|
39
|
+
HelmetProvider: ()=>external_react_helmet_async_namespaceObject.HelmetProvider,
|
|
40
|
+
default: ()=>exports_head
|
|
39
41
|
});
|
|
40
|
-
const
|
|
41
|
-
var
|
|
42
|
-
const
|
|
42
|
+
const external_react_namespaceObject = require("react");
|
|
43
|
+
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
44
|
+
const external_react_helmet_async_namespaceObject = require("react-helmet-async");
|
|
45
|
+
const index_js_namespaceObject = require("../core/context/index.js");
|
|
46
|
+
const ATTRIBUTE_NAME_MAP = {
|
|
47
|
+
charSet: 'charset',
|
|
48
|
+
className: 'class',
|
|
49
|
+
contentEditable: 'contenteditable',
|
|
50
|
+
httpEquiv: 'http-equiv',
|
|
51
|
+
itemProp: 'itemprop',
|
|
52
|
+
tabIndex: 'tabindex'
|
|
53
|
+
};
|
|
54
|
+
const escapeHtml = (value)=>String(value).replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
55
|
+
const toHtmlAttributeName = (name)=>ATTRIBUTE_NAME_MAP[name] ?? name;
|
|
56
|
+
const attributesToString = (attributes, includeHelmetAttribute = false)=>{
|
|
57
|
+
const pairs = [];
|
|
58
|
+
if (includeHelmetAttribute) pairs.push('data-rh="true"');
|
|
59
|
+
for (const [name, value] of Object.entries(attributes ?? {})){
|
|
60
|
+
if (false === value || null == value) continue;
|
|
61
|
+
const htmlName = toHtmlAttributeName(name);
|
|
62
|
+
if (true === value) pairs.push(htmlName);
|
|
63
|
+
else pairs.push(`${htmlName}="${escapeHtml(value)}"`);
|
|
64
|
+
}
|
|
65
|
+
return pairs.join(' ');
|
|
66
|
+
};
|
|
67
|
+
const createDatum = (tagName, tags)=>({
|
|
68
|
+
toComponent: ()=>[],
|
|
69
|
+
toString: ()=>tags.map((tag)=>{
|
|
70
|
+
const attrs = attributesToString(tag, true);
|
|
71
|
+
if ("script" === tagName && 'string' == typeof tag.innerHTML) return `<script ${attrs}>${tag.innerHTML}</script>`;
|
|
72
|
+
if ('style' === tagName && 'string' == typeof tag.cssText) return `<style ${attrs}>${tag.cssText}</style>`;
|
|
73
|
+
if ("noscript" === tagName && 'string' == typeof tag.innerHTML) return `<noscript ${attrs}>${tag.innerHTML}</noscript>`;
|
|
74
|
+
return `<${tagName} ${attrs}>`;
|
|
75
|
+
}).join('')
|
|
76
|
+
});
|
|
77
|
+
const createAttributeDatum = (attributes)=>({
|
|
78
|
+
toComponent: ()=>attributes,
|
|
79
|
+
toString: ()=>attributesToString(attributes)
|
|
80
|
+
});
|
|
81
|
+
const createTitleDatum = (title, attributes)=>({
|
|
82
|
+
toComponent: ()=>[],
|
|
83
|
+
toString: ()=>{
|
|
84
|
+
if (!title) return '';
|
|
85
|
+
const attrs = attributesToString(attributes, true);
|
|
86
|
+
return `<title ${attrs}>${escapeHtml(title)}</title>`;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const createEmptyHelmetState = ()=>({
|
|
90
|
+
base: createDatum('base', []),
|
|
91
|
+
bodyAttributes: createAttributeDatum({}),
|
|
92
|
+
htmlAttributes: createAttributeDatum({}),
|
|
93
|
+
link: createDatum('link', []),
|
|
94
|
+
meta: createDatum('meta', []),
|
|
95
|
+
noscript: createDatum("noscript", []),
|
|
96
|
+
priority: createDatum('meta', []),
|
|
97
|
+
script: createDatum("script", []),
|
|
98
|
+
style: createDatum('style', []),
|
|
99
|
+
title: createTitleDatum(void 0, {})
|
|
100
|
+
});
|
|
101
|
+
const mergeAttributes = (current, next)=>({
|
|
102
|
+
...current,
|
|
103
|
+
...next ?? {}
|
|
104
|
+
});
|
|
105
|
+
const collectChildren = (children, draft)=>{
|
|
106
|
+
external_react_default().Children.forEach(children, (child)=>{
|
|
107
|
+
if (!external_react_default().isValidElement(child)) return;
|
|
108
|
+
if (child.type === external_react_default().Fragment) return void collectChildren(child.props.children, draft);
|
|
109
|
+
if ('string' != typeof child.type) return;
|
|
110
|
+
const { children: nestedChildren, ...props } = child.props;
|
|
111
|
+
if ('title' === child.type) {
|
|
112
|
+
draft.title = external_react_default().Children.toArray(nestedChildren).join('');
|
|
113
|
+
draft.titleAttributes = mergeAttributes(draft.titleAttributes, props);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if ('html' === child.type || 'body' === child.type) return;
|
|
117
|
+
if ('base' === child.type || 'link' === child.type || 'meta' === child.type || "noscript" === child.type || "script" === child.type || 'style' === child.type) {
|
|
118
|
+
const tag = {
|
|
119
|
+
...props
|
|
120
|
+
};
|
|
121
|
+
if (("script" === child.type || 'style' === child.type || "noscript" === child.type) && 'string' == typeof nestedChildren) tag['style' === child.type ? 'cssText' : 'innerHTML'] = nestedChildren;
|
|
122
|
+
draft[child.type].push(tag);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const collectHelmetProps = (current, props)=>{
|
|
127
|
+
const baseState = current ?? createEmptyHelmetState();
|
|
128
|
+
const draft = {
|
|
129
|
+
base: [
|
|
130
|
+
...props.base ? [
|
|
131
|
+
props.base
|
|
132
|
+
] : []
|
|
133
|
+
],
|
|
134
|
+
bodyAttributes: props.bodyAttributes,
|
|
135
|
+
htmlAttributes: props.htmlAttributes,
|
|
136
|
+
link: [
|
|
137
|
+
...props.link ?? []
|
|
138
|
+
],
|
|
139
|
+
meta: [
|
|
140
|
+
...props.meta ?? []
|
|
141
|
+
],
|
|
142
|
+
noscript: [
|
|
143
|
+
...props.noscript ?? []
|
|
144
|
+
],
|
|
145
|
+
script: [
|
|
146
|
+
...props.script ?? []
|
|
147
|
+
],
|
|
148
|
+
style: [
|
|
149
|
+
...props.style ?? []
|
|
150
|
+
],
|
|
151
|
+
title: 'string' == typeof props.title ? props.title : Array.isArray(props.title) ? props.title.join('') : void 0,
|
|
152
|
+
titleAttributes: props.titleAttributes ?? {}
|
|
153
|
+
};
|
|
154
|
+
collectChildren(props.children, draft);
|
|
155
|
+
const title = draft.title && props.titleTemplate ? props.titleTemplate.replaceAll('%s', draft.title) : draft.title ?? props.defaultTitle;
|
|
156
|
+
return {
|
|
157
|
+
base: createDatum('base', [
|
|
158
|
+
...baseState.__baseTags ?? [],
|
|
159
|
+
...draft.base
|
|
160
|
+
]),
|
|
161
|
+
bodyAttributes: createAttributeDatum(mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes)),
|
|
162
|
+
htmlAttributes: createAttributeDatum(mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes)),
|
|
163
|
+
link: createDatum('link', [
|
|
164
|
+
...baseState.__linkTags ?? [],
|
|
165
|
+
...draft.link
|
|
166
|
+
]),
|
|
167
|
+
meta: createDatum('meta', [
|
|
168
|
+
...baseState.__metaTags ?? [],
|
|
169
|
+
...draft.meta
|
|
170
|
+
]),
|
|
171
|
+
noscript: createDatum("noscript", [
|
|
172
|
+
...baseState.__noscriptTags ?? [],
|
|
173
|
+
...draft.noscript
|
|
174
|
+
]),
|
|
175
|
+
priority: createDatum('meta', []),
|
|
176
|
+
script: createDatum("script", [
|
|
177
|
+
...baseState.__scriptTags ?? [],
|
|
178
|
+
...draft.script
|
|
179
|
+
]),
|
|
180
|
+
style: createDatum('style', [
|
|
181
|
+
...baseState.__styleTags ?? [],
|
|
182
|
+
...draft.style
|
|
183
|
+
]),
|
|
184
|
+
title: createTitleDatum(title ?? baseState.__title, mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)),
|
|
185
|
+
__baseTags: [
|
|
186
|
+
...baseState.__baseTags ?? [],
|
|
187
|
+
...draft.base
|
|
188
|
+
],
|
|
189
|
+
__bodyAttributes: mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes),
|
|
190
|
+
__htmlAttributes: mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes),
|
|
191
|
+
__linkTags: [
|
|
192
|
+
...baseState.__linkTags ?? [],
|
|
193
|
+
...draft.link
|
|
194
|
+
],
|
|
195
|
+
__metaTags: [
|
|
196
|
+
...baseState.__metaTags ?? [],
|
|
197
|
+
...draft.meta
|
|
198
|
+
],
|
|
199
|
+
__noscriptTags: [
|
|
200
|
+
...baseState.__noscriptTags ?? [],
|
|
201
|
+
...draft.noscript
|
|
202
|
+
],
|
|
203
|
+
__scriptTags: [
|
|
204
|
+
...baseState.__scriptTags ?? [],
|
|
205
|
+
...draft.script
|
|
206
|
+
],
|
|
207
|
+
__styleTags: [
|
|
208
|
+
...baseState.__styleTags ?? [],
|
|
209
|
+
...draft.style
|
|
210
|
+
],
|
|
211
|
+
__title: title ?? baseState.__title,
|
|
212
|
+
__titleAttributes: mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
const Helmet = (props)=>{
|
|
216
|
+
const runtimeContext = external_react_default().useContext(index_js_namespaceObject.InternalRuntimeContext);
|
|
217
|
+
if (runtimeContext && !runtimeContext.isBrowser) {
|
|
218
|
+
runtimeContext._helmetContext ??= {};
|
|
219
|
+
runtimeContext._helmetContext.helmet = collectHelmetProps(runtimeContext._helmetContext.helmet ?? void 0, props);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return external_react_default().createElement(external_react_helmet_async_namespaceObject.Helmet, props);
|
|
223
|
+
};
|
|
224
|
+
const head = {
|
|
225
|
+
Helmet,
|
|
226
|
+
HelmetData: external_react_helmet_async_namespaceObject.HelmetData,
|
|
227
|
+
HelmetProvider: external_react_helmet_async_namespaceObject.HelmetProvider
|
|
228
|
+
};
|
|
229
|
+
const exports_head = head;
|
|
43
230
|
exports.Helmet = __webpack_exports__.Helmet;
|
|
231
|
+
exports.HelmetData = __webpack_exports__.HelmetData;
|
|
232
|
+
exports.HelmetProvider = __webpack_exports__.HelmetProvider;
|
|
44
233
|
exports["default"] = __webpack_exports__["default"];
|
|
45
234
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
235
|
"Helmet",
|
|
236
|
+
"HelmetData",
|
|
237
|
+
"HelmetProvider",
|
|
47
238
|
"default"
|
|
48
239
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
49
240
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -39,13 +39,11 @@ const node_namespaceObject = require("@modern-js/runtime-utils/node");
|
|
|
39
39
|
const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
40
40
|
const external_react_namespaceObject = require("react");
|
|
41
41
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const external_react_helmet_async_namespaceObject = require("react-helmet-async");
|
|
43
|
+
const helmet_js_namespaceObject = require("../../../core/server/helmet.js");
|
|
44
44
|
const utils_js_namespaceObject = require("../../../router/runtime/utils.js");
|
|
45
45
|
const external_prefetch_namespaceObject = require("../../prefetch");
|
|
46
46
|
var external_prefetch_default = /*#__PURE__*/ __webpack_require__.n(external_prefetch_namespaceObject);
|
|
47
|
-
const external_helmet_namespaceObject = require("../helmet");
|
|
48
|
-
var external_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_helmet_namespaceObject);
|
|
49
47
|
const external_tracker_namespaceObject = require("../tracker");
|
|
50
48
|
const external_types_js_namespaceObject = require("../types.js");
|
|
51
49
|
const external_utils_namespaceObject = require("../utils");
|
|
@@ -101,8 +99,8 @@ class Entry {
|
|
|
101
99
|
(0, external_buildHtml_namespaceObject.createReplaceSSRDataScript)(ssrDataScripts),
|
|
102
100
|
...this.htmlModifiers
|
|
103
101
|
]);
|
|
104
|
-
const helmetData =
|
|
105
|
-
return helmetData ?
|
|
102
|
+
const helmetData = (0, helmet_js_namespaceObject.getHelmetData)(context);
|
|
103
|
+
return helmetData ? (0, helmet_js_namespaceObject.helmetReplace)(html, helmetData) : html;
|
|
106
104
|
}
|
|
107
105
|
async prefetch(context) {
|
|
108
106
|
let prefetchData;
|
|
@@ -123,11 +121,14 @@ class Entry {
|
|
|
123
121
|
const end = (0, time_namespaceObject.time)();
|
|
124
122
|
const { ssrContext } = context;
|
|
125
123
|
try {
|
|
126
|
-
const
|
|
124
|
+
const helmetContext = context._helmetContext ??= {};
|
|
125
|
+
const App = external_react_default().createElement(external_react_helmet_async_namespaceObject.HelmetProvider, {
|
|
126
|
+
context: helmetContext
|
|
127
|
+
}, external_react_default().createElement(this.App, {
|
|
127
128
|
context: Object.assign(context, {
|
|
128
129
|
ssr: true
|
|
129
130
|
})
|
|
130
|
-
});
|
|
131
|
+
}));
|
|
131
132
|
html = await (0, external_render_namespaceObject.createRender)(App).addCollector((0, external_styledComponent_namespaceObject.createStyledCollector)(this.result)).addCollector((0, external_loadable_namespaceObject.createLoadableCollector)({
|
|
132
133
|
stats: ssrContext.loadableStats,
|
|
133
134
|
result: this.result,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { HelmetProvider } from "react-helmet-async";
|
|
2
3
|
import { InternalRuntimeContext, RuntimeContext } from "../context/index.mjs";
|
|
3
4
|
function wrapRuntimeContextProvider(App, contextValue) {
|
|
4
|
-
const { isBrowser, initialData, routes, routerFramework, context, routeManifest, routerRuntime, routerInstance, routerHydrationScript, routerMatchedRouteIds, routerServerSnapshot, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
|
|
5
|
+
const { isBrowser, initialData, routes, routerFramework, context, routeManifest, routerRuntime, routerInstance, routerHydrationScript, routerMatchedRouteIds, routerServerSnapshot, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, _helmetContext, ...rest } = contextValue;
|
|
6
|
+
const internalContextValue = contextValue;
|
|
7
|
+
internalContextValue._helmetContext ??= {};
|
|
5
8
|
const runtimeContextValue = {
|
|
6
9
|
isBrowser,
|
|
7
10
|
initialData,
|
|
@@ -11,10 +14,13 @@ function wrapRuntimeContextProvider(App, contextValue) {
|
|
|
11
14
|
...rest
|
|
12
15
|
};
|
|
13
16
|
return /*#__PURE__*/ jsx(InternalRuntimeContext.Provider, {
|
|
14
|
-
value:
|
|
17
|
+
value: internalContextValue,
|
|
15
18
|
children: /*#__PURE__*/ jsx(RuntimeContext.Provider, {
|
|
16
19
|
value: runtimeContextValue,
|
|
17
|
-
children:
|
|
20
|
+
children: /*#__PURE__*/ jsx(HelmetProvider, {
|
|
21
|
+
context: internalContextValue._helmetContext,
|
|
22
|
+
children: App
|
|
23
|
+
})
|
|
18
24
|
})
|
|
19
25
|
});
|
|
20
26
|
}
|
|
@@ -5,6 +5,9 @@ const RE_BODY_ATTR = /<body[^>]*>/;
|
|
|
5
5
|
const RE_LAST_IN_HEAD = /<\/head>/;
|
|
6
6
|
const RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title>/;
|
|
7
7
|
const TEST_TITLE_CONTENT = /(?<=<title[^>]*>)([\s\S\n\r]*?)([.|\S])([\s\S\n\r]*?)(?=<\/title>)/;
|
|
8
|
+
function getHelmetData(runtimeContext) {
|
|
9
|
+
return runtimeContext._helmetContext?.helmet ?? void 0;
|
|
10
|
+
}
|
|
8
11
|
function createReplaceHelemt(helmetData) {
|
|
9
12
|
return helmetData ? (template)=>helmetReplace(template, helmetData) : (tempalte)=>tempalte;
|
|
10
13
|
}
|
|
@@ -35,4 +38,4 @@ function helmetReplace(content, helmetData) {
|
|
|
35
38
|
].reduce((pre, cur)=>pre + (cur.length > 0 ? ` ${cur}${EOL}` : ''), '');
|
|
36
39
|
return safeReplace(result, RE_LAST_IN_HEAD, `${helmetStr}</head>`);
|
|
37
40
|
}
|
|
38
|
-
export { createReplaceHelemt, helmetReplace };
|
|
41
|
+
export { createReplaceHelemt, getHelmetData, helmetReplace };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
|
-
import react_helmet from "react-helmet";
|
|
3
2
|
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
4
3
|
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
5
4
|
import { createFederatedCssLinks } from "../federatedCss.mjs";
|
|
6
|
-
import { createReplaceHelemt } from "../helmet.mjs";
|
|
5
|
+
import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
|
|
7
6
|
import { buildHtml } from "../shared.mjs";
|
|
8
7
|
import { checkIsNode, safeReplace } from "../utils.mjs";
|
|
9
8
|
const readAsset = async (chunk)=>{
|
|
@@ -19,7 +18,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
19
18
|
};
|
|
20
19
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
21
20
|
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
22
|
-
const helmetData =
|
|
21
|
+
const helmetData = getHelmetData(runtimeContext);
|
|
23
22
|
const callbacks = [
|
|
24
23
|
createReplaceHelemt(helmetData),
|
|
25
24
|
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
|
-
import react_helmet from "react-helmet";
|
|
3
2
|
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
4
3
|
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
5
4
|
import { createFederatedCssLinks } from "../federatedCss.mjs";
|
|
6
|
-
import { createReplaceHelemt } from "../helmet.mjs";
|
|
5
|
+
import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
|
|
7
6
|
import { buildHtml } from "../shared.mjs";
|
|
8
7
|
import { safeReplace } from "../utils.mjs";
|
|
9
8
|
const checkIsInline = (chunk, enableInline)=>{
|
|
@@ -13,7 +12,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
13
12
|
};
|
|
14
13
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
15
14
|
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
16
|
-
const helmetData =
|
|
15
|
+
const helmetData = getHelmetData(runtimeContext);
|
|
17
16
|
const callbacks = [
|
|
18
17
|
createReplaceHelemt(helmetData),
|
|
19
18
|
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
@@ -35,11 +35,14 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
35
35
|
if (extender.modifyRootElement) processedRootElement = extender.modifyRootElement(processedRootElement);
|
|
36
36
|
});
|
|
37
37
|
const chunkVec = [];
|
|
38
|
+
let hasStartedPipe = false;
|
|
38
39
|
return new Promise((resolve)=>{
|
|
39
40
|
const { pipe: reactStreamingPipe } = renderToPipeableStream(processedRootElement, {
|
|
40
41
|
nonce: config.nonce,
|
|
41
42
|
identifierPrefix: SSR_HYDRATION_ID_PREFIX,
|
|
42
43
|
[onReady] () {
|
|
44
|
+
if (hasStartedPipe) return;
|
|
45
|
+
hasStartedPipe = true;
|
|
43
46
|
let styledComponentsStyleTags = '';
|
|
44
47
|
extenders.forEach((extender)=>{
|
|
45
48
|
if (extender.getStyleTags) styledComponentsStyleTags += extender.getStyleTags();
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { time } from "@modern-js/runtime-utils/time";
|
|
2
2
|
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
3
3
|
import server from "react-dom/server";
|
|
4
|
-
import react_helmet from "react-helmet";
|
|
5
4
|
import { RenderLevel } from "../../constants.mjs";
|
|
6
5
|
import { getGlobalInternalRuntimeContext } from "../../context/index.mjs";
|
|
7
6
|
import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
|
|
8
7
|
import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
|
|
9
|
-
import { createReplaceHelemt } from "../helmet.mjs";
|
|
8
|
+
import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
|
|
10
9
|
import { buildHtml } from "../shared.mjs";
|
|
11
10
|
import { SSRErrors, SSRTimings } from "../tracer.mjs";
|
|
12
11
|
import { getSSRConfigByEntry, safeReplace } from "../utils.mjs";
|
|
13
12
|
import { LoadableCollector } from "./loadable.mjs";
|
|
14
13
|
import { SSRDataCollector } from "./ssrData.mjs";
|
|
15
14
|
const renderString = async (request, serverRoot, options)=>{
|
|
16
|
-
const { resource, runtimeContext, config, onError, onTiming } = options;
|
|
15
|
+
const { resource, runtimeContext: runtimeContext1, config, onError, onTiming } = options;
|
|
17
16
|
const tracer = {
|
|
18
17
|
onError,
|
|
19
18
|
onTiming
|
|
20
19
|
};
|
|
21
|
-
const routerContext =
|
|
20
|
+
const routerContext = runtimeContext1.routerContext;
|
|
22
21
|
const { htmlTemplate, entryName, loadableStats, routeManifest, moduleFederationCssAssets } = resource;
|
|
23
22
|
const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
24
23
|
const chunkSet = {
|
|
@@ -32,7 +31,7 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
32
31
|
stats: loadableStats,
|
|
33
32
|
nonce: config.nonce,
|
|
34
33
|
routeManifest,
|
|
35
|
-
runtimeContext,
|
|
34
|
+
runtimeContext: runtimeContext1,
|
|
36
35
|
template: htmlTemplate,
|
|
37
36
|
entryName,
|
|
38
37
|
moduleFederationCssAssets,
|
|
@@ -40,10 +39,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
40
39
|
config
|
|
41
40
|
}),
|
|
42
41
|
new SSRDataCollector({
|
|
43
|
-
runtimeContext,
|
|
42
|
+
runtimeContext: runtimeContext1,
|
|
44
43
|
request,
|
|
45
44
|
ssrConfig,
|
|
46
|
-
ssrContext:
|
|
45
|
+
ssrContext: runtimeContext1.ssrContext,
|
|
47
46
|
chunkSet,
|
|
48
47
|
routerContext,
|
|
49
48
|
nonce: config.nonce,
|
|
@@ -56,10 +55,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
56
55
|
chunkSet
|
|
57
56
|
});
|
|
58
57
|
for (const c of extraCollectors)if (c) collectors.unshift(c);
|
|
59
|
-
const rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(
|
|
58
|
+
const rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext1, {
|
|
60
59
|
ssr: true
|
|
61
60
|
}));
|
|
62
|
-
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors,
|
|
61
|
+
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext1.ssrContext?.htmlModifiers || [], tracer);
|
|
63
62
|
return html;
|
|
64
63
|
};
|
|
65
64
|
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }) {
|
|
@@ -72,7 +71,7 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
|
|
|
72
71
|
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
73
72
|
});
|
|
74
73
|
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
75
|
-
helmetData =
|
|
74
|
+
helmetData = getHelmetData(runtimeContext);
|
|
76
75
|
const cost = end();
|
|
77
76
|
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
78
77
|
} catch (e) {
|