@bleedingdev/modern-js-runtime 3.2.0-ultramodern.9 → 3.2.0-ultramodern.90
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/boundary-debugger/index.js +299 -0
- package/dist/cjs/cli/ssr/index.js +5 -15
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/react/wrapper.js +9 -3
- package/dist/cjs/core/server/federatedCss.js +47 -0
- package/dist/cjs/core/server/helmet.js +8 -2
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -6
- package/dist/cjs/core/server/stream/beforeTemplate.js +13 -20
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +98 -0
- package/dist/cjs/core/server/stream/createReadableStream.js +7 -2
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +4 -2
- package/dist/cjs/core/server/stream/shared.js +3 -1
- package/dist/cjs/core/server/string/index.js +6 -6
- package/dist/cjs/core/server/string/loadable.js +33 -7
- package/dist/cjs/exports/head.js +196 -5
- package/dist/cjs/router/cli/code/tanstackTypes.js +116 -51
- package/dist/cjs/router/cli/code/templates.js +1 -8
- package/dist/cjs/router/runtime/tanstack/plugin.js +4 -5
- package/dist/cjs/router/runtime/tanstack/plugin.node.js +2 -13
- package/dist/cjs/router/runtime/tanstack/routeTree.js +47 -4
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +9 -8
- package/dist/esm/boundary-debugger/index.mjs +263 -0
- package/dist/esm/cli/ssr/index.mjs +5 -15
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/react/wrapper.mjs +9 -3
- package/dist/esm/core/server/federatedCss.mjs +13 -0
- package/dist/esm/core/server/helmet.mjs +5 -2
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +64 -0
- package/dist/esm/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm/core/server/stream/shared.mjs +3 -1
- package/dist/esm/core/server/string/index.mjs +7 -6
- package/dist/esm/core/server/string/loadable.mjs +33 -7
- package/dist/esm/exports/head.mjs +189 -4
- package/dist/esm/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm/router/cli/code/templates.mjs +1 -8
- package/dist/esm/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +47 -4
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/esm-node/boundary-debugger/index.mjs +264 -0
- package/dist/esm-node/cli/ssr/index.mjs +5 -15
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/react/wrapper.mjs +9 -3
- package/dist/esm-node/core/server/federatedCss.mjs +14 -0
- package/dist/esm-node/core/server/helmet.mjs +5 -2
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +65 -0
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm-node/core/server/stream/shared.mjs +3 -1
- package/dist/esm-node/core/server/string/index.mjs +7 -6
- package/dist/esm-node/core/server/string/loadable.mjs +33 -7
- package/dist/esm-node/exports/head.mjs +189 -4
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm-node/router/cli/code/templates.mjs +1 -8
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +47 -4
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/dist/types/core/context/runtime.d.ts +4 -0
- package/dist/types/core/server/federatedCss.d.ts +5 -0
- package/dist/types/core/server/helmet.d.ts +5 -3
- package/dist/types/core/server/stream/beforeTemplate.d.ts +1 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +10 -0
- package/dist/types/core/server/stream/shared.d.ts +8 -0
- package/dist/types/core/server/string/loadable.d.ts +4 -0
- package/dist/types/exports/head.d.ts +10 -3
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +25 -19
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
4
|
+
const queryParamName = 'modern-boundaries';
|
|
5
|
+
const boundarySelector = '[data-modern-boundary-id]';
|
|
6
|
+
const defaultLabels = {
|
|
7
|
+
cs: {
|
|
8
|
+
toggle: 'zobrazit hranice týmů'
|
|
9
|
+
},
|
|
10
|
+
en: {
|
|
11
|
+
toggle: 'show team boundaries'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const palette = [
|
|
15
|
+
'#ff5a5f',
|
|
16
|
+
'#30e27a',
|
|
17
|
+
'#f6cf45',
|
|
18
|
+
'#7c8cff',
|
|
19
|
+
'#29b6f6'
|
|
20
|
+
];
|
|
21
|
+
const readStoredEnabled = (storageKey, fallback)=>{
|
|
22
|
+
if ("u" < typeof window) return fallback;
|
|
23
|
+
try {
|
|
24
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
25
|
+
return null === stored ? fallback : 'true' === stored;
|
|
26
|
+
} catch {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
31
|
+
if ("u" < typeof window) return;
|
|
32
|
+
try {
|
|
33
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
34
|
+
} catch {}
|
|
35
|
+
};
|
|
36
|
+
const parseEnabledOverride = (value)=>{
|
|
37
|
+
if (null === value) return;
|
|
38
|
+
const normalized = value.toLowerCase();
|
|
39
|
+
if ('1' === normalized || 'true' === normalized) return true;
|
|
40
|
+
if ('0' === normalized || 'false' === normalized) return false;
|
|
41
|
+
};
|
|
42
|
+
const readQueryEnabledOverride = ()=>{
|
|
43
|
+
if ("u" < typeof window) return;
|
|
44
|
+
try {
|
|
45
|
+
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const detectLanguage = ()=>{
|
|
51
|
+
if ("u" < typeof document) return 'en';
|
|
52
|
+
const htmlLanguage = document.documentElement.lang;
|
|
53
|
+
if (htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
54
|
+
if ("u" < typeof window) return 'en';
|
|
55
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
56
|
+
};
|
|
57
|
+
const hashBoundaryId = (id)=>{
|
|
58
|
+
let hash = 0;
|
|
59
|
+
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
60
|
+
return hash;
|
|
61
|
+
};
|
|
62
|
+
const formatRectKey = (rect)=>[
|
|
63
|
+
Math.round(100 * rect.left) / 100,
|
|
64
|
+
Math.round(100 * rect.top) / 100,
|
|
65
|
+
Math.round(100 * rect.width) / 100,
|
|
66
|
+
Math.round(100 * rect.height) / 100
|
|
67
|
+
].join(':');
|
|
68
|
+
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
69
|
+
const collectBoundaryElements = (legacySelector)=>{
|
|
70
|
+
const elements = new Set();
|
|
71
|
+
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
72
|
+
if (!legacySelector) return Array.from(elements);
|
|
73
|
+
try {
|
|
74
|
+
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
75
|
+
} catch {}
|
|
76
|
+
return Array.from(elements);
|
|
77
|
+
};
|
|
78
|
+
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
79
|
+
const [mounted, setMounted] = useState(false);
|
|
80
|
+
const [enabled, setEnabled] = useState(false);
|
|
81
|
+
const [boxes, setBoxes] = useState([]);
|
|
82
|
+
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
83
|
+
entry.mfName,
|
|
84
|
+
{
|
|
85
|
+
...entry,
|
|
86
|
+
color: entry.color ?? palette[index % palette.length],
|
|
87
|
+
label: entry.label ?? entry.appId
|
|
88
|
+
}
|
|
89
|
+
])), [
|
|
90
|
+
metadata
|
|
91
|
+
]);
|
|
92
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
93
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
94
|
+
useEffect(()=>{
|
|
95
|
+
setMounted(true);
|
|
96
|
+
const queryOverride = readQueryEnabledOverride();
|
|
97
|
+
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
98
|
+
}, [
|
|
99
|
+
enabledByDefault,
|
|
100
|
+
storageKey
|
|
101
|
+
]);
|
|
102
|
+
useEffect(()=>{
|
|
103
|
+
if (!mounted) return;
|
|
104
|
+
writeStoredEnabled(storageKey, enabled);
|
|
105
|
+
}, [
|
|
106
|
+
enabled,
|
|
107
|
+
mounted,
|
|
108
|
+
storageKey
|
|
109
|
+
]);
|
|
110
|
+
useEffect(()=>{
|
|
111
|
+
if (!enabled) return void setBoxes([]);
|
|
112
|
+
const readBoxes = ()=>{
|
|
113
|
+
const seenBoxes = new Set();
|
|
114
|
+
const nextBoxes = collectBoundaryElements(legacySelector).map((element)=>{
|
|
115
|
+
const boundaryId = getBoundaryId(element);
|
|
116
|
+
if (!boundaryId) return;
|
|
117
|
+
const rect = element.getBoundingClientRect();
|
|
118
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
119
|
+
const rectKey = formatRectKey(rect);
|
|
120
|
+
const boxKey = `${boundaryId}:${rectKey}`;
|
|
121
|
+
if (seenBoxes.has(boxKey)) return;
|
|
122
|
+
seenBoxes.add(boxKey);
|
|
123
|
+
const boundary = boundaries.get(boundaryId);
|
|
124
|
+
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
125
|
+
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
126
|
+
const expose = element.dataset.modernMfExpose;
|
|
127
|
+
const detail = expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
128
|
+
const box = {
|
|
129
|
+
color,
|
|
130
|
+
height: rect.height,
|
|
131
|
+
id: boxKey,
|
|
132
|
+
label,
|
|
133
|
+
left: rect.left,
|
|
134
|
+
top: rect.top,
|
|
135
|
+
width: rect.width
|
|
136
|
+
};
|
|
137
|
+
if (detail) box.detail = detail;
|
|
138
|
+
return box;
|
|
139
|
+
}).filter((box)=>void 0 !== box);
|
|
140
|
+
setBoxes(nextBoxes);
|
|
141
|
+
};
|
|
142
|
+
readBoxes();
|
|
143
|
+
const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
144
|
+
for (const element of collectBoundaryElements(legacySelector))resizeObserver?.observe(element);
|
|
145
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
146
|
+
mutationObserver.observe(document.body, {
|
|
147
|
+
childList: true,
|
|
148
|
+
subtree: true
|
|
149
|
+
});
|
|
150
|
+
window.addEventListener('resize', readBoxes);
|
|
151
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
152
|
+
return ()=>{
|
|
153
|
+
mutationObserver.disconnect();
|
|
154
|
+
resizeObserver?.disconnect();
|
|
155
|
+
window.removeEventListener('resize', readBoxes);
|
|
156
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
157
|
+
};
|
|
158
|
+
}, [
|
|
159
|
+
boundaries,
|
|
160
|
+
enabled,
|
|
161
|
+
legacySelector
|
|
162
|
+
]);
|
|
163
|
+
if (!mounted) return null;
|
|
164
|
+
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
165
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
166
|
+
children: [
|
|
167
|
+
shouldRenderToggle ? /*#__PURE__*/ jsxs("label", {
|
|
168
|
+
style: {
|
|
169
|
+
alignItems: 'center',
|
|
170
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
171
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
172
|
+
borderRadius: 10,
|
|
173
|
+
boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
|
|
174
|
+
color: '#111827',
|
|
175
|
+
display: 'flex',
|
|
176
|
+
font: '600 13px/1.2 system-ui, sans-serif',
|
|
177
|
+
gap: 8,
|
|
178
|
+
left: 'max(12px, env(safe-area-inset-left))',
|
|
179
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
180
|
+
padding: '9px 11px',
|
|
181
|
+
position: 'fixed',
|
|
182
|
+
top: 'max(12px, env(safe-area-inset-top))',
|
|
183
|
+
zIndex: 2147483000
|
|
184
|
+
},
|
|
185
|
+
children: [
|
|
186
|
+
/*#__PURE__*/ jsx("input", {
|
|
187
|
+
checked: enabled,
|
|
188
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
189
|
+
type: "checkbox"
|
|
190
|
+
}),
|
|
191
|
+
/*#__PURE__*/ jsx("span", {
|
|
192
|
+
children: toggleLabel
|
|
193
|
+
})
|
|
194
|
+
]
|
|
195
|
+
}) : null,
|
|
196
|
+
enabled ? /*#__PURE__*/ jsx("div", {
|
|
197
|
+
"aria-hidden": "true",
|
|
198
|
+
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
199
|
+
style: {
|
|
200
|
+
border: `2px solid ${box.color}`,
|
|
201
|
+
borderRadius: 8,
|
|
202
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
203
|
+
height: box.height,
|
|
204
|
+
left: box.left,
|
|
205
|
+
pointerEvents: 'none',
|
|
206
|
+
position: 'fixed',
|
|
207
|
+
top: box.top,
|
|
208
|
+
width: box.width,
|
|
209
|
+
zIndex: 2147482999
|
|
210
|
+
},
|
|
211
|
+
children: /*#__PURE__*/ jsxs("span", {
|
|
212
|
+
style: {
|
|
213
|
+
background: box.color,
|
|
214
|
+
borderRadius: 999,
|
|
215
|
+
color: '#111827',
|
|
216
|
+
display: 'grid',
|
|
217
|
+
font: '800 11px/1.1 system-ui, sans-serif',
|
|
218
|
+
gap: 3,
|
|
219
|
+
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
220
|
+
padding: '5px 8px',
|
|
221
|
+
position: 'absolute',
|
|
222
|
+
right: 4,
|
|
223
|
+
top: 4,
|
|
224
|
+
whiteSpace: 'nowrap'
|
|
225
|
+
},
|
|
226
|
+
children: [
|
|
227
|
+
/*#__PURE__*/ jsx("span", {
|
|
228
|
+
children: box.label
|
|
229
|
+
}),
|
|
230
|
+
box.detail ? /*#__PURE__*/ jsx("span", {
|
|
231
|
+
style: {
|
|
232
|
+
font: '700 10px/1.1 system-ui, sans-serif',
|
|
233
|
+
opacity: 0.82,
|
|
234
|
+
overflow: 'hidden',
|
|
235
|
+
textOverflow: 'ellipsis'
|
|
236
|
+
},
|
|
237
|
+
children: box.detail
|
|
238
|
+
}) : null
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
}, box.id))
|
|
242
|
+
}) : null
|
|
243
|
+
]
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
247
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
248
|
+
setup: (api)=>{
|
|
249
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
250
|
+
children: [
|
|
251
|
+
/*#__PURE__*/ jsx(App, {
|
|
252
|
+
...props
|
|
253
|
+
}),
|
|
254
|
+
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
255
|
+
...options
|
|
256
|
+
})
|
|
257
|
+
]
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
262
|
+
export default boundary_debugger;
|
|
263
|
+
export { ultramodernBoundaryDebuggerPlugin };
|
|
@@ -84,30 +84,20 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
84
84
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
85
85
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
86
86
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
87
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
87
88
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
88
89
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
89
90
|
const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
|
|
90
91
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
91
92
|
console.warn(warningMessage);
|
|
92
93
|
}
|
|
93
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
94
|
-
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
94
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
95
95
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
96
96
|
const appContext = modernAPI.getAppContext();
|
|
97
97
|
const { appDirectory, entrypoints } = appContext;
|
|
98
|
-
const serverBundlerChain = useModuleFederationNodeOutput ? (chain)=>{
|
|
99
|
-
chain.target('async-node');
|
|
100
|
-
chain.output.module(false);
|
|
101
|
-
chain.output.chunkFormat('commonjs');
|
|
102
|
-
chain.output.chunkLoading('async-node');
|
|
103
|
-
chain.output.library({
|
|
104
|
-
...chain.output.get('library') || {},
|
|
105
|
-
type: 'commonjs-module'
|
|
106
|
-
});
|
|
107
|
-
} : void 0;
|
|
108
98
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
109
99
|
const outputConfig = {
|
|
110
|
-
module: isServerEnvironment &&
|
|
100
|
+
module: isServerEnvironment && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
111
101
|
};
|
|
112
102
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
113
103
|
return mergeEnvironmentConfig(config, {
|
|
@@ -120,13 +110,13 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
120
110
|
},
|
|
121
111
|
output: outputConfig,
|
|
122
112
|
tools: {
|
|
123
|
-
bundlerChain:
|
|
113
|
+
bundlerChain: useLoadablePlugin ? (chain)=>{
|
|
124
114
|
chain.plugin('loadable').use(loadable_bundler_plugin, [
|
|
125
115
|
{
|
|
126
116
|
filename: LOADABLE_STATS_FILE
|
|
127
117
|
}
|
|
128
118
|
]);
|
|
129
|
-
} : void 0
|
|
119
|
+
} : void 0,
|
|
130
120
|
swc: useLoadableComponents ? {
|
|
131
121
|
jsc: {
|
|
132
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
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { attributesToString } from "./utils.mjs";
|
|
2
|
+
const createFederatedCssLinks = (assets, options)=>{
|
|
3
|
+
if (!assets?.length) return '';
|
|
4
|
+
const seen = new Set(options.existingAssets || []);
|
|
5
|
+
const attributes = attributesToString(options.attributes || {});
|
|
6
|
+
const links = [];
|
|
7
|
+
for (const asset of assets)if (!(!asset || seen.has(asset) || options.template.includes(asset))) {
|
|
8
|
+
seen.add(asset);
|
|
9
|
+
links.push(`<link${attributes} href="${asset}" rel="stylesheet" />`);
|
|
10
|
+
}
|
|
11
|
+
return links.join('');
|
|
12
|
+
};
|
|
13
|
+
export { createFederatedCssLinks };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { EOL } from "os";
|
|
2
1
|
import { safeReplace } from "./utils.mjs";
|
|
2
|
+
const EOL = '\n';
|
|
3
3
|
const RE_HTML_ATTR = /<html[^>]*>/;
|
|
4
4
|
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,5 +1,5 @@
|
|
|
1
1
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
2
|
-
import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
|
|
2
|
+
import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
3
3
|
import { SSR_DATA_JSON_ID } from "../../constants.mjs";
|
|
4
4
|
import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
|
|
5
5
|
import { buildHtml } from "../shared.mjs";
|
|
@@ -22,12 +22,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
22
22
|
if (!routeManifest) return template;
|
|
23
23
|
const { routeAssets } = routeManifest;
|
|
24
24
|
if (!routeAssets) return template;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
26
|
+
const assetEntries = [
|
|
27
|
+
...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
|
|
28
|
+
routeAssets[`async-${entryName}`]
|
|
29
|
+
].filter(Boolean);
|
|
30
|
+
const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
|
|
31
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
|
|
32
|
+
const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
|
|
33
|
+
if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
|
|
31
34
|
return template;
|
|
32
35
|
}
|
|
33
36
|
return buildHtml(afterAppTemplate, callbacks);
|
|
@@ -1,8 +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
|
-
import {
|
|
4
|
+
import { createFederatedCssLinks } from "../federatedCss.mjs";
|
|
5
|
+
import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
|
|
6
6
|
import { buildHtml } from "../shared.mjs";
|
|
7
7
|
import { checkIsNode, safeReplace } from "../utils.mjs";
|
|
8
8
|
const readAsset = async (chunk)=>{
|
|
@@ -17,8 +17,8 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
17
17
|
return Boolean(enableInline);
|
|
18
18
|
};
|
|
19
19
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
20
|
-
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
21
|
-
const helmetData =
|
|
20
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
21
|
+
const helmetData = getHelmetData(runtimeContext);
|
|
22
22
|
const callbacks = [
|
|
23
23
|
createReplaceHelemt(helmetData),
|
|
24
24
|
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
@@ -27,33 +27,36 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
27
27
|
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
28
28
|
let css = await getCssChunks();
|
|
29
29
|
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
30
|
+
css += createFederatedCssLinks(moduleFederationCssAssets, {
|
|
31
|
+
template,
|
|
32
|
+
existingAssets: css.match(/href="([^"]+)"/g)?.map((item)=>item.replace(/^href="/, '').replace(/"$/, ''))
|
|
33
|
+
});
|
|
30
34
|
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
31
35
|
async function getCssChunks() {
|
|
32
36
|
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
33
37
|
if (!routeManifest) return '';
|
|
34
38
|
const { routeAssets } = routeManifest;
|
|
35
|
-
let matchedRouteManifests;
|
|
39
|
+
let matchedRouteManifests = [];
|
|
36
40
|
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
37
41
|
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
38
|
-
else {
|
|
39
|
-
if (!routerContext || !routes) return '';
|
|
42
|
+
else if (routerContext && routes) {
|
|
40
43
|
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
41
44
|
matchedRouteManifests = matches?.map((match, index)=>{
|
|
42
45
|
if (!index) return;
|
|
43
46
|
const routeId = match.route.id;
|
|
44
47
|
if (routeId) return routeAssets[routeId];
|
|
45
|
-
}).filter(Boolean);
|
|
48
|
+
}).filter(Boolean) ?? [];
|
|
46
49
|
}
|
|
47
50
|
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
48
|
-
if (asyncEntry) matchedRouteManifests
|
|
49
|
-
const cssChunks = matchedRouteManifests
|
|
51
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
52
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
50
53
|
const { referenceCssAssets = [] } = routeManifest;
|
|
51
54
|
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
52
55
|
return [
|
|
53
56
|
...chunks,
|
|
54
57
|
..._cssChunks
|
|
55
58
|
];
|
|
56
|
-
}, [])
|
|
59
|
+
}, []);
|
|
57
60
|
const { inlineStyles } = config;
|
|
58
61
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
59
62
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
3
|
+
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
4
|
+
import { createFederatedCssLinks } from "../federatedCss.mjs";
|
|
5
|
+
import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
|
|
6
|
+
import { buildHtml } from "../shared.mjs";
|
|
7
|
+
import { safeReplace } from "../utils.mjs";
|
|
8
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
9
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
10
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
11
|
+
return Boolean(enableInline);
|
|
12
|
+
};
|
|
13
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
14
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
15
|
+
const helmetData = getHelmetData(runtimeContext);
|
|
16
|
+
const callbacks = [
|
|
17
|
+
createReplaceHelemt(helmetData),
|
|
18
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
19
|
+
];
|
|
20
|
+
return buildHtml(beforeAppTemplate, callbacks);
|
|
21
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
22
|
+
let css = await getCssChunks();
|
|
23
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
24
|
+
css += createFederatedCssLinks(moduleFederationCssAssets, {
|
|
25
|
+
template,
|
|
26
|
+
existingAssets: css.match(/href="([^"]+)"/g)?.map((item)=>item.replace(/^href="/, '').replace(/"$/, ''))
|
|
27
|
+
});
|
|
28
|
+
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
29
|
+
async function getCssChunks() {
|
|
30
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
31
|
+
if (!routeManifest) return '';
|
|
32
|
+
const { routeAssets } = routeManifest;
|
|
33
|
+
let matchedRouteManifests = [];
|
|
34
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
35
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
36
|
+
else if (routerContext && routes) {
|
|
37
|
+
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
38
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
39
|
+
if (!index) return;
|
|
40
|
+
const routeId = match.route.id;
|
|
41
|
+
if (routeId) return routeAssets[routeId];
|
|
42
|
+
}).filter(Boolean) ?? [];
|
|
43
|
+
}
|
|
44
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
45
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
46
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
47
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
48
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
49
|
+
return [
|
|
50
|
+
...chunks,
|
|
51
|
+
..._cssChunks
|
|
52
|
+
];
|
|
53
|
+
}, []);
|
|
54
|
+
const { inlineStyles } = config;
|
|
55
|
+
const styles = cssChunks.map((chunk)=>{
|
|
56
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
57
|
+
checkIsInline(chunk, inlineStyles);
|
|
58
|
+
return link;
|
|
59
|
+
});
|
|
60
|
+
return `${styles.join('')}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export { buildShellBeforeTemplate };
|
|
@@ -15,7 +15,7 @@ const defaultExtender = {
|
|
|
15
15
|
};
|
|
16
16
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
17
17
|
const { renderToPipeableStream } = await import("react-dom/server");
|
|
18
|
-
const { runtimeContext, htmlTemplate, config, ssrConfig, entryName } = options;
|
|
18
|
+
const { runtimeContext, htmlTemplate, config, ssrConfig, entryName, moduleFederationCssAssets } = options;
|
|
19
19
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
20
20
|
let renderLevel = RenderLevel.SERVER_RENDER;
|
|
21
21
|
const forceStream2String = Boolean(process.env.MODERN_JS_STREAM_TO_STRING);
|
|
@@ -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();
|
|
@@ -52,6 +55,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
52
55
|
runtimeContext,
|
|
53
56
|
config,
|
|
54
57
|
entryName,
|
|
58
|
+
moduleFederationCssAssets,
|
|
55
59
|
styledComponentsStyleTags
|
|
56
60
|
}).then(({ shellAfter, shellBefore })=>{
|
|
57
61
|
const pendingScripts = [];
|
|
@@ -109,7 +113,8 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
109
113
|
renderLevel,
|
|
110
114
|
runtimeContext,
|
|
111
115
|
entryName,
|
|
112
|
-
config
|
|
116
|
+
config,
|
|
117
|
+
moduleFederationCssAssets
|
|
113
118
|
}).then(({ shellAfter, shellBefore })=>{
|
|
114
119
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
115
120
|
const readableStream = getReadableStreamFromString(fallbackHtml);
|
|
@@ -8,19 +8,21 @@ import { getTemplates } from "./template.mjs";
|
|
|
8
8
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
9
9
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
10
10
|
const chunkVec = [];
|
|
11
|
-
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscRoot } = options;
|
|
11
|
+
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, moduleFederationCssAssets, rscManifest, rscRoot } = options;
|
|
12
12
|
const { shellBefore, shellAfter } = await getTemplates(htmlTemplate, {
|
|
13
13
|
renderLevel: RenderLevel.SERVER_RENDER,
|
|
14
14
|
runtimeContext,
|
|
15
15
|
ssrConfig,
|
|
16
16
|
request,
|
|
17
17
|
config,
|
|
18
|
-
entryName
|
|
18
|
+
entryName,
|
|
19
|
+
moduleFederationCssAssets
|
|
19
20
|
});
|
|
20
21
|
try {
|
|
21
22
|
const readableOriginal = await renderSSRStream(rootElement, {
|
|
22
23
|
request,
|
|
23
24
|
nonce: config.nonce,
|
|
25
|
+
rscManifest,
|
|
24
26
|
rscRoot: rscRoot,
|
|
25
27
|
routes: runtimeContext.routes,
|
|
26
28
|
onError (error) {
|
|
@@ -63,7 +63,7 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
63
63
|
const end = time();
|
|
64
64
|
const { runtimeContext, config, resource } = options;
|
|
65
65
|
const { onError, onTiming } = options;
|
|
66
|
-
const { htmlTemplate, entryName } = resource;
|
|
66
|
+
const { htmlTemplate, entryName, moduleFederationCssAssets } = resource;
|
|
67
67
|
const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
68
68
|
const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ jsxs(Fragment, {
|
|
69
69
|
children: [
|
|
@@ -83,9 +83,11 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
83
83
|
runtimeContext,
|
|
84
84
|
ssrConfig,
|
|
85
85
|
entryName,
|
|
86
|
+
moduleFederationCssAssets,
|
|
86
87
|
rscClientManifest: options.rscClientManifest,
|
|
87
88
|
rscSSRManifest: options.rscSSRManifest,
|
|
88
89
|
rscServerManifest: options.rscServerManifest,
|
|
90
|
+
rscManifest: options.rscManifest,
|
|
89
91
|
rscRoot: options.rscRoot,
|
|
90
92
|
onShellReady () {
|
|
91
93
|
const cost = end();
|