remote-components 0.3.0 → 0.3.2
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/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +467 -395
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +467 -395
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +507 -447
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +515 -455
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +5 -6
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +5 -6
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +6 -11
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +9 -11
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +435 -374
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +435 -374
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +16 -7
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.d.ts +2 -2
- package/dist/internal/host/nextjs/dom-flight.js +16 -7
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +2 -2
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.js +2 -2
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +183 -149
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +185 -149
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +2 -5
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.js +2 -5
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -1
- package/dist/internal/runtime/constants.cjs +6 -6
- package/dist/internal/runtime/constants.cjs.map +1 -1
- package/dist/internal/runtime/constants.d.ts +3 -3
- package/dist/internal/runtime/constants.js +4 -4
- package/dist/internal/runtime/constants.js.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.cjs +11 -15
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.d.ts +2 -12
- package/dist/internal/runtime/html/parse-remote-html.js +17 -15
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +2 -2
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +1 -1
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/metadata.cjs +42 -0
- package/dist/internal/runtime/metadata.cjs.map +1 -1
- package/dist/internal/runtime/metadata.d.ts +21 -1
- package/dist/internal/runtime/metadata.js +38 -0
- package/dist/internal/runtime/metadata.js.map +1 -1
- package/dist/internal/runtime/patterns.cjs +38 -0
- package/dist/internal/runtime/patterns.cjs.map +1 -0
- package/dist/internal/runtime/patterns.d.ts +5 -0
- package/dist/internal/runtime/patterns.js +12 -0
- package/dist/internal/runtime/patterns.js.map +1 -0
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +79 -128
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +22 -7
- package/dist/internal/runtime/turbopack/chunk-loader.js +85 -131
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +56 -57
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +14 -11
- package/dist/internal/runtime/turbopack/module.js +54 -56
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +101 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +55 -0
- package/dist/internal/runtime/turbopack/remote-scope.js +73 -0
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -0
- package/dist/internal/runtime/turbopack/shared-modules.cjs +62 -56
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +7 -3
- package/dist/internal/runtime/turbopack/shared-modules.js +63 -57
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +50 -31
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +5 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.js +52 -34
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +4 -3
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/internal/utils.cjs +5 -0
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +15 -1
- package/dist/internal/utils.js +4 -0
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +2 -1
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +2 -1
- package/dist/remote/nextjs/app.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,15 +7,174 @@ import {
|
|
|
7
7
|
import { fetchWithHooks } from "#internal/host/server/fetch-with-hooks";
|
|
8
8
|
import { getClientSrc } from "#internal/host/server/get-client-src";
|
|
9
9
|
import { getSSRRelativePathBaseUrl } from "#internal/host/server/get-ssr-relative-path-base-url";
|
|
10
|
+
import {
|
|
11
|
+
buildMetadata
|
|
12
|
+
} from "#internal/runtime/metadata";
|
|
13
|
+
import { computeScopedName } from "#internal/utils";
|
|
10
14
|
import {
|
|
11
15
|
failedToFetchRemoteComponentError,
|
|
12
16
|
multipleRemoteComponentsError,
|
|
13
17
|
RemoteComponentsError
|
|
14
18
|
} from "#internal/utils/error";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
+
async function buildRscComponent(rsc, serverUrl) {
|
|
20
|
+
const componentRSC = `0:${JSON.stringify(rsc)}
|
|
21
|
+
`;
|
|
22
|
+
const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.edge");
|
|
23
|
+
return createFromReadableStream(
|
|
24
|
+
new ReadableStream({
|
|
25
|
+
type: "bytes",
|
|
26
|
+
start(controller) {
|
|
27
|
+
const encoder = new TextEncoder();
|
|
28
|
+
controller.enqueue(encoder.encode(componentRSC));
|
|
29
|
+
controller.close();
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
{
|
|
33
|
+
serverConsumerManifest: {
|
|
34
|
+
moduleLoading: {
|
|
35
|
+
prefix: serverUrl.origin,
|
|
36
|
+
crossOrigin: true
|
|
37
|
+
},
|
|
38
|
+
moduleMap: {}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function buildSkeletonResponse(serverUrl, metadata, skeletonComponent) {
|
|
44
|
+
return {
|
|
45
|
+
name: "remote-component-skeleton",
|
|
46
|
+
serverUrl,
|
|
47
|
+
metadata: {
|
|
48
|
+
...metadata,
|
|
49
|
+
type: "remote-component"
|
|
50
|
+
},
|
|
51
|
+
rsc: getSkeletonMessage(),
|
|
52
|
+
scripts: [],
|
|
53
|
+
links: [],
|
|
54
|
+
hydrationData: [],
|
|
55
|
+
nextData: void 0,
|
|
56
|
+
component: skeletonComponent,
|
|
57
|
+
html: getSkeletonHtml(serverUrl.href),
|
|
58
|
+
remoteShared: {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function scopeChunkReferences(chunk, bundle, scopedName) {
|
|
62
|
+
return chunk.replaceAll(`[${bundle}]`, `[${scopedName}]`);
|
|
63
|
+
}
|
|
64
|
+
function visitFragment(fragment, serverUrl, remoteName) {
|
|
65
|
+
const scriptSrcSet = /* @__PURE__ */ new Set();
|
|
66
|
+
const scriptTextSet = /* @__PURE__ */ new Set();
|
|
67
|
+
const scripts = [];
|
|
68
|
+
const linkKeySet = /* @__PURE__ */ new Set();
|
|
69
|
+
const links = [];
|
|
70
|
+
const hydrationData = [];
|
|
71
|
+
const htmlChunks = /* @__PURE__ */ new Set();
|
|
72
|
+
let metadata;
|
|
73
|
+
let nextData;
|
|
74
|
+
let remoteShared = {};
|
|
75
|
+
let hasRSC = false;
|
|
76
|
+
let hasShared = false;
|
|
77
|
+
let error;
|
|
78
|
+
const isCrossOrigin = serverUrl.origin !== getSSRRelativePathBaseUrl();
|
|
79
|
+
const rawRscChunks = [];
|
|
80
|
+
const rsc = visit(fragment, {
|
|
81
|
+
url: serverUrl,
|
|
82
|
+
name: remoteName,
|
|
83
|
+
onMetadata(attrs) {
|
|
84
|
+
const incoming = buildMetadata(attrs, serverUrl);
|
|
85
|
+
if (!remoteName && metadata && metadata.id !== incoming.id && incoming.id !== "__next" && metadata.id !== "__next" && !nextData) {
|
|
86
|
+
throw multipleRemoteComponentsError(serverUrl.href);
|
|
87
|
+
}
|
|
88
|
+
metadata = incoming;
|
|
89
|
+
},
|
|
90
|
+
onScript(attrs) {
|
|
91
|
+
const clientSrc = getClientSrc(attrs.src, serverUrl.href);
|
|
92
|
+
const textContent = typeof attrs.textContent === "string" ? attrs.textContent : void 0;
|
|
93
|
+
if (textContent) {
|
|
94
|
+
if (!scriptTextSet.has(textContent)) {
|
|
95
|
+
scriptTextSet.add(textContent);
|
|
96
|
+
scripts.push({ src: "", textContent });
|
|
97
|
+
}
|
|
98
|
+
} else if (!scriptSrcSet.has(clientSrc)) {
|
|
99
|
+
scriptSrcSet.add(clientSrc);
|
|
100
|
+
scripts.push({ src: clientSrc });
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onLink(attrs) {
|
|
104
|
+
const relativeAttrs = {
|
|
105
|
+
...attrs,
|
|
106
|
+
href: getClientSrc(attrs.href, serverUrl.href)
|
|
107
|
+
};
|
|
108
|
+
const linkKey = `${relativeAttrs.href}::${attrs.rel}`;
|
|
109
|
+
if (!linkKeySet.has(linkKey)) {
|
|
110
|
+
linkKeySet.add(linkKey);
|
|
111
|
+
links.push(relativeAttrs);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
onRSC(chunk) {
|
|
115
|
+
rawRscChunks.push(chunk);
|
|
116
|
+
hasRSC = true;
|
|
117
|
+
},
|
|
118
|
+
onNextData(data) {
|
|
119
|
+
nextData = data;
|
|
120
|
+
},
|
|
121
|
+
onHTML(chunk) {
|
|
122
|
+
if (!htmlChunks.has(chunk)) {
|
|
123
|
+
htmlChunks.add(chunk);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
onShared(_shared) {
|
|
127
|
+
remoteShared = _shared;
|
|
128
|
+
hasShared = true;
|
|
129
|
+
},
|
|
130
|
+
onError(message, stack) {
|
|
131
|
+
error = new RemoteComponentsError(message);
|
|
132
|
+
if (stack) {
|
|
133
|
+
error.stack = stack;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (isCrossOrigin && metadata?.bundle) {
|
|
138
|
+
const scopedName = computeScopedName(metadata.bundle, {
|
|
139
|
+
remoteHost: serverUrl.host,
|
|
140
|
+
isCrossOrigin: true
|
|
141
|
+
});
|
|
142
|
+
for (const chunk of rawRscChunks) {
|
|
143
|
+
hydrationData.push(
|
|
144
|
+
scopeChunkReferences(chunk, metadata.bundle, scopedName)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
hydrationData.push(...rawRscChunks);
|
|
149
|
+
}
|
|
150
|
+
if (error) {
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
if (metadata) {
|
|
154
|
+
if (!hasRSC && !nextData && metadata.type === "nextjs") {
|
|
155
|
+
throw new RemoteComponentsError(
|
|
156
|
+
`The Remote Component at "${serverUrl.href}" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (metadata.type === "nextjs" && !hasShared && !nextData?.props.__REMOTE_COMPONENT__?.shared) {
|
|
160
|
+
throw new RemoteComponentsError(
|
|
161
|
+
`No shared dependencies found for Remote Component at "${serverUrl.href}". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const resolvedShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared;
|
|
166
|
+
return {
|
|
167
|
+
rsc,
|
|
168
|
+
metadata,
|
|
169
|
+
scripts,
|
|
170
|
+
links,
|
|
171
|
+
hydrationData,
|
|
172
|
+
nextData,
|
|
173
|
+
remoteShared: resolvedShared,
|
|
174
|
+
html: Array.from(htmlChunks).join("")
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async function fetchRemoteComponent(src, options = {}) {
|
|
19
178
|
const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();
|
|
20
179
|
const serverUrl = new URL(src, ssrRelativePathBaseUrl);
|
|
21
180
|
const tags = [
|
|
@@ -68,122 +227,36 @@ async function fetchRemoteComponent(src, options = {
|
|
|
68
227
|
parser.tokenizer.write(decoder.decode(chunk), false);
|
|
69
228
|
}
|
|
70
229
|
const fragment = parser.getFragment();
|
|
71
|
-
let metadata = {
|
|
72
|
-
bundle: CURRENT_ZONE ?? "__vercel_remote_component",
|
|
73
|
-
route: "/",
|
|
74
|
-
runtime: "webpack",
|
|
75
|
-
id: "__vercel_remote_component",
|
|
76
|
-
type: "unknown"
|
|
77
|
-
};
|
|
78
|
-
let remoteShared = {};
|
|
79
|
-
const scripts = [];
|
|
80
|
-
const links = [];
|
|
81
|
-
const hydrationData = [];
|
|
82
|
-
let nextData;
|
|
83
|
-
let html = "";
|
|
84
230
|
const remoteName = options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : void 0);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
metadata = _metadata;
|
|
98
|
-
hasRemoteComponent = true;
|
|
99
|
-
},
|
|
100
|
-
onScript(attrs) {
|
|
101
|
-
const clientSrc = getClientSrc(attrs.src, serverUrl.href);
|
|
102
|
-
if (!scripts.find(
|
|
103
|
-
(it) => it.src === clientSrc || attrs.textContent && it.textContent === attrs.textContent
|
|
104
|
-
)) {
|
|
105
|
-
scripts.push(
|
|
106
|
-
typeof attrs.textContent === "string" ? {
|
|
107
|
-
src: "",
|
|
108
|
-
textContent: attrs.textContent
|
|
109
|
-
} : {
|
|
110
|
-
src: clientSrc
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
onLink(attrs) {
|
|
116
|
-
const relativeAttrs = {
|
|
117
|
-
...attrs,
|
|
118
|
-
href: getClientSrc(attrs.href, serverUrl.href)
|
|
119
|
-
};
|
|
120
|
-
if (!links.find(
|
|
121
|
-
(it) => it.href === relativeAttrs.href && it.rel === attrs.rel
|
|
122
|
-
)) {
|
|
123
|
-
links.push(relativeAttrs);
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
onRSC(chunk) {
|
|
127
|
-
hydrationData.push(chunk);
|
|
128
|
-
hasRSC = true;
|
|
129
|
-
},
|
|
130
|
-
onNextData(data) {
|
|
131
|
-
nextData = data;
|
|
132
|
-
if (data.props.__REMOTE_COMPONENT__) {
|
|
133
|
-
Object.assign(metadata, data.props.__REMOTE_COMPONENT__);
|
|
134
|
-
metadata.id = "__next";
|
|
135
|
-
metadata.route = data.page ?? "/";
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
onHTML(_html) {
|
|
139
|
-
if (!html.includes(_html)) {
|
|
140
|
-
html += _html;
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
onShared(_shared) {
|
|
144
|
-
remoteShared = _shared;
|
|
145
|
-
hasShared = true;
|
|
146
|
-
},
|
|
147
|
-
onError(message, stack) {
|
|
148
|
-
error = new RemoteComponentsError(message);
|
|
149
|
-
if (stack) {
|
|
150
|
-
error.stack = stack;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
if (error) {
|
|
155
|
-
throw error;
|
|
156
|
-
}
|
|
157
|
-
if (!hasRemoteComponent) {
|
|
231
|
+
const {
|
|
232
|
+
rsc,
|
|
233
|
+
metadata,
|
|
234
|
+
scripts,
|
|
235
|
+
links,
|
|
236
|
+
hydrationData,
|
|
237
|
+
nextData,
|
|
238
|
+
remoteShared,
|
|
239
|
+
html
|
|
240
|
+
} = visitFragment(fragment, serverUrl, remoteName);
|
|
241
|
+
if (!metadata) {
|
|
158
242
|
const isSSGBuild = process.env.NEXT_PHASE === "phase-production-build";
|
|
159
243
|
const isSSRRelativePathBase = serverUrl.host === new URL(ssrRelativePathBaseUrl).host;
|
|
160
244
|
const isPreview = process.env.VERCEL_TARGET_ENV === "preview";
|
|
161
245
|
if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {
|
|
162
|
-
const skeletonMessage = getSkeletonMessage();
|
|
163
|
-
const skeletonHtml = getSkeletonHtml(serverUrl.href);
|
|
164
246
|
let skeletonComponent;
|
|
165
247
|
if (options.rsc) {
|
|
166
248
|
const { createElement } = await import("react");
|
|
167
249
|
skeletonComponent = createElement("div", {
|
|
168
|
-
dangerouslySetInnerHTML: {
|
|
250
|
+
dangerouslySetInnerHTML: {
|
|
251
|
+
__html: getSkeletonHtml(serverUrl.href)
|
|
252
|
+
}
|
|
169
253
|
});
|
|
170
254
|
}
|
|
171
|
-
return
|
|
172
|
-
name: "remote-component-skeleton",
|
|
255
|
+
return buildSkeletonResponse(
|
|
173
256
|
serverUrl,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
rsc: skeletonMessage,
|
|
179
|
-
scripts: [],
|
|
180
|
-
links: [],
|
|
181
|
-
hydrationData: [],
|
|
182
|
-
nextData: void 0,
|
|
183
|
-
component: skeletonComponent,
|
|
184
|
-
html: skeletonHtml,
|
|
185
|
-
remoteShared: {}
|
|
186
|
-
};
|
|
257
|
+
buildMetadata({}, serverUrl),
|
|
258
|
+
skeletonComponent
|
|
259
|
+
);
|
|
187
260
|
}
|
|
188
261
|
throw failedToFetchRemoteComponentError(
|
|
189
262
|
serverUrl.href,
|
|
@@ -191,47 +264,10 @@ async function fetchRemoteComponent(src, options = {
|
|
|
191
264
|
`No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`
|
|
192
265
|
);
|
|
193
266
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
if (!hasRSC && !nextData && metadata.type === "nextjs") {
|
|
198
|
-
throw new RemoteComponentsError(
|
|
199
|
-
`The Remote Component at "${serverUrl.href}" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
if (metadata.type === "nextjs" && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
203
|
-
!hasShared && !nextData?.props.__REMOTE_COMPONENT__?.shared) {
|
|
204
|
-
throw new RemoteComponentsError(
|
|
205
|
-
`No shared dependencies found for Remote Component at "${serverUrl.href}". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
let component;
|
|
209
|
-
if (options.rsc) {
|
|
210
|
-
const componentRSC = `0:${JSON.stringify(rsc)}
|
|
211
|
-
`;
|
|
212
|
-
const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.edge");
|
|
213
|
-
component = await createFromReadableStream(
|
|
214
|
-
new ReadableStream({
|
|
215
|
-
type: "bytes",
|
|
216
|
-
start(controller) {
|
|
217
|
-
const encoder = new TextEncoder();
|
|
218
|
-
controller.enqueue(encoder.encode(componentRSC));
|
|
219
|
-
controller.close();
|
|
220
|
-
}
|
|
221
|
-
}),
|
|
222
|
-
{
|
|
223
|
-
serverConsumerManifest: {
|
|
224
|
-
moduleLoading: {
|
|
225
|
-
prefix: serverUrl.origin,
|
|
226
|
-
crossOrigin: true
|
|
227
|
-
},
|
|
228
|
-
moduleMap: {}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
);
|
|
232
|
-
}
|
|
267
|
+
const name = remoteName || metadata.name;
|
|
268
|
+
const component = options.rsc ? await buildRscComponent(rsc, serverUrl) : void 0;
|
|
233
269
|
return {
|
|
234
|
-
name
|
|
270
|
+
name,
|
|
235
271
|
serverUrl,
|
|
236
272
|
metadata,
|
|
237
273
|
rsc,
|
|
@@ -241,7 +277,7 @@ async function fetchRemoteComponent(src, options = {
|
|
|
241
277
|
nextData,
|
|
242
278
|
component,
|
|
243
279
|
html,
|
|
244
|
-
remoteShared
|
|
280
|
+
remoteShared
|
|
245
281
|
};
|
|
246
282
|
}
|
|
247
283
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { getSSRRelativePathBaseUrl } from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n } = {\n rsc: false,\n },\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n let metadata: RemoteComponentMetadata = {\n bundle: CURRENT_ZONE ?? '__vercel_remote_component',\n route: '/',\n runtime: 'webpack',\n id: '__vercel_remote_component',\n type: 'unknown',\n };\n let remoteShared: Record<string, string> = {};\n const scripts: ScriptDescriptor[] = [];\n const links: LinkDescriptor[] = [];\n const hydrationData: string[] = [];\n let nextData: NextData | undefined;\n let html = '';\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n // convert the parsed HTML fragment into an RSC flight data\n // and extract the metadata, scripts, links and remote component RSC flight data\n let hasRemoteComponent = false;\n let hasRSC = false;\n let hasShared = false;\n let hasMultipleRemoteComponents = false;\n let error: RemoteComponentsError | undefined;\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(_metadata) {\n // Skip multiple component detection for Pages Router (__next) since it only supports one remote component per page\n if (\n hasRemoteComponent &&\n metadata.id !== _metadata.id &&\n _metadata.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n hasMultipleRemoteComponents = true;\n }\n metadata = _metadata;\n hasRemoteComponent = true;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n if (\n !scripts.find(\n (it) =>\n it.src === clientSrc ||\n (attrs.textContent && it.textContent === attrs.textContent),\n )\n ) {\n scripts.push(\n typeof attrs.textContent === 'string'\n ? {\n src: '',\n textContent: attrs.textContent,\n }\n : {\n src: clientSrc,\n },\n );\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n if (\n !links.find(\n (it) => it.href === relativeAttrs.href && it.rel === attrs.rel,\n )\n ) {\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n hydrationData.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n\n // use the Next.js Pages Router props data to extract remote component metadata\n if (data.props.__REMOTE_COMPONENT__) {\n Object.assign(metadata, data.props.__REMOTE_COMPONENT__);\n // only a singleton remote component is supported per page when using the Next.js Pages Router\n metadata.id = '__next';\n metadata.route = data.page ?? '/';\n }\n },\n onHTML(_html) {\n if (!html.includes(_html)) {\n html += _html;\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n if (error) {\n throw error;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRemoteComponent) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n const skeletonMessage = getSkeletonMessage();\n const skeletonHtml = getSkeletonHtml(serverUrl.href);\n\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: { __html: skeletonHtml },\n });\n }\n\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: skeletonMessage,\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: skeletonHtml,\n remoteShared: {},\n };\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (hasMultipleRemoteComponents && !remoteName) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n\n let component: React.ReactNode | undefined;\n\n // only create a React component if requested\n if (options.rsc) {\n // RSC flight data for the static HTML in a single RSC line\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n\n // create a React tree from the RSC flight data\n component = await createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n }\n\n return {\n name: remoteName || metadata.id.replace(/_ssr$/, ''),\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared: nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,iCAAiC;AAU1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,eAAe,QAAQ,IAAI;AAEjC,eAAsB,qBACpB,KACA,UAOI;AAAA,EACF,KAAK;AACP,GACuC;AACvC,QAAM,yBAAyB,0BAA0B;AACzD,QAAM,YAAY,IAAI,IAAI,KAAK,sBAAsB;AAErD,QAAM,OAAO;AAAA,IACX;AAAA;AAAA,IAEA,UAAU,KAAK,MAAM,GAAG,GAAG;AAAA;AAAA;AAAA,KAG1B,OAAO,QAAQ,WAAW,MAAM,IAAI,MAAM,MAAM,IAAI;AAAA,EACvD;AACA,MAAI,QAAQ,MAAM;AAChB,SAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;AAAA,EACpC;AAEA,QAAM,YAAY;AAAA,IAChB,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,MAAM,eAAe,WAAW,WAAW;AAAA,IACrD,WAAW,QAAQ;AAAA,IACnB,YAAY,QAAQ;AAAA,EACtB,CAAC;AAGD,MAAI,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM;AACxB,UAAM,kCAAkC,UAAU,MAAM,GAAG;AAAA,EAC7D;AAEA,MAAI,IAAI,WAAW,KAAK;AACtB,UAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,I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AM,UAAU,IAAI,YAAY;AAChC,qBAAW,QAAQ,QAAQ,OAAO,YAAY,CAAC;AAC/C,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF,CAAC;AAAA,MACD;AAAA,QACE,wBAAwB;AAAA,UACtB,eAAe;AAAA,YACb,QAAQ,UAAU;AAAA,YAClB,aAAa;AAAA,UACf;AAAA,UACA,WAAW,CAAC;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM,cAAc,SAAS,GAAG,QAAQ,SAAS,EAAE;AAAA,IACnD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,UAAU,MAAM,sBAAsB,UAAU;AAAA,EAChE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/server/fetch-remote-component.ts"],"sourcesContent":["import { type DefaultTreeAdapterMap, Parser } from 'parse5';\nimport { type RSC, visit } from '#internal/host/nextjs/dom-flight';\nimport {\n getSkeletonHtml,\n getSkeletonMessage,\n} from '#internal/host/nextjs/skeleton';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientSrc } from '#internal/host/server/get-client-src';\nimport { getSSRRelativePathBaseUrl } from '#internal/host/server/get-ssr-relative-path-base-url';\nimport type {\n LinkDescriptor,\n ScriptDescriptor,\n} from '#internal/host/shared/asset-descriptors';\nimport type {\n OnRequestHook,\n OnResponseHook,\n} from '#internal/host/shared/fetch-interceptors';\nimport {\n buildMetadata,\n type RawMetadataAttrs,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport { computeScopedName } from '#internal/utils';\nimport {\n failedToFetchRemoteComponentError,\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport type { FetchRemoteComponentResponse, NextData } from './types';\n\n/**\n * Converts RSC flight data into a React element tree using the edge streaming\n * runtime. The manifest tells React how to resolve module references back to\n * the remote origin.\n */\nasync function buildRscComponent(\n rsc: RSC | RSC[] | string | null,\n serverUrl: URL,\n): Promise<React.ReactNode> {\n const componentRSC = `0:${JSON.stringify(rsc)}\\n`;\n const { createFromReadableStream } = await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n return createFromReadableStream(\n new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n controller.enqueue(encoder.encode(componentRSC));\n controller.close();\n },\n }),\n {\n serverConsumerManifest: {\n moduleLoading: {\n prefix: serverUrl.origin,\n crossOrigin: true,\n },\n moduleMap: {},\n },\n },\n );\n}\n\nfunction buildSkeletonResponse(\n serverUrl: URL,\n metadata: RemoteComponentMetadata,\n skeletonComponent: React.ReactNode | undefined,\n): FetchRemoteComponentResponse {\n return {\n name: 'remote-component-skeleton',\n serverUrl,\n metadata: {\n ...metadata,\n type: 'remote-component',\n },\n rsc: getSkeletonMessage(),\n scripts: [],\n links: [],\n hydrationData: [],\n nextData: undefined,\n component: skeletonComponent,\n html: getSkeletonHtml(serverUrl.href),\n remoteShared: {},\n };\n}\n\n/**\n * Rewrites the bundle identifier in RSC flight data from the plain bundle\n * name to the origin-qualified scoped name. When multiple remotes share the\n * same bundle name (e.g. production and preview of the same app), this\n * makes each one unique so the client can look up the correct RemoteScope\n * by name alone.\n *\n * `[bundle] /path` → `[scopedName] /path`\n * `[bundle] 12345` → `[scopedName] 12345`\n *\n * Only applied for cross-origin remotes — same-origin chunks keep the\n * plain bundle name since there's no ambiguity.\n */\nfunction scopeChunkReferences(\n chunk: string,\n bundle: string,\n scopedName: string,\n): string {\n return chunk.replaceAll(`[${bundle}]`, `[${scopedName}]`);\n}\n\n/**\n * Walks the parsed HTML fragment and extracts all remote component data:\n * metadata, scripts, links, hydration data, Next.js data, shared deps, and HTML.\n */\nfunction visitFragment(\n fragment: DefaultTreeAdapterMap['documentFragment'],\n serverUrl: URL,\n remoteName: string | undefined,\n) {\n const scriptSrcSet = new Set<string>();\n const scriptTextSet = new Set<string>();\n const scripts: ScriptDescriptor[] = [];\n\n const linkKeySet = new Set<string>();\n const links: LinkDescriptor[] = [];\n\n const hydrationData: string[] = [];\n const htmlChunks = new Set<string>();\n\n let metadata: RemoteComponentMetadata | undefined;\n let nextData: NextData | undefined;\n let remoteShared: Record<string, string> = {};\n let hasRSC = false;\n let hasShared = false;\n let error: RemoteComponentsError | undefined;\n\n // For cross-origin remotes, rewrite bundle identifiers in RSC chunks to\n // the scoped name so the client dispatchers resolve the correct scope.\n // Chunks are collected raw during visit() and rewritten afterwards because\n // RSC script tags appear before the metadata element in the HTML.\n const isCrossOrigin = serverUrl.origin !== getSSRRelativePathBaseUrl();\n\n const rawRscChunks: string[] = [];\n\n const rsc = visit(fragment, {\n url: serverUrl,\n name: remoteName,\n onMetadata(attrs: RawMetadataAttrs) {\n const incoming = buildMetadata(attrs, serverUrl);\n // Skip multiple component detection for Pages Router (__next) since\n // it only supports one remote component per page\n if (\n !remoteName &&\n metadata &&\n metadata.id !== incoming.id &&\n incoming.id !== '__next' &&\n metadata.id !== '__next' &&\n !nextData\n ) {\n throw multipleRemoteComponentsError(serverUrl.href);\n }\n metadata = incoming;\n },\n onScript(attrs) {\n const clientSrc = getClientSrc(attrs.src, serverUrl.href);\n const textContent =\n typeof attrs.textContent === 'string' ? attrs.textContent : undefined;\n\n if (textContent) {\n if (!scriptTextSet.has(textContent)) {\n scriptTextSet.add(textContent);\n scripts.push({ src: '', textContent });\n }\n } else if (!scriptSrcSet.has(clientSrc)) {\n scriptSrcSet.add(clientSrc);\n scripts.push({ src: clientSrc });\n }\n },\n onLink(attrs) {\n const relativeAttrs = {\n ...attrs,\n href: getClientSrc(attrs.href, serverUrl.href),\n };\n const linkKey = `${relativeAttrs.href}::${attrs.rel}`;\n if (!linkKeySet.has(linkKey)) {\n linkKeySet.add(linkKey);\n links.push(relativeAttrs);\n }\n },\n onRSC(chunk) {\n rawRscChunks.push(chunk);\n hasRSC = true;\n },\n onNextData(data) {\n nextData = data;\n },\n onHTML(chunk) {\n if (!htmlChunks.has(chunk)) {\n htmlChunks.add(chunk);\n }\n },\n onShared(_shared) {\n remoteShared = _shared;\n hasShared = true;\n },\n onError(message, stack) {\n error = new RemoteComponentsError(message);\n if (stack) {\n error.stack = stack;\n }\n },\n });\n\n // Rewrite bundle identifiers in RSC chunk references to use the scoped name\n // so the client dispatchers can resolve the correct scope with a direct lookup.\n // This must happen after visit() because RSC script tags appear before the\n // metadata element in the HTML.\n if (isCrossOrigin && metadata?.bundle) {\n const scopedName = computeScopedName(metadata.bundle, {\n remoteHost: serverUrl.host,\n isCrossOrigin: true,\n });\n for (const chunk of rawRscChunks) {\n hydrationData.push(\n scopeChunkReferences(chunk, metadata.bundle, scopedName),\n );\n }\n } else {\n hydrationData.push(...rawRscChunks);\n }\n\n if (error) {\n throw error;\n }\n\n if (metadata) {\n if (!hasRSC && !nextData && metadata.type === 'nextjs') {\n throw new RemoteComponentsError(\n `The Remote Component at \"${serverUrl.href}\" seems to be a Next.js component but it does not contain any RSC flight data or Next.js props data. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n if (\n metadata.type === 'nextjs' &&\n !hasShared &&\n !nextData?.props.__REMOTE_COMPONENT__?.shared\n ) {\n throw new RemoteComponentsError(\n `No shared dependencies found for Remote Component at \"${serverUrl.href}\". Make sure the remote URL is correct and contains a Remote Component with shared dependencies.`,\n );\n }\n }\n\n const resolvedShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ?? remoteShared;\n\n return {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared: resolvedShared,\n html: Array.from(htmlChunks).join(''),\n };\n}\n\nexport async function fetchRemoteComponent(\n src: string | URL,\n options: {\n name?: string;\n rsc?: boolean;\n /** Whether this is being called from Next.js App Router. Used to enable skeleton fallback during SSG builds. */\n appRouter?: boolean;\n onRequest?: OnRequestHook;\n onResponse?: OnResponseHook;\n } = {},\n): Promise<FetchRemoteComponentResponse> {\n const ssrRelativePathBaseUrl = getSSRRelativePathBaseUrl();\n const serverUrl = new URL(src, ssrRelativePathBaseUrl);\n\n const tags = [\n '_vc_rc:fetch-remote-component',\n // the max size of a next cache tag is 256 characters\n serverUrl.host.slice(0, 256),\n // use the suffix so this tag is unique if multiple remote\n // components have the same host, but unique pathnames / query params\n (typeof src === 'string' ? src : src.href).slice(-256),\n ];\n if (options.name) {\n tags.push(options.name.slice(-256));\n }\n\n const fetchInit = {\n next: {\n tags,\n },\n };\n\n const res = await fetchWithHooks(serverUrl, fetchInit, {\n onRequest: options.onRequest,\n onResponse: options.onResponse,\n });\n\n // If there is an error in the remote, parse and extract the remote error (except 404 and 401).\n if (!res.ok && !res.body) {\n throw failedToFetchRemoteComponentError(serverUrl.href, res);\n }\n\n if (res.status === 401) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'If you are using Deployment Protection, ensure the automation bypass environment variable secret in the host matches an automation bypass value in the remote. See https://remote-components-docs.vercel.sh/docs/concepts/cors-external-urls#deployment-protection for details.',\n );\n }\n\n if (res.status === 404) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n 'Check if you can open it in the browser.',\n );\n }\n\n // create a parser for the HTML response\n const parser = Parser.getFragmentParser<DefaultTreeAdapterMap>();\n\n if (!res.body) {\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `Response body is empty. Check if you can open it in the browser and you see the Remote Component content.`,\n );\n }\n\n const decoder = new TextDecoder();\n // read the response body as a stream and parse it using the parse5 fragment parser\n for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {\n parser.tokenizer.write(decoder.decode(chunk), false);\n }\n const fragment = parser.getFragment();\n\n const remoteName =\n options.name || (serverUrl.hash ? serverUrl.hash.substring(1) : undefined);\n\n const {\n rsc,\n metadata,\n scripts,\n links,\n hydrationData,\n nextData,\n remoteShared,\n html,\n } = visitFragment(fragment, serverUrl, remoteName);\n\n if (!metadata) {\n // For microfrontend builds during run time, the host and remote build\n // may be happening concurrently. In this case, the request will 404.\n // We want to allow the build to continue with a placeholder remote\n // component. Once the build completes, vercel will automatically revalidate\n // ISR and fetch the built remote component.\n const isSSGBuild = process.env.NEXT_PHASE === 'phase-production-build';\n // If the remote component is part of a microfrontend, the src provided\n // will be relative.\n const isSSRRelativePathBase =\n serverUrl.host === new URL(ssrRelativePathBaseUrl).host;\n // Only want this skeleton behaviour in previews to unblock development.\n // For production, the remote component should already be built.\n const isPreview = process.env.VERCEL_TARGET_ENV === 'preview';\n\n if (isSSGBuild && isSSRRelativePathBase && isPreview && options.appRouter) {\n let skeletonComponent: React.ReactNode | undefined;\n if (options.rsc) {\n const { createElement } = await import('react');\n skeletonComponent = createElement('div', {\n dangerouslySetInnerHTML: {\n __html: getSkeletonHtml(serverUrl.href),\n },\n });\n }\n\n return buildSkeletonResponse(\n serverUrl,\n buildMetadata({}, serverUrl),\n skeletonComponent,\n );\n }\n\n throw failedToFetchRemoteComponentError(\n serverUrl.href,\n res,\n `No Remote Component found. Make sure the remote URL is correct and contains a Remote Component.`,\n );\n }\n\n const name = remoteName || metadata.name;\n const component = options.rsc\n ? await buildRscComponent(rsc, serverUrl)\n : undefined;\n\n return {\n name,\n serverUrl,\n metadata,\n rsc,\n scripts,\n links,\n hydrationData,\n nextData,\n component,\n html,\n remoteShared,\n };\n}\n"],"mappings":"AAAA,SAAqC,cAAc;AACnD,SAAmB,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,iCAAiC;AAS1C;AAAA,EACE;AAAA,OAGK;AACP,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,eAAe,kBACb,KACA,WAC0B;AAC1B,QAAM,eAAe,KAAK,KAAK,UAAU,GAAG;AAAA;AAC5C,QAAM,EAAE,yBAAyB,IAAI,MAAM,OACzC,yDACF;AACA,SAAO;AAAA,IACL,IAAI,eAA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,IAAI,sBAAsB;AAEpD,QAAI,cAAc,yBAAyB,aAAa,QAAQ,WAAW;AACzE,UAAI;AACJ,UAAI,QAAQ,KAAK;AACf,cAAM,EAAE,cAAc,IAAI,MAAM,OAAO,OAAO;AAC9C,4BAAoB,cAAc,OAAO;AAAA,UACvC,yBAAyB;AAAA,YACvB,QAAQ,gBAAgB,UAAU,IAAI;AAAA,UACxC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL;AAAA,QACA,cAAc,CAAC,GAAG,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,cAAc,SAAS;AACpC,QAAM,YAAY,QAAQ,MACtB,MAAM,kBAAkB,KAAK,SAAS,IACtC;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -21,10 +21,7 @@ __export(remote_image_loader_exports, {
|
|
|
21
21
|
createRemoteImageLoader: () => createRemoteImageLoader
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(remote_image_loader_exports);
|
|
24
|
-
|
|
25
|
-
const self = globalThis;
|
|
26
|
-
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
27
|
-
}
|
|
24
|
+
var import_remote_scope = require("#internal/runtime/turbopack/remote-scope");
|
|
28
25
|
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
29
26
|
const loader = Object.assign(
|
|
30
27
|
({
|
|
@@ -34,7 +31,7 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
|
34
31
|
quality
|
|
35
32
|
}) => {
|
|
36
33
|
const q = quality ?? 75;
|
|
37
|
-
const remoteOrigin =
|
|
34
|
+
const remoteOrigin = (0, import_remote_scope.getScope)(bundle)?.url.origin ?? "";
|
|
38
35
|
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
39
36
|
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
40
37
|
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\n/**\n * Replacement for `next/dist/shared/lib/image-loader`.\n *\n * Uses `config.path` (which includes the remote's asset prefix, e.g.\n * `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered\n * HTML and avoid hydration mismatches. Under the microfrontends proxy these\n * relative paths are routed to the correct app.\n *\n * For cross-origin deployments (standalone host on a different domain),\n * `config.path` is a relative path that would incorrectly resolve to the host\n * origin, so we prefix it with the remote origin to produce an absolute URL\n * pointing at the remote's optimizer.\n *\n * When `resolveClientUrl` is provided (deployment protection), the final URL\n * is routed through the host's proxy.\n */\nexport function createRemoteImageLoader(\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const loader = Object.assign(\n ({\n config,\n src,\n width,\n quality,\n }: {\n config: { path?: string };\n src: string;\n width: number;\n quality?: number;\n }) => {\n const q = quality ?? 75;\n const remoteOrigin = getScope(bundle)?.url.origin ?? '';\n const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;\n const basePath = isCrossOrigin\n ? `${remoteOrigin}${config.path ?? '/_next/image'}`\n : (config.path ?? `${remoteOrigin}/_next/image`);\n const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;\n return resolveClientUrl?.(url) ?? url;\n },\n // Signals to getImgProps that this is a default loader (not a user-defined\n // one), enabling srcSet generation with device/image sizes from the config.\n { __next_img_default: true as const },\n );\n return loader;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAyB;AAmBlB,SAAS,wBACd,QACA,kBACA;AACA,QAAM,SAAS,OAAO;AAAA,IACpB,CAAC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,MAKM;AACJ,YAAM,IAAI,WAAW;AACrB,YAAM,mBAAe,8BAAS,MAAM,GAAG,IAAI,UAAU;AACrD,YAAM,gBAAgB,gBAAgB,iBAAiB,SAAS;AAChE,YAAM,WAAW,gBACb,GAAG,eAAe,OAAO,QAAQ,mBAChC,OAAO,QAAQ,GAAG;AACvB,YAAM,MAAM,GAAG,gBAAgB,mBAAmB,GAAG,OAAO,WAAW;AACvE,aAAO,mBAAmB,GAAG,KAAK;AAAA,IACpC;AAAA;AAAA;AAAA,IAGA,EAAE,oBAAoB,KAAc;AAAA,EACtC;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const self = globalThis;
|
|
3
|
-
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
4
|
-
}
|
|
1
|
+
import { getScope } from "#internal/runtime/turbopack/remote-scope";
|
|
5
2
|
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
6
3
|
const loader = Object.assign(
|
|
7
4
|
({
|
|
@@ -11,7 +8,7 @@ function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
|
11
8
|
quality
|
|
12
9
|
}) => {
|
|
13
10
|
const q = quality ?? 75;
|
|
14
|
-
const remoteOrigin =
|
|
11
|
+
const remoteOrigin = getScope(bundle)?.url.origin ?? "";
|
|
15
12
|
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
16
13
|
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
17
14
|
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import { getScope } from '#internal/runtime/turbopack/remote-scope';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\n/**\n * Replacement for `next/dist/shared/lib/image-loader`.\n *\n * Uses `config.path` (which includes the remote's asset prefix, e.g.\n * `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered\n * HTML and avoid hydration mismatches. Under the microfrontends proxy these\n * relative paths are routed to the correct app.\n *\n * For cross-origin deployments (standalone host on a different domain),\n * `config.path` is a relative path that would incorrectly resolve to the host\n * origin, so we prefix it with the remote origin to produce an absolute URL\n * pointing at the remote's optimizer.\n *\n * When `resolveClientUrl` is provided (deployment protection), the final URL\n * is routed through the host's proxy.\n */\nexport function createRemoteImageLoader(\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const loader = Object.assign(\n ({\n config,\n src,\n width,\n quality,\n }: {\n config: { path?: string };\n src: string;\n width: number;\n quality?: number;\n }) => {\n const q = quality ?? 75;\n const remoteOrigin = getScope(bundle)?.url.origin ?? '';\n const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;\n const basePath = isCrossOrigin\n ? `${remoteOrigin}${config.path ?? '/_next/image'}`\n : (config.path ?? `${remoteOrigin}/_next/image`);\n const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;\n return resolveClientUrl?.(url) ?? url;\n },\n // Signals to getImgProps that this is a default loader (not a user-defined\n // one), enabling srcSet generation with device/image sizes from the config.\n { __next_img_default: true as const },\n );\n return loader;\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AAmBlB,SAAS,wBACd,QACA,kBACA;AACA,QAAM,SAAS,OAAO;AAAA,IACpB,CAAC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,MAKM;AACJ,YAAM,IAAI,WAAW;AACrB,YAAM,eAAe,SAAS,MAAM,GAAG,IAAI,UAAU;AACrD,YAAM,gBAAgB,gBAAgB,iBAAiB,SAAS;AAChE,YAAM,WAAW,gBACb,GAAG,eAAe,OAAO,QAAQ,mBAChC,OAAO,QAAQ,GAAG;AACvB,YAAM,MAAM,GAAG,gBAAgB,mBAAmB,GAAG,OAAO,WAAW;AACvE,aAAO,mBAAmB,GAAG,KAAK;AAAA,IACpC;AAAA;AAAA;AAAA,IAGA,EAAE,oBAAoB,KAAc;AAAA,EACtC;AACA,SAAO;AACT;","names":[]}
|
|
@@ -18,9 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constants_exports = {};
|
|
20
20
|
__export(constants_exports, {
|
|
21
|
+
DEFAULT_BUNDLE_NAME: () => DEFAULT_BUNDLE_NAME,
|
|
22
|
+
DEFAULT_COMPONENT_NAME: () => DEFAULT_COMPONENT_NAME,
|
|
21
23
|
DEFAULT_ROUTE: () => DEFAULT_ROUTE,
|
|
22
|
-
NEXT_BUNDLE_PATH_RE: () => NEXT_BUNDLE_PATH_RE,
|
|
23
|
-
REMOTE_COMPONENT_REGEX: () => REMOTE_COMPONENT_REGEX,
|
|
24
24
|
RUNTIME_SCRIPT: () => RUNTIME_SCRIPT,
|
|
25
25
|
RUNTIME_TURBOPACK: () => RUNTIME_TURBOPACK,
|
|
26
26
|
RUNTIME_WEBPACK: () => RUNTIME_WEBPACK,
|
|
@@ -28,20 +28,20 @@ __export(constants_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(constants_exports);
|
|
30
30
|
var import_utils = require("#internal/utils");
|
|
31
|
+
const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
32
|
+
const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
31
33
|
const DEFAULT_ROUTE = "/";
|
|
32
34
|
const RUNTIME_WEBPACK = "webpack";
|
|
33
35
|
const RUNTIME_TURBOPACK = "turbopack";
|
|
34
36
|
const RUNTIME_SCRIPT = "script";
|
|
35
|
-
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
36
|
-
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
37
37
|
function getBundleKey(bundle) {
|
|
38
38
|
return (0, import_utils.escapeString)(bundle);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
41
|
0 && (module.exports = {
|
|
42
|
+
DEFAULT_BUNDLE_NAME,
|
|
43
|
+
DEFAULT_COMPONENT_NAME,
|
|
42
44
|
DEFAULT_ROUTE,
|
|
43
|
-
NEXT_BUNDLE_PATH_RE,
|
|
44
|
-
REMOTE_COMPONENT_REGEX,
|
|
45
45
|
RUNTIME_SCRIPT,
|
|
46
46
|
RUNTIME_TURBOPACK,
|
|
47
47
|
RUNTIME_WEBPACK,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const DEFAULT_BUNDLE_NAME = '__vercel_remote_bundle';\nexport const DEFAULT_COMPONENT_NAME = '__vercel_remote_component';\nexport const DEFAULT_ROUTE = '/';\n\nexport const RUNTIME_WEBPACK = 'webpack';\nexport const RUNTIME_TURBOPACK = 'turbopack';\nexport const RUNTIME_SCRIPT = 'script';\n\nexport function getBundleKey(bundle: string): string {\n return escapeString(bundle);\n}\n\nexport type Runtime =\n | typeof RUNTIME_WEBPACK\n | typeof RUNTIME_TURBOPACK\n | typeof RUNTIME_SCRIPT;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6B;AAEtB,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,gBAAgB;AAEtB,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AAEvB,SAAS,aAAa,QAAwB;AACnD,aAAO,2BAAa,MAAM;AAC5B;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
declare const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
2
|
+
declare const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
1
3
|
declare const DEFAULT_ROUTE = "/";
|
|
2
4
|
declare const RUNTIME_WEBPACK = "webpack";
|
|
3
5
|
declare const RUNTIME_TURBOPACK = "turbopack";
|
|
4
6
|
declare const RUNTIME_SCRIPT = "script";
|
|
5
|
-
declare const REMOTE_COMPONENT_REGEX: RegExp;
|
|
6
|
-
declare const NEXT_BUNDLE_PATH_RE: RegExp;
|
|
7
7
|
declare function getBundleKey(bundle: string): string;
|
|
8
8
|
type Runtime = typeof RUNTIME_WEBPACK | typeof RUNTIME_TURBOPACK | typeof RUNTIME_SCRIPT;
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { DEFAULT_BUNDLE_NAME, DEFAULT_COMPONENT_NAME, DEFAULT_ROUTE, RUNTIME_SCRIPT, RUNTIME_TURBOPACK, RUNTIME_WEBPACK, Runtime, getBundleKey };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { escapeString } from "#internal/utils";
|
|
2
|
+
const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
3
|
+
const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
2
4
|
const DEFAULT_ROUTE = "/";
|
|
3
5
|
const RUNTIME_WEBPACK = "webpack";
|
|
4
6
|
const RUNTIME_TURBOPACK = "turbopack";
|
|
5
7
|
const RUNTIME_SCRIPT = "script";
|
|
6
|
-
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
7
|
-
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
8
8
|
function getBundleKey(bundle) {
|
|
9
9
|
return escapeString(bundle);
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
12
|
+
DEFAULT_BUNDLE_NAME,
|
|
13
|
+
DEFAULT_COMPONENT_NAME,
|
|
12
14
|
DEFAULT_ROUTE,
|
|
13
|
-
NEXT_BUNDLE_PATH_RE,
|
|
14
|
-
REMOTE_COMPONENT_REGEX,
|
|
15
15
|
RUNTIME_SCRIPT,
|
|
16
16
|
RUNTIME_TURBOPACK,
|
|
17
17
|
RUNTIME_WEBPACK,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const DEFAULT_BUNDLE_NAME = '__vercel_remote_bundle';\nexport const DEFAULT_COMPONENT_NAME = '__vercel_remote_component';\nexport const DEFAULT_ROUTE = '/';\n\nexport const RUNTIME_WEBPACK = 'webpack';\nexport const RUNTIME_TURBOPACK = 'turbopack';\nexport const RUNTIME_SCRIPT = 'script';\n\nexport function getBundleKey(bundle: string): string {\n return escapeString(bundle);\n}\n\nexport type Runtime =\n | typeof RUNTIME_WEBPACK\n | typeof RUNTIME_TURBOPACK\n | typeof RUNTIME_SCRIPT;\n"],"mappings":"AAAA,SAAS,oBAAoB;AAEtB,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,gBAAgB;AAEtB,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AAEvB,SAAS,aAAa,QAAwB;AACnD,SAAO,aAAa,MAAM;AAC5B;","names":[]}
|