@bleedingdev/modern-js-runtime 3.2.0-ultramodern.82 → 3.2.0-ultramodern.84
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/cli/ssr/index.js +3 -14
- 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/router/runtime/tanstack/routeTree.js +10 -3
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +9 -8
- package/dist/esm/cli/ssr/index.mjs +3 -14
- 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/router/runtime/tanstack/routeTree.mjs +10 -3
- package/dist/esm/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/esm-node/cli/ssr/index.mjs +3 -14
- 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/router/runtime/tanstack/routeTree.mjs +10 -3
- 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
|
@@ -133,23 +133,12 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
133
133
|
console.warn(warningMessage);
|
|
134
134
|
}
|
|
135
135
|
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
136
|
-
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
137
136
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
138
137
|
const appContext = modernAPI.getAppContext();
|
|
139
138
|
const { appDirectory, entrypoints } = appContext;
|
|
140
|
-
const serverBundlerChain = useModuleFederationNodeOutput ? (chain)=>{
|
|
141
|
-
chain.target('async-node');
|
|
142
|
-
chain.output.module(false);
|
|
143
|
-
chain.output.chunkFormat('commonjs');
|
|
144
|
-
chain.output.chunkLoading('async-node');
|
|
145
|
-
chain.output.library({
|
|
146
|
-
...chain.output.get('library') || {},
|
|
147
|
-
type: 'commonjs-module'
|
|
148
|
-
});
|
|
149
|
-
} : void 0;
|
|
150
139
|
const useLoadablePlugin = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
151
140
|
const outputConfig = {
|
|
152
|
-
module: isServerEnvironment &&
|
|
141
|
+
module: isServerEnvironment && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
153
142
|
};
|
|
154
143
|
const useLoadableComponents = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
155
144
|
return mergeEnvironmentConfig(config, {
|
|
@@ -162,13 +151,13 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
162
151
|
},
|
|
163
152
|
output: outputConfig,
|
|
164
153
|
tools: {
|
|
165
|
-
bundlerChain:
|
|
154
|
+
bundlerChain: useLoadablePlugin ? (chain)=>{
|
|
166
155
|
chain.plugin('loadable').use(external_loadable_bundler_plugin_js_default(), [
|
|
167
156
|
{
|
|
168
157
|
filename: utils_namespaceObject.LOADABLE_STATS_FILE
|
|
169
158
|
}
|
|
170
159
|
]);
|
|
171
|
-
} : void 0
|
|
160
|
+
} : void 0,
|
|
172
161
|
swc: useLoadableComponents ? {
|
|
173
162
|
jsc: {
|
|
174
163
|
experimental: {
|
|
@@ -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', {
|
|
@@ -74,12 +74,19 @@ function isModernDeferredData(value) {
|
|
|
74
74
|
function normalizeModernLoaderResult(result) {
|
|
75
75
|
return isModernDeferredData(result) ? result.data : result;
|
|
76
76
|
}
|
|
77
|
-
function pickRouteModuleComponent(routeModule) {
|
|
77
|
+
function pickRouteModuleComponent(routeModule, seen = new Set()) {
|
|
78
78
|
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
79
79
|
if (!routeModule || 'object' != typeof routeModule) return;
|
|
80
|
+
if (seen.has(routeModule)) return;
|
|
81
|
+
seen.add(routeModule);
|
|
80
82
|
const module = routeModule;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
+
for (const candidate of [
|
|
84
|
+
module.default,
|
|
85
|
+
module.Component
|
|
86
|
+
]){
|
|
87
|
+
const component = pickRouteModuleComponent(candidate, seen);
|
|
88
|
+
if (component) return component;
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
85
92
|
if ("u" > typeof document) return fallbackComponent;
|
|
@@ -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,
|
|
@@ -92,23 +92,12 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
92
92
|
console.warn(warningMessage);
|
|
93
93
|
}
|
|
94
94
|
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
95
|
-
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
96
95
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
97
96
|
const appContext = modernAPI.getAppContext();
|
|
98
97
|
const { appDirectory, entrypoints } = appContext;
|
|
99
|
-
const serverBundlerChain = useModuleFederationNodeOutput ? (chain)=>{
|
|
100
|
-
chain.target('async-node');
|
|
101
|
-
chain.output.module(false);
|
|
102
|
-
chain.output.chunkFormat('commonjs');
|
|
103
|
-
chain.output.chunkLoading('async-node');
|
|
104
|
-
chain.output.library({
|
|
105
|
-
...chain.output.get('library') || {},
|
|
106
|
-
type: 'commonjs-module'
|
|
107
|
-
});
|
|
108
|
-
} : void 0;
|
|
109
98
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
110
99
|
const outputConfig = {
|
|
111
|
-
module: isServerEnvironment &&
|
|
100
|
+
module: isServerEnvironment && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
112
101
|
};
|
|
113
102
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
114
103
|
return mergeEnvironmentConfig(config, {
|
|
@@ -121,13 +110,13 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
121
110
|
},
|
|
122
111
|
output: outputConfig,
|
|
123
112
|
tools: {
|
|
124
|
-
bundlerChain:
|
|
113
|
+
bundlerChain: useLoadablePlugin ? (chain)=>{
|
|
125
114
|
chain.plugin('loadable').use(loadable_bundler_plugin, [
|
|
126
115
|
{
|
|
127
116
|
filename: LOADABLE_STATS_FILE
|
|
128
117
|
}
|
|
129
118
|
]);
|
|
130
|
-
} : void 0
|
|
119
|
+
} : void 0,
|
|
131
120
|
swc: useLoadableComponents ? {
|
|
132
121
|
jsc: {
|
|
133
122
|
experimental: {
|
|
@@ -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)
|