@nuxt/nitro-server 4.2.2 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +4 -2
  2. package/dist/index.d.mts +280 -78
  3. package/dist/index.mjs +696 -745
  4. package/dist/runtime/handlers/{error.d.ts → error.d.mts} +1 -1
  5. package/dist/runtime/handlers/error.mjs +77 -0
  6. package/dist/runtime/handlers/island.d.mts +2 -0
  7. package/dist/runtime/handlers/island.mjs +120 -0
  8. package/dist/runtime/handlers/renderer.d.mts +2 -0
  9. package/dist/runtime/handlers/renderer.mjs +305 -0
  10. package/dist/runtime/middleware/no-ssr.d.mts +2 -0
  11. package/dist/runtime/middleware/no-ssr.mjs +7 -0
  12. package/dist/runtime/plugins/dev-server-logs.d.mts +2 -0
  13. package/dist/runtime/plugins/dev-server-logs.mjs +94 -0
  14. package/dist/runtime/templates/error-500.d.mts +2 -0
  15. package/dist/runtime/templates/error-500.mjs +15 -0
  16. package/dist/runtime/utils/app-config.d.mts +3 -0
  17. package/dist/runtime/utils/app-config.mjs +31 -0
  18. package/dist/runtime/utils/cache.d.mts +5 -0
  19. package/dist/runtime/utils/cache.mjs +20 -0
  20. package/dist/runtime/utils/config.d.mts +1 -0
  21. package/dist/runtime/utils/{dev.d.ts → dev.d.mts} +1 -1
  22. package/dist/runtime/utils/dev.mjs +985 -0
  23. package/dist/runtime/utils/error.d.mts +6 -0
  24. package/dist/runtime/utils/error.mjs +15 -0
  25. package/dist/runtime/utils/paths.mjs +19 -0
  26. package/dist/runtime/utils/renderer/{app.d.ts → app.d.mts} +4 -4
  27. package/dist/runtime/utils/renderer/app.mjs +39 -0
  28. package/dist/runtime/utils/renderer/build-files.d.mts +18 -0
  29. package/dist/runtime/utils/renderer/build-files.mjs +100 -0
  30. package/dist/runtime/utils/renderer/{inline-styles.d.ts → inline-styles.d.mts} +1 -1
  31. package/dist/runtime/utils/renderer/inline-styles.mjs +13 -0
  32. package/dist/runtime/utils/renderer/{islands.d.ts → islands.d.mts} +5 -5
  33. package/dist/runtime/utils/renderer/islands.mjs +87 -0
  34. package/dist/runtime/utils/renderer/payload.d.mts +24 -0
  35. package/dist/runtime/utils/renderer/payload.mjs +64 -0
  36. package/package.json +19 -17
  37. package/dist/index.d.ts +0 -85
  38. package/dist/runtime/handlers/error.js +0 -63
  39. package/dist/runtime/handlers/island.d.ts +0 -4
  40. package/dist/runtime/handlers/island.js +0 -100
  41. package/dist/runtime/handlers/renderer.d.ts +0 -8
  42. package/dist/runtime/handlers/renderer.js +0 -238
  43. package/dist/runtime/middleware/no-ssr.d.ts +0 -2
  44. package/dist/runtime/middleware/no-ssr.js +0 -7
  45. package/dist/runtime/plugins/dev-server-logs.d.ts +0 -3
  46. package/dist/runtime/plugins/dev-server-logs.js +0 -82
  47. package/dist/runtime/templates/error-500.d.ts +0 -2
  48. package/dist/runtime/templates/error-500.js +0 -6
  49. package/dist/runtime/utils/app-config.d.ts +0 -2
  50. package/dist/runtime/utils/app-config.js +0 -25
  51. package/dist/runtime/utils/cache-driver.d.ts +0 -6
  52. package/dist/runtime/utils/cache.d.ts +0 -8
  53. package/dist/runtime/utils/cache.js +0 -19
  54. package/dist/runtime/utils/config.d.ts +0 -1
  55. package/dist/runtime/utils/dev.js +0 -334
  56. package/dist/runtime/utils/error.d.ts +0 -6
  57. package/dist/runtime/utils/error.js +0 -11
  58. package/dist/runtime/utils/paths.js +0 -16
  59. package/dist/runtime/utils/renderer/app.js +0 -33
  60. package/dist/runtime/utils/renderer/build-files.d.ts +0 -22
  61. package/dist/runtime/utils/renderer/build-files.js +0 -85
  62. package/dist/runtime/utils/renderer/inline-styles.js +0 -13
  63. package/dist/runtime/utils/renderer/islands.js +0 -82
  64. package/dist/runtime/utils/renderer/payload.d.ts +0 -37
  65. package/dist/runtime/utils/renderer/payload.js +0 -67
  66. /package/dist/runtime/utils/{config.js → config.mjs} +0 -0
  67. /package/dist/runtime/utils/{paths.d.ts → paths.d.mts} +0 -0
@@ -1,334 +0,0 @@
1
- const iframeStorageBridge = (nonce) => (
2
- /* js */
3
- `
4
- (function() {
5
- const memoryStore = {};
6
-
7
- const NONCE = ${JSON.stringify(nonce)}
8
-
9
- const mockStorage = {
10
- getItem: function(key) {
11
- return memoryStore[key] !== undefined ? memoryStore[key] : null;
12
- },
13
- setItem: function(key, value) {
14
- memoryStore[key] = String(value);
15
- window.parent.postMessage({
16
- type: 'storage-set',
17
- key: key,
18
- value: String(value),
19
- nonce: NONCE
20
- }, '*');
21
- },
22
- removeItem: function(key) {
23
- delete memoryStore[key];
24
- window.parent.postMessage({
25
- type: 'storage-remove',
26
- key: key,
27
- nonce: NONCE
28
- }, '*');
29
- },
30
- clear: function() {
31
- for (const key in memoryStore) {
32
- delete memoryStore[key];
33
- }
34
- window.parent.postMessage({
35
- type: 'storage-clear',
36
- nonce: NONCE
37
- }, '*');
38
- },
39
- key: function(index) {
40
- const keys = Object.keys(memoryStore);
41
- return keys[index] !== undefined ? keys[index] : null;
42
- },
43
- get length() {
44
- return Object.keys(memoryStore).length;
45
- }
46
- };
47
-
48
- try {
49
- Object.defineProperty(window, 'localStorage', {
50
- value: mockStorage,
51
- writable: false,
52
- configurable: true
53
- });
54
- } catch (e) {
55
- window.localStorage = mockStorage;
56
- }
57
-
58
- window.addEventListener('message', function(event) {
59
- if (event.data.type === 'storage-sync-data' && event.data.nonce === NONCE) {
60
- const data = event.data.data;
61
- for (const key in data) {
62
- if (Object.prototype.hasOwnProperty.call(data, key)) {
63
- memoryStore[key] = data[key];
64
- }
65
- }
66
- if (typeof window.initTheme === 'function') {
67
- window.initTheme();
68
- }
69
- window.dispatchEvent(new Event('storage-ready'));
70
- }
71
- });
72
-
73
- window.parent.postMessage({
74
- type: 'storage-sync-request',
75
- nonce: NONCE
76
- }, '*');
77
- })();
78
- `
79
- );
80
- const parentStorageBridge = (nonce) => (
81
- /* js */
82
- `
83
- (function() {
84
- const host = document.querySelector('nuxt-error-overlay');
85
- if (!host) return;
86
-
87
- // Wait for shadow root to be attached
88
- const checkShadow = setInterval(function() {
89
- if (host.shadowRoot) {
90
- clearInterval(checkShadow);
91
- const iframe = host.shadowRoot.getElementById('frame');
92
- if (!iframe) return;
93
-
94
- const NONCE = ${JSON.stringify(nonce)}
95
-
96
- window.addEventListener('message', function(event) {
97
- if (!event.data || event.data.nonce !== NONCE) return;
98
-
99
- const data = event.data;
100
-
101
- if (data.type === 'storage-set') {
102
- localStorage.setItem(data.key, data.value);
103
- } else if (data.type === 'storage-remove') {
104
- localStorage.removeItem(data.key);
105
- } else if (data.type === 'storage-clear') {
106
- localStorage.clear();
107
- } else if (data.type === 'storage-sync-request') {
108
- const allData = {};
109
- for (let i = 0; i < localStorage.length; i++) {
110
- const key = localStorage.key(i);
111
- allData[key] = localStorage.getItem(key);
112
- }
113
- iframe.contentWindow.postMessage({
114
- type: 'storage-sync-data',
115
- data: allData,
116
- nonce: NONCE
117
- }, '*');
118
- }
119
- });
120
- }
121
- }, 10);
122
- })();
123
- `
124
- );
125
- const errorCSS = (
126
- /* css */
127
- `
128
- :host {
129
- --preview-width: 240px;
130
- --preview-height: 180px;
131
- --base-width: 1200px;
132
- --base-height: 900px;
133
- --z-base: 999999998;
134
- all: initial;
135
- display: contents;
136
- }
137
- .sr-only {
138
- position: absolute;
139
- width: 1px;
140
- height: 1px;
141
- padding: 0;
142
- margin: -1px;
143
- overflow: hidden;
144
- clip: rect(0, 0, 0, 0);
145
- white-space: nowrap;
146
- border-width: 0;
147
- }
148
- #frame {
149
- position: fixed;
150
- left: 0;
151
- top: 0;
152
- width: 100vw;
153
- height: 100vh;
154
- border: none;
155
- z-index: var(--z-base);
156
- }
157
- #frame[inert] {
158
- right: 5px;
159
- bottom: 5px;
160
- left: auto;
161
- top: auto;
162
- width: var(--base-width);
163
- height: var(--base-height);
164
- transform: scale(calc(240 / 1200));
165
- transform-origin: bottom right;
166
- overflow: hidden;
167
- border-radius: calc(1200 * 8px / 240);
168
- }
169
- #preview {
170
- position: fixed;
171
- right: 5px;
172
- bottom: 5px;
173
- width: var(--preview-width);
174
- height: var(--preview-height);
175
- overflow: hidden;
176
- border-radius: 8px;
177
- pointer-events: none;
178
- z-index: var(--z-base);
179
- background: white;
180
- display: none;
181
- }
182
- #frame:not([inert]) + #preview {
183
- display: block;
184
- }
185
- #toggle {
186
- position: fixed;
187
- right: 5px;
188
- bottom: 5px;
189
- width: var(--preview-width);
190
- height: var(--preview-height);
191
- background: none;
192
- border: 3px solid #00DC82;
193
- border-radius: 8px;
194
- cursor: pointer;
195
- opacity: 0.8;
196
- transition: opacity 0.2s, box-shadow 0.2s;
197
- z-index: calc(var(--z-base) + 1);
198
- }
199
- #toggle:hover,
200
- #toggle:focus {
201
- opacity: 1;
202
- box-shadow: 0 0 20px rgba(0, 220, 130, 0.6);
203
- }
204
- #toggle:focus-visible {
205
- outline: 3px solid #00DC82;
206
- outline-offset: 3px;
207
- box-shadow: 0 0 24px rgba(0, 220, 130, 0.8);
208
- }
209
- @media (prefers-reduced-motion: reduce) {
210
- #toggle {
211
- transition: none;
212
- }
213
- }
214
- `
215
- );
216
- function webComponentScript(base64HTML, startMinimized) {
217
- return (
218
- /* js */
219
- `
220
- (function() {
221
- try {
222
- const host = document.querySelector('nuxt-error-overlay');
223
- if (!host) return;
224
-
225
- const shadow = host.attachShadow({ mode: 'open' });
226
-
227
- // Create elements
228
- const style = document.createElement('style');
229
- style.textContent = ${JSON.stringify(errorCSS)};
230
-
231
- const iframe = document.createElement('iframe');
232
- iframe.id = 'frame';
233
- iframe.src = 'data:text/html;base64,${base64HTML}';
234
- iframe.title = 'Detailed error stack trace';
235
- iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
236
-
237
- const preview = document.createElement('div');
238
- preview.id = 'preview';
239
-
240
- const button = document.createElement('button');
241
- button.id = 'toggle';
242
- button.setAttribute('aria-expanded', 'true');
243
- button.setAttribute('type', 'button');
244
- button.innerHTML = '<span class="sr-only">Toggle detailed error view</span>';
245
-
246
- const liveRegion = document.createElement('div');
247
- liveRegion.setAttribute('role', 'status');
248
- liveRegion.setAttribute('aria-live', 'polite');
249
- liveRegion.className = 'sr-only';
250
-
251
- // Update preview snapshot
252
- function updatePreview() {
253
- try {
254
- let previewIframe = preview.querySelector('iframe');
255
- if (!previewIframe) {
256
- previewIframe = document.createElement('iframe');
257
- previewIframe.style.cssText = 'width: 1200px; height: 900px; transform: scale(0.2); transform-origin: top left; border: none;';
258
- previewIframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
259
- preview.appendChild(previewIframe);
260
- }
261
-
262
- const doctype = document.doctype ? '<!DOCTYPE ' + document.doctype.name + '>' : '';
263
- const cleanedHTML = document.documentElement.outerHTML
264
- .replace(/<nuxt-error-overlay[^>]*>.*?<\\/nuxt-error-overlay>/gs, '')
265
- .replace(/<script[^>]*>.*?<\\/script>/gs, '');
266
-
267
- const iframeDoc = previewIframe.contentDocument || previewIframe.contentWindow.document;
268
- iframeDoc.open();
269
- iframeDoc.write(doctype + cleanedHTML);
270
- iframeDoc.close();
271
- } catch (error) {
272
- console.error('Failed to update preview:', error);
273
- }
274
- }
275
-
276
- function toggleView() {
277
- const isMinimized = iframe.hasAttribute('inert');
278
-
279
- if (isMinimized) {
280
- updatePreview();
281
- iframe.removeAttribute('inert');
282
- button.setAttribute('aria-expanded', 'true');
283
- liveRegion.textContent = 'Showing detailed error view';
284
- setTimeout(function() {
285
- try { iframe.contentWindow.focus(); } catch {}
286
- }, 100);
287
- } else {
288
- iframe.setAttribute('inert', '');
289
- button.setAttribute('aria-expanded', 'false');
290
- liveRegion.textContent = 'Showing error page';
291
- button.focus();
292
- }
293
- }
294
-
295
- button.onclick = toggleView;
296
-
297
- document.addEventListener('keydown', function(e) {
298
- if ((e.key === 'Escape' || e.key === 'Esc') && !iframe.hasAttribute('inert')) {
299
- toggleView();
300
- }
301
- });
302
-
303
- // Append to shadow DOM
304
- shadow.appendChild(style);
305
- shadow.appendChild(liveRegion);
306
- shadow.appendChild(iframe);
307
- shadow.appendChild(preview);
308
- shadow.appendChild(button);
309
-
310
- if (${startMinimized}) {
311
- iframe.setAttribute('inert', '');
312
- button.setAttribute('aria-expanded', 'false');
313
- }
314
-
315
- // Initialize preview
316
- setTimeout(updatePreview, 100);
317
-
318
- } catch (error) {
319
- console.error('Failed to initialize Nuxt error overlay:', error);
320
- }
321
- })();
322
- `
323
- );
324
- }
325
- export function generateErrorOverlayHTML(html, options) {
326
- const nonce = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
327
- const errorPage = html.replace("<head>", `<head><script>${iframeStorageBridge(nonce)}<\/script>`);
328
- const base64HTML = Buffer.from(errorPage, "utf8").toString("base64");
329
- return `
330
- <script>${parentStorageBridge(nonce)}<\/script>
331
- <nuxt-error-overlay></nuxt-error-overlay>
332
- <script>${webComponentScript(base64HTML, options?.startMinimized ?? false)}<\/script>
333
- `;
334
- }
@@ -1,6 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- /**
3
- * Nitro internal functions extracted from https://github.com/nitrojs/nitro/blob/v2/src/runtime/internal/utils.ts
4
- */
5
- export declare function isJsonRequest(event: H3Event): boolean;
6
- export declare function hasReqHeader(event: H3Event, name: string, includes: string): boolean | "" | undefined;
@@ -1,11 +0,0 @@
1
- import { getRequestHeader } from "h3";
2
- export function isJsonRequest(event) {
3
- if (hasReqHeader(event, "accept", "text/html")) {
4
- return false;
5
- }
6
- return hasReqHeader(event, "accept", "application/json") || hasReqHeader(event, "user-agent", "curl/") || hasReqHeader(event, "user-agent", "httpie/") || hasReqHeader(event, "sec-fetch-mode", "cors") || event.path.startsWith("/api/") || event.path.endsWith(".json");
7
- }
8
- export function hasReqHeader(event, name, includes) {
9
- const value = getRequestHeader(event, name);
10
- return value && typeof value === "string" && value.toLowerCase().includes(includes);
11
- }
@@ -1,16 +0,0 @@
1
- import { joinRelativeURL } from "ufo";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- export function baseURL() {
4
- return useRuntimeConfig().app.baseURL;
5
- }
6
- export function buildAssetsDir() {
7
- return useRuntimeConfig().app.buildAssetsDir;
8
- }
9
- export function buildAssetsURL(...path) {
10
- return joinRelativeURL(publicAssetsURL(), buildAssetsDir(), ...path);
11
- }
12
- export function publicAssetsURL(...path) {
13
- const app = useRuntimeConfig().app;
14
- const publicBase = app.cdnURL || app.baseURL;
15
- return path.length ? joinRelativeURL(publicBase, ...path) : publicBase;
16
- }
@@ -1,33 +0,0 @@
1
- import process from "node:process";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- import { createHead } from "@unhead/vue/server";
4
- import { sharedPrerenderCache } from "../cache.js";
5
- import unheadOptions from "#internal/unhead-options.mjs";
6
- const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.html", "/404.html"]);
7
- export function createSSRContext(event) {
8
- const ssrContext = {
9
- url: event.path,
10
- event,
11
- runtimeConfig: useRuntimeConfig(event),
12
- noSSR: !!process.env.NUXT_NO_SSR || event.context.nuxt?.noSSR || (import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(event.path) : false),
13
- head: createHead(unheadOptions),
14
- error: false,
15
- nuxt: void 0,
16
- /* NuxtApp */
17
- payload: {},
18
- _payloadReducers: /* @__PURE__ */ Object.create(null),
19
- modules: /* @__PURE__ */ new Set()
20
- };
21
- if (import.meta.prerender) {
22
- if (process.env.NUXT_SHARED_DATA) {
23
- ssrContext._sharedPrerenderCache = sharedPrerenderCache;
24
- }
25
- ssrContext.payload.prerenderedAt = Date.now();
26
- }
27
- return ssrContext;
28
- }
29
- export function setSSRError(ssrContext, error) {
30
- ssrContext.error = true;
31
- ssrContext.payload = { error };
32
- ssrContext.url = error.url;
33
- }
@@ -1,22 +0,0 @@
1
- import type { NuxtSSRContext } from 'nuxt/app';
2
- export declare const getSSRRenderer: () => Promise<{
3
- rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
4
- renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
5
- html: string;
6
- renderResourceHeaders: () => Record<string, string>;
7
- renderResourceHints: () => string;
8
- renderStyles: () => string;
9
- renderScripts: () => string;
10
- }>;
11
- }>;
12
- export declare function getRenderer(ssrContext: NuxtSSRContext): Promise<{
13
- rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
14
- renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
15
- html: string;
16
- renderResourceHeaders: () => Record<string, string>;
17
- renderResourceHints: () => string;
18
- renderStyles: () => string;
19
- renderScripts: () => string;
20
- }>;
21
- }>;
22
- export declare const getSSRStyles: () => Promise<Record<string, () => Promise<string[]>>>;
@@ -1,85 +0,0 @@
1
- import process from "node:process";
2
- import { createRenderer } from "vue-bundle-renderer/runtime";
3
- import { renderToString as _renderToString } from "vue/server-renderer";
4
- import { propsToString } from "@unhead/vue/server";
5
- import { useRuntimeConfig } from "nitropack/runtime";
6
- import { appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, spaLoadingTemplateOutside } from "#internal/nuxt.config.mjs";
7
- import { buildAssetsURL } from "#internal/nuxt/paths";
8
- const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
9
- const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
10
- const getServerEntry = () => import("#build/dist/server/server.mjs").then((r) => r.default || r);
11
- const getClientManifest = () => import("#build/dist/server/client.manifest.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
12
- const getPrecomputedDependencies = () => import("#build/dist/server/client.precomputed.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
13
- export const getSSRRenderer = lazyCachedFunction(async () => {
14
- const createSSRApp = await getServerEntry();
15
- if (!createSSRApp) {
16
- throw new Error("Server bundle is not available");
17
- }
18
- const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
19
- const renderer = createRenderer(createSSRApp, {
20
- precomputed,
21
- manifest: import.meta.dev ? await getClientManifest() : void 0,
22
- renderToString,
23
- buildAssetsURL
24
- });
25
- async function renderToString(input, context) {
26
- const html = await _renderToString(input, context);
27
- if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
28
- renderer.rendererContext.updateManifest(await getClientManifest());
29
- }
30
- return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG;
31
- }
32
- return renderer;
33
- });
34
- const getSPARenderer = lazyCachedFunction(async () => {
35
- const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
36
- const spaTemplate = await import("#spa-template").then((r) => r.template).catch(() => "").then((r) => {
37
- if (spaLoadingTemplateOutside) {
38
- const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`;
39
- const APP_SPA_LOADER_CLOSE_TAG = `</${appSpaLoaderTag}>`;
40
- const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG;
41
- const loaderTemplate = r ? APP_SPA_LOADER_OPEN_TAG + r + APP_SPA_LOADER_CLOSE_TAG : "";
42
- return appTemplate + loaderTemplate;
43
- } else {
44
- return APP_ROOT_OPEN_TAG + r + APP_ROOT_CLOSE_TAG;
45
- }
46
- });
47
- const renderer = createRenderer(() => () => {
48
- }, {
49
- precomputed,
50
- manifest: import.meta.dev ? await getClientManifest() : void 0,
51
- renderToString: () => spaTemplate,
52
- buildAssetsURL
53
- });
54
- const result = await renderer.renderToString({});
55
- const renderToString = (ssrContext) => {
56
- const config = useRuntimeConfig(ssrContext.event);
57
- ssrContext.modules ||= /* @__PURE__ */ new Set();
58
- ssrContext.payload.serverRendered = false;
59
- ssrContext.config = {
60
- public: config.public,
61
- app: config.app
62
- };
63
- return Promise.resolve(result);
64
- };
65
- return {
66
- rendererContext: renderer.rendererContext,
67
- renderToString
68
- };
69
- });
70
- function lazyCachedFunction(fn) {
71
- let res = null;
72
- return () => {
73
- if (res === null) {
74
- res = fn().catch((err) => {
75
- res = null;
76
- throw err;
77
- });
78
- }
79
- return res;
80
- };
81
- }
82
- export function getRenderer(ssrContext) {
83
- return process.env.NUXT_NO_SSR || ssrContext.noSSR ? getSPARenderer() : getSSRRenderer();
84
- }
85
- export const getSSRStyles = lazyCachedFunction(() => import("#build/dist/server/styles.mjs").then((r) => r.default || r));
@@ -1,13 +0,0 @@
1
- import { getSSRStyles } from "./build-files.js";
2
- export async function renderInlineStyles(usedModules) {
3
- const styleMap = await getSSRStyles();
4
- const inlinedStyles = /* @__PURE__ */ new Set();
5
- for (const mod of usedModules) {
6
- if (mod in styleMap && styleMap[mod]) {
7
- for (const style of await styleMap[mod]()) {
8
- inlinedStyles.add(style);
9
- }
10
- }
11
- }
12
- return Array.from(inlinedStyles).map((style) => ({ innerHTML: style }));
13
- }
@@ -1,82 +0,0 @@
1
- import { appRootTag } from "#internal/nuxt.config.mjs";
2
- const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag}[^>]*>([\\s\\S]*)<\\/${appRootTag}>$`);
3
- export function getServerComponentHTML(body) {
4
- const match = body.match(ROOT_NODE_REGEX);
5
- return match?.[1] || body;
6
- }
7
- const SSR_SLOT_TELEPORT_MARKER = /^uid=([^;]*);slot=(.*)$/;
8
- const SSR_CLIENT_TELEPORT_MARKER = /^uid=([^;]*);client=(.*)$/;
9
- const SSR_CLIENT_SLOT_MARKER = /^island-slot=([^;]*);(.*)$/;
10
- export function getSlotIslandResponse(ssrContext) {
11
- if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) {
12
- return void 0;
13
- }
14
- const response = {};
15
- for (const [name, slot] of Object.entries(ssrContext.islandContext.slots)) {
16
- response[name] = {
17
- ...slot,
18
- fallback: ssrContext.teleports?.[`island-fallback=${name}`]
19
- };
20
- }
21
- return response;
22
- }
23
- export function getClientIslandResponse(ssrContext) {
24
- if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.components).length) {
25
- return void 0;
26
- }
27
- const response = {};
28
- for (const [clientUid, component] of Object.entries(ssrContext.islandContext.components)) {
29
- const html = ssrContext.teleports?.[clientUid]?.replaceAll("<!--teleport start anchor-->", "") || "";
30
- response[clientUid] = {
31
- ...component,
32
- html,
33
- slots: getComponentSlotTeleport(clientUid, ssrContext.teleports ?? {})
34
- };
35
- }
36
- return response;
37
- }
38
- export function getComponentSlotTeleport(clientUid, teleports) {
39
- const entries = Object.entries(teleports);
40
- const slots = {};
41
- for (const [key, value] of entries) {
42
- const match = key.match(SSR_CLIENT_SLOT_MARKER);
43
- if (match) {
44
- const [, id, slot] = match;
45
- if (!slot || clientUid !== id) {
46
- continue;
47
- }
48
- slots[slot] = value;
49
- }
50
- }
51
- return slots;
52
- }
53
- export function replaceIslandTeleports(ssrContext, html) {
54
- const { teleports, islandContext } = ssrContext;
55
- if (islandContext || !teleports) {
56
- return html;
57
- }
58
- for (const key in teleports) {
59
- const matchClientComp = key.match(SSR_CLIENT_TELEPORT_MARKER);
60
- if (matchClientComp) {
61
- const [, uid, clientId] = matchClientComp;
62
- if (!uid || !clientId) {
63
- continue;
64
- }
65
- html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-component="${clientId}"[^>]*>`), (full) => {
66
- return full + teleports[key];
67
- });
68
- continue;
69
- }
70
- const matchSlot = key.match(SSR_SLOT_TELEPORT_MARKER);
71
- if (matchSlot) {
72
- const [, uid, slot] = matchSlot;
73
- if (!uid || !slot) {
74
- continue;
75
- }
76
- html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-slot="${slot}"[^>]*>`), (full) => {
77
- return full + teleports[key];
78
- });
79
- }
80
- }
81
- return html;
82
- }
@@ -1,37 +0,0 @@
1
- import type { Script } from '@unhead/vue';
2
- import type { NuxtSSRContext } from 'nuxt/app';
3
- export declare function renderPayloadResponse(ssrContext: NuxtSSRContext): {
4
- body: string;
5
- statusCode: number;
6
- statusMessage: string;
7
- headers: {
8
- 'content-type': string;
9
- 'x-powered-by': string;
10
- };
11
- };
12
- export declare function renderPayloadJsonScript(opts: {
13
- ssrContext: NuxtSSRContext;
14
- data?: any;
15
- src?: string;
16
- }): Script[];
17
- export declare function renderPayloadScript(opts: {
18
- ssrContext: NuxtSSRContext;
19
- data?: any;
20
- src?: string;
21
- }): Script[];
22
- export declare function splitPayload(ssrContext: NuxtSSRContext): {
23
- initial: {
24
- prerenderedAt: number | undefined;
25
- path?: string | undefined;
26
- serverRendered?: boolean | undefined;
27
- state?: Record<string, any> | undefined;
28
- once?: Set<string> | undefined;
29
- config?: Pick<import("nuxt/schema").RuntimeConfig, "public" | "app"> | undefined;
30
- error?: import("nuxt/app").NuxtError<unknown> | undefined;
31
- _errors?: Record<string, import("nuxt/app").NuxtError<unknown> | undefined> | undefined;
32
- };
33
- payload: {
34
- data: Record<string, any> | undefined;
35
- prerenderedAt: number | undefined;
36
- };
37
- };