remote-components 0.3.5 → 0.3.7
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/app-63L5THIQ.js +12 -0
- package/dist/app-63L5THIQ.js.map +1 -0
- package/dist/app-A5QE7XRH.cjs +12 -0
- package/dist/app-A5QE7XRH.cjs.map +1 -0
- package/dist/chunk-52BJ7VFA.js +202 -0
- package/dist/chunk-52BJ7VFA.js.map +1 -0
- package/dist/chunk-AWWWK2ZY.cjs +670 -0
- package/dist/chunk-AWWWK2ZY.cjs.map +1 -0
- package/dist/chunk-CTUJSWCM.js +215 -0
- package/dist/chunk-CTUJSWCM.js.map +1 -0
- package/dist/chunk-D5GNZB6O.js +61 -0
- package/dist/chunk-D5GNZB6O.js.map +1 -0
- package/dist/chunk-ENYGL5CO.js +11 -0
- package/dist/chunk-ENYGL5CO.js.map +1 -0
- package/dist/chunk-GAXJTFBV.js +20 -0
- package/dist/chunk-GAXJTFBV.js.map +1 -0
- package/dist/chunk-GBFUPMMI.js +670 -0
- package/dist/chunk-GBFUPMMI.js.map +1 -0
- package/dist/chunk-I47KE3EC.cjs +703 -0
- package/dist/chunk-I47KE3EC.cjs.map +1 -0
- package/dist/chunk-KE7QPAQ4.cjs +21 -0
- package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
- package/dist/chunk-LCXO7BUY.cjs +57 -0
- package/dist/chunk-LCXO7BUY.cjs.map +1 -0
- package/dist/chunk-LQ7VQ74E.js +155 -0
- package/dist/chunk-LQ7VQ74E.js.map +1 -0
- package/dist/chunk-N5VQR2PW.cjs +215 -0
- package/dist/chunk-N5VQR2PW.cjs.map +1 -0
- package/dist/chunk-NZAB7REE.js +703 -0
- package/dist/chunk-NZAB7REE.js.map +1 -0
- package/dist/chunk-QKB74MLO.js +709 -0
- package/dist/chunk-QKB74MLO.js.map +1 -0
- package/dist/chunk-RJW3EZJP.cjs +709 -0
- package/dist/chunk-RJW3EZJP.cjs.map +1 -0
- package/dist/chunk-RUWR74XQ.cjs +152 -0
- package/dist/chunk-RUWR74XQ.cjs.map +1 -0
- package/dist/chunk-S2A4TFLS.js +152 -0
- package/dist/chunk-S2A4TFLS.js.map +1 -0
- package/dist/chunk-SHFJ5OQA.cjs +11 -0
- package/dist/chunk-SHFJ5OQA.cjs.map +1 -0
- package/dist/chunk-SJM7AAGU.js +358 -0
- package/dist/chunk-SJM7AAGU.js.map +1 -0
- package/dist/chunk-SZFCBE54.js +57 -0
- package/dist/chunk-SZFCBE54.js.map +1 -0
- package/dist/chunk-T64P7BAG.cjs +202 -0
- package/dist/chunk-T64P7BAG.cjs.map +1 -0
- package/dist/chunk-TCFLEBQM.cjs +20 -0
- package/dist/chunk-TCFLEBQM.cjs.map +1 -0
- package/dist/chunk-TZT7DLO5.cjs +155 -0
- package/dist/chunk-TZT7DLO5.cjs.map +1 -0
- package/dist/chunk-X6W464D6.cjs +358 -0
- package/dist/chunk-X6W464D6.cjs.map +1 -0
- package/dist/chunk-X6YKUJKH.js +21 -0
- package/dist/chunk-X6YKUJKH.js.map +1 -0
- package/dist/chunk-Z2SLBFQL.cjs +61 -0
- package/dist/chunk-Z2SLBFQL.cjs.map +1 -0
- package/dist/config/nextjs.cjs +74 -355
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +25 -271
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +12 -240
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +6 -207
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/html.cjs +128 -2494
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +45 -2382
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +53 -2939
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +31 -2894
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/proxy/client.cjs +8 -38
- package/dist/host/proxy/client.cjs.map +1 -1
- package/dist/host/proxy/client.js +4 -7
- package/dist/host/proxy/client.js.map +1 -1
- package/dist/host/proxy.cjs +19 -56
- package/dist/host/proxy.cjs.map +1 -1
- package/dist/host/proxy.js +8 -20
- package/dist/host/proxy.js.map +1 -1
- package/dist/host/react.cjs +17 -2870
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +13 -2837
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.d.ts +3 -5
- package/dist/internal/config/webpack/next-client-pages-loader.js +27 -15
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.d.ts +1 -1
- package/dist/internal/host/react/context.d.ts +2 -2
- package/dist/internal/host/server/fetch-remote-component.cjs +1 -18
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +1 -18
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/pipeline.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +2 -2
- package/dist/internal/runtime/loaders/component-loader.js +5 -2
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +2 -1
- package/dist/internal/runtime/namespace.cjs +1 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -1
- package/dist/internal/runtime/namespace.d.ts +2 -1
- package/dist/internal/runtime/namespace.js +1 -0
- package/dist/internal/runtime/namespace.js.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/types.d.ts +2 -1
- package/dist/internal/utils.cjs +1 -1
- package/dist/internal/utils.cjs.map +1 -1
- package/dist/internal/utils.d.ts +5 -5
- package/dist/internal/utils.js +1 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/remote/html.cjs +15 -314
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +7 -305
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/middleware.cjs +16 -41
- package/dist/remote/middleware.cjs.map +1 -1
- package/dist/script-D5AD7HLV.cjs +26 -0
- package/dist/script-D5AD7HLV.cjs.map +1 -0
- package/dist/script-VPOI7ARP.js +26 -0
- package/dist/script-VPOI7ARP.js.map +1 -0
- package/dist/{server-handoff-ce13bebc.d.ts → server-handoff-8c89b856.d.ts} +2 -2
- package/dist/static-loader-OHSAUD62.js +11 -0
- package/dist/static-loader-OHSAUD62.js.map +1 -0
- package/dist/static-loader-UDIXK5MV.cjs +11 -0
- package/dist/static-loader-UDIXK5MV.cjs.map +1 -0
- package/dist/turbopack-5LW6V6IT.js +55 -0
- package/dist/turbopack-5LW6V6IT.js.map +1 -0
- package/dist/turbopack-KRKECGY2.cjs +55 -0
- package/dist/turbopack-KRKECGY2.cjs.map +1 -0
- package/dist/{types-59251814.d.ts → types-8b0edd78.d.ts} +7 -0
- package/dist/webpack-NPZNXRNL.js +92 -0
- package/dist/webpack-NPZNXRNL.js.map +1 -0
- package/dist/webpack-TTZDARNY.cjs +92 -0
- package/dist/webpack-TTZDARNY.cjs.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadScripts
|
|
3
|
+
} from "./chunk-SZFCBE54.js";
|
|
4
|
+
import {
|
|
5
|
+
initializeSharedModules,
|
|
6
|
+
setupRemoteScope
|
|
7
|
+
} from "./chunk-QKB74MLO.js";
|
|
8
|
+
import {
|
|
9
|
+
applySharedModules,
|
|
10
|
+
nextClientPagesLoader
|
|
11
|
+
} from "./chunk-52BJ7VFA.js";
|
|
12
|
+
import {
|
|
13
|
+
loadStaticRemoteComponent
|
|
14
|
+
} from "./chunk-LQ7VQ74E.js";
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_BUNDLE_NAME,
|
|
17
|
+
DEFAULT_COMPONENT_NAME,
|
|
18
|
+
DEFAULT_ROUTE,
|
|
19
|
+
REMOTE_COMPONENT_REGEX,
|
|
20
|
+
RUNTIME_SCRIPT,
|
|
21
|
+
buildCoreShared,
|
|
22
|
+
buildHostShared,
|
|
23
|
+
buildWebpackResolve,
|
|
24
|
+
collapseDoubleSlashes,
|
|
25
|
+
escapeString
|
|
26
|
+
} from "./chunk-SJM7AAGU.js";
|
|
27
|
+
import {
|
|
28
|
+
RemoteComponentsError,
|
|
29
|
+
logDebug,
|
|
30
|
+
logWarn,
|
|
31
|
+
multipleRemoteComponentsError,
|
|
32
|
+
warnCrossOriginFetchError
|
|
33
|
+
} from "./chunk-S2A4TFLS.js";
|
|
34
|
+
import {
|
|
35
|
+
remoteFetchHeaders
|
|
36
|
+
} from "./chunk-GAXJTFBV.js";
|
|
37
|
+
|
|
38
|
+
// src/host/server/fetch-with-hooks.ts
|
|
39
|
+
async function fetchWithWarning(url, init) {
|
|
40
|
+
try {
|
|
41
|
+
return await fetch(url, init);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
48
|
+
const {
|
|
49
|
+
onRequest,
|
|
50
|
+
onResponse,
|
|
51
|
+
abortController = new AbortController()
|
|
52
|
+
} = options;
|
|
53
|
+
const signal = abortController.signal;
|
|
54
|
+
const hookOptions = {
|
|
55
|
+
signal,
|
|
56
|
+
abort: (reason) => abortController.abort(reason)
|
|
57
|
+
};
|
|
58
|
+
const init = {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers: remoteFetchHeaders(),
|
|
61
|
+
signal,
|
|
62
|
+
...additionalInit
|
|
63
|
+
};
|
|
64
|
+
const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
|
|
65
|
+
return await onResponse?.(url, res, hookOptions) ?? res;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/host/server/get-client-or-server-url.ts
|
|
69
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
70
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
71
|
+
if (!src) {
|
|
72
|
+
return new URL(fallback);
|
|
73
|
+
}
|
|
74
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/host/shared/lifecycle.ts
|
|
78
|
+
function makeReactEmitter(callbacks) {
|
|
79
|
+
return {
|
|
80
|
+
beforeLoad(src) {
|
|
81
|
+
callbacks.onBeforeLoad?.(src);
|
|
82
|
+
},
|
|
83
|
+
load(src) {
|
|
84
|
+
callbacks.onLoad?.(src);
|
|
85
|
+
},
|
|
86
|
+
error(error, _src) {
|
|
87
|
+
callbacks.onError?.(error);
|
|
88
|
+
},
|
|
89
|
+
change(info) {
|
|
90
|
+
callbacks.onChange?.(info);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function makeEventEmitter(element) {
|
|
95
|
+
function dispatch(type, detail) {
|
|
96
|
+
const event = new Event(type, { bubbles: true, composed: true });
|
|
97
|
+
if (detail) {
|
|
98
|
+
Object.assign(event, detail);
|
|
99
|
+
}
|
|
100
|
+
element.dispatchEvent(event);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
beforeLoad(src) {
|
|
104
|
+
dispatch("beforeload", { src });
|
|
105
|
+
},
|
|
106
|
+
load(src) {
|
|
107
|
+
dispatch("load", { src });
|
|
108
|
+
},
|
|
109
|
+
error(error, src) {
|
|
110
|
+
dispatch("error", src != null ? { error, src } : { error });
|
|
111
|
+
},
|
|
112
|
+
change(info) {
|
|
113
|
+
dispatch("change", info);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/runtime/rsc.ts
|
|
119
|
+
import { ReadableStream } from "web-streams-polyfill";
|
|
120
|
+
function fixPayload(payload) {
|
|
121
|
+
if (Array.isArray(payload)) {
|
|
122
|
+
if (payload[0] === "$") {
|
|
123
|
+
fixPayload(payload[3]);
|
|
124
|
+
if (payload.length === 4) {
|
|
125
|
+
payload.push(null, null, 1);
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
for (const item of payload) {
|
|
129
|
+
fixPayload(item);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else if (typeof payload === "object" && payload !== null) {
|
|
133
|
+
for (const key in payload) {
|
|
134
|
+
fixPayload(payload[key]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function buildRSCChunks(rscName, data) {
|
|
139
|
+
const chunks = [];
|
|
140
|
+
for (const chunk of data) {
|
|
141
|
+
for (const line of chunk.split("\n")) {
|
|
142
|
+
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
143
|
+
if (match?.groups?.rsc) {
|
|
144
|
+
chunks.push(JSON.parse(`"${match.groups.rsc}"`));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return chunks;
|
|
149
|
+
}
|
|
150
|
+
function createRSCStream(rscName, data) {
|
|
151
|
+
return new ReadableStream({
|
|
152
|
+
type: "bytes",
|
|
153
|
+
start(controller) {
|
|
154
|
+
const encoder = new TextEncoder();
|
|
155
|
+
const self = globalThis;
|
|
156
|
+
if (data.length > 0) {
|
|
157
|
+
const parsed = buildRSCChunks(rscName, data);
|
|
158
|
+
if (parsed.length > 0) {
|
|
159
|
+
self[rscName] = self[rscName] ?? [];
|
|
160
|
+
self[rscName].push(...parsed);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const allChunks = (self[rscName] ?? [`0:[null]
|
|
164
|
+
`]).join("");
|
|
165
|
+
self[rscName] = null;
|
|
166
|
+
allChunks.split("\n").forEach((chunk) => {
|
|
167
|
+
if (chunk.length > 0) {
|
|
168
|
+
const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
|
|
169
|
+
chunk
|
|
170
|
+
)?.groups ?? {};
|
|
171
|
+
if (payload) {
|
|
172
|
+
const jsonPayload = JSON.parse(payload);
|
|
173
|
+
fixPayload(jsonPayload);
|
|
174
|
+
const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
|
|
175
|
+
controller.enqueue(encoder.encode(`${reconstruct}
|
|
176
|
+
`));
|
|
177
|
+
} else {
|
|
178
|
+
controller.enqueue(encoder.encode(`${chunk}
|
|
179
|
+
`));
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
controller.enqueue(encoder.encode(`${chunk}
|
|
183
|
+
`));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
controller.close();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/runtime/html/html-spec.ts
|
|
192
|
+
var ORIGIN_REWRITE_TAGS = [
|
|
193
|
+
"img",
|
|
194
|
+
"source",
|
|
195
|
+
"video",
|
|
196
|
+
"audio",
|
|
197
|
+
"track",
|
|
198
|
+
"iframe",
|
|
199
|
+
"embed",
|
|
200
|
+
"script",
|
|
201
|
+
"link"
|
|
202
|
+
];
|
|
203
|
+
var ID_SUFFIX_RSC = "_rsc";
|
|
204
|
+
var ID_SUFFIX_SSR = "_ssr";
|
|
205
|
+
var ID_SUFFIX_SHARED = "_shared";
|
|
206
|
+
var DATA_BUNDLE = "data-bundle";
|
|
207
|
+
var DATA_ROUTE = "data-route";
|
|
208
|
+
var DATA_RUNTIME = "data-runtime";
|
|
209
|
+
var DATA_TYPE = "data-type";
|
|
210
|
+
var DATA_SRC = "data-src";
|
|
211
|
+
var DATA_REMOTE_COMPONENTS_SHARED = "data-remote-components-shared";
|
|
212
|
+
var TAG_REMOTE_COMPONENT = "remote-component";
|
|
213
|
+
var NEXT_DATA_ID = "__NEXT_DATA__";
|
|
214
|
+
var REMOTE_NEXT_DATA_ID = "__REMOTE_NEXT_DATA__";
|
|
215
|
+
var NEXT_CONTAINER_ID = "__next";
|
|
216
|
+
|
|
217
|
+
// src/runtime/html/rewrite-srcset.ts
|
|
218
|
+
function rewriteSrcset(srcset, base, resolve) {
|
|
219
|
+
return srcset.split(",").map((entry) => {
|
|
220
|
+
const [url, descriptor] = entry.trim().split(/\s+/);
|
|
221
|
+
if (!url)
|
|
222
|
+
return entry;
|
|
223
|
+
const absoluteUrl = new URL(url, base).href;
|
|
224
|
+
const resolvedUrl = resolve ? resolve(absoluteUrl) : absoluteUrl;
|
|
225
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
226
|
+
}).join(", ");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/runtime/html/apply-origin.ts
|
|
230
|
+
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
231
|
+
if (url.origin !== location.origin) {
|
|
232
|
+
const nodes = doc.querySelectorAll(
|
|
233
|
+
ORIGIN_REWRITE_TAGS.map(
|
|
234
|
+
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
235
|
+
).join(",")
|
|
236
|
+
);
|
|
237
|
+
nodes.forEach((node) => {
|
|
238
|
+
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
239
|
+
const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
240
|
+
const isScript = node.tagName.toLowerCase() === "script";
|
|
241
|
+
node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
|
|
242
|
+
}
|
|
243
|
+
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
244
|
+
const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
|
|
245
|
+
node.setAttribute(
|
|
246
|
+
"href",
|
|
247
|
+
resolveClientUrl?.(absoluteHref) ?? absoluteHref
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (node.hasAttribute("srcset")) {
|
|
251
|
+
const raw = node.getAttribute("srcset");
|
|
252
|
+
if (raw) {
|
|
253
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
254
|
+
node.setAttribute("srcset", rewriteSrcset(raw, url, resolve));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (node.hasAttribute("imagesrcset")) {
|
|
258
|
+
const raw = node.getAttribute("imagesrcset");
|
|
259
|
+
if (raw) {
|
|
260
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
261
|
+
node.setAttribute("imagesrcset", rewriteSrcset(raw, url, resolve));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/runtime/metadata.ts
|
|
269
|
+
var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
270
|
+
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
271
|
+
"nextjs",
|
|
272
|
+
"remote-component",
|
|
273
|
+
"unknown"
|
|
274
|
+
]);
|
|
275
|
+
function isRuntime(value) {
|
|
276
|
+
return VALID_RUNTIMES.has(value);
|
|
277
|
+
}
|
|
278
|
+
function isComponentType(value) {
|
|
279
|
+
return VALID_TYPES.has(value);
|
|
280
|
+
}
|
|
281
|
+
function toRuntime(value) {
|
|
282
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
283
|
+
}
|
|
284
|
+
function toComponentType(value) {
|
|
285
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
286
|
+
}
|
|
287
|
+
function buildMetadata(attrs, url) {
|
|
288
|
+
const id = attrs.id || DEFAULT_COMPONENT_NAME;
|
|
289
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
|
|
290
|
+
return {
|
|
291
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
292
|
+
bundle,
|
|
293
|
+
route: attrs.route || url.pathname || DEFAULT_ROUTE,
|
|
294
|
+
runtime: toRuntime(attrs.runtime),
|
|
295
|
+
id,
|
|
296
|
+
type: toComponentType(attrs.type)
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/runtime/html/parse-remote-html.ts
|
|
301
|
+
function validateSingleComponent(doc, name, url) {
|
|
302
|
+
if (doc.querySelectorAll(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`).length > 1 && !doc.querySelector(
|
|
303
|
+
`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`
|
|
304
|
+
) || doc.querySelectorAll(`${TAG_REMOTE_COMPONENT}:not([src])`).length > 1 && !doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]`)) {
|
|
305
|
+
throw multipleRemoteComponentsError(url);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function findComponentElement(doc, name) {
|
|
309
|
+
return doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`) ?? doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`) ?? doc.querySelector(`div#${NEXT_CONTAINER_ID}`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]:not([src])`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}:not([src])`);
|
|
310
|
+
}
|
|
311
|
+
function parseNextData(doc) {
|
|
312
|
+
return JSON.parse(
|
|
313
|
+
(doc.querySelector(`#${NEXT_DATA_ID}`) ?? doc.querySelector(`#${REMOTE_NEXT_DATA_ID}`))?.textContent ?? "null"
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function resolveComponentName(component, nextData, fallbackName) {
|
|
317
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === TAG_REMOTE_COMPONENT;
|
|
318
|
+
const name = component?.getAttribute("id")?.replace(new RegExp(`${ID_SUFFIX_SSR}$`), "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
319
|
+
return { name, isRemoteComponent };
|
|
320
|
+
}
|
|
321
|
+
function extractRemoteShared(doc, name, nextData) {
|
|
322
|
+
const remoteSharedEl = doc.querySelector(
|
|
323
|
+
`#${name}${ID_SUFFIX_SHARED}[${DATA_REMOTE_COMPONENTS_SHARED}]`
|
|
324
|
+
);
|
|
325
|
+
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
326
|
+
remoteSharedEl?.remove();
|
|
327
|
+
return remoteShared;
|
|
328
|
+
}
|
|
329
|
+
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
330
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
331
|
+
throw new RemoteComponentsError(
|
|
332
|
+
`Remote Component not found on ${url}.${name !== DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function extractLinks(doc, component) {
|
|
337
|
+
return Array.from(doc.querySelectorAll("link[href]")).filter(
|
|
338
|
+
(link) => !component.contains(link)
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
function extractScripts(doc, component, isRemoteComponent) {
|
|
342
|
+
return Array.from(
|
|
343
|
+
(isRemoteComponent ? component : doc).querySelectorAll(
|
|
344
|
+
`script[src],script[${DATA_SRC}]`
|
|
345
|
+
)
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
function parseRemoteComponentDocument(doc, name, url) {
|
|
349
|
+
validateSingleComponent(doc, name, url.href);
|
|
350
|
+
const component = findComponentElement(doc, name);
|
|
351
|
+
const nextData = parseNextData(doc);
|
|
352
|
+
const { name: resolvedName, isRemoteComponent } = resolveComponentName(
|
|
353
|
+
component,
|
|
354
|
+
nextData,
|
|
355
|
+
name
|
|
356
|
+
);
|
|
357
|
+
const rsc = doc.querySelector(`#${resolvedName}${ID_SUFFIX_RSC}`);
|
|
358
|
+
const metadata = buildMetadata(
|
|
359
|
+
{
|
|
360
|
+
name: resolvedName,
|
|
361
|
+
bundle: component?.getAttribute(DATA_BUNDLE) || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
362
|
+
route: component?.getAttribute(DATA_ROUTE) ?? nextData?.page,
|
|
363
|
+
runtime: component?.getAttribute(DATA_RUNTIME) ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
364
|
+
id: component?.getAttribute("id"),
|
|
365
|
+
type: component?.getAttribute(DATA_TYPE)
|
|
366
|
+
},
|
|
367
|
+
url
|
|
368
|
+
);
|
|
369
|
+
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
370
|
+
validateComponentFound(
|
|
371
|
+
component,
|
|
372
|
+
rsc,
|
|
373
|
+
nextData,
|
|
374
|
+
isRemoteComponent,
|
|
375
|
+
url.href,
|
|
376
|
+
resolvedName
|
|
377
|
+
);
|
|
378
|
+
const links = extractLinks(doc, component);
|
|
379
|
+
const scripts = extractScripts(doc, component, isRemoteComponent);
|
|
380
|
+
return {
|
|
381
|
+
component,
|
|
382
|
+
name: resolvedName,
|
|
383
|
+
isRemoteComponent,
|
|
384
|
+
metadata,
|
|
385
|
+
nextData,
|
|
386
|
+
rsc,
|
|
387
|
+
remoteShared,
|
|
388
|
+
links,
|
|
389
|
+
scripts
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/runtime/loaders/component-loader.ts
|
|
394
|
+
import * as React from "react";
|
|
395
|
+
import * as JSXDevRuntime from "react/jsx-dev-runtime";
|
|
396
|
+
import * as JSXRuntime from "react/jsx-runtime";
|
|
397
|
+
import * as ReactDOM from "react-dom";
|
|
398
|
+
import * as ReactDOMClient from "react-dom/client";
|
|
399
|
+
|
|
400
|
+
// src/runtime/rsc-imports.ts
|
|
401
|
+
async function importRSCClientBrowser() {
|
|
402
|
+
try {
|
|
403
|
+
return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
|
|
404
|
+
} catch {
|
|
405
|
+
const mod = await import("react-server-dom-webpack/client.browser");
|
|
406
|
+
return mod.default ?? mod;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/runtime/loaders/component-loader.ts
|
|
411
|
+
async function loadRemoteComponent({
|
|
412
|
+
url,
|
|
413
|
+
name,
|
|
414
|
+
rscName,
|
|
415
|
+
bundle,
|
|
416
|
+
route = "/",
|
|
417
|
+
runtime = "webpack",
|
|
418
|
+
data,
|
|
419
|
+
nextData,
|
|
420
|
+
scripts = [],
|
|
421
|
+
shared = Promise.resolve({}),
|
|
422
|
+
remoteShared = {},
|
|
423
|
+
container,
|
|
424
|
+
resolveClientUrl
|
|
425
|
+
}) {
|
|
426
|
+
try {
|
|
427
|
+
if (runtime === "webpack") {
|
|
428
|
+
const self = globalThis;
|
|
429
|
+
if (!self.__DISABLE_WEBPACK_EXEC__) {
|
|
430
|
+
self.__DISABLE_WEBPACK_EXEC__ = {};
|
|
431
|
+
}
|
|
432
|
+
self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
|
|
433
|
+
await loadScripts(scripts, resolveClientUrl);
|
|
434
|
+
}
|
|
435
|
+
const hostShared = await shared;
|
|
436
|
+
logDebug(
|
|
437
|
+
"ComponentLoader",
|
|
438
|
+
`loadRemoteComponent: bundle="${bundle}", name="${name}"`
|
|
439
|
+
);
|
|
440
|
+
logDebug(
|
|
441
|
+
"ComponentLoader",
|
|
442
|
+
`Host shared modules available: ${Object.keys(hostShared)}`
|
|
443
|
+
);
|
|
444
|
+
logDebug(
|
|
445
|
+
"ComponentLoader",
|
|
446
|
+
`Remote shared modules requested: ${JSON.stringify(remoteShared)}`
|
|
447
|
+
);
|
|
448
|
+
const scope = await setupRemoteScope(
|
|
449
|
+
runtime,
|
|
450
|
+
scripts,
|
|
451
|
+
url,
|
|
452
|
+
bundle,
|
|
453
|
+
resolveClientUrl
|
|
454
|
+
);
|
|
455
|
+
if (runtime === "turbopack") {
|
|
456
|
+
await initializeSharedModules(
|
|
457
|
+
scope,
|
|
458
|
+
buildCoreShared(hostShared),
|
|
459
|
+
remoteShared
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (bundle) {
|
|
463
|
+
const resolve = await buildWebpackResolve(
|
|
464
|
+
hostShared,
|
|
465
|
+
remoteShared,
|
|
466
|
+
bundle,
|
|
467
|
+
{
|
|
468
|
+
"/react/index.js": React,
|
|
469
|
+
"/react/jsx-dev-runtime.js": JSXDevRuntime,
|
|
470
|
+
"/react/jsx-runtime.js": JSXRuntime,
|
|
471
|
+
"/react-dom/index.js": ReactDOM,
|
|
472
|
+
"/react-dom/client.js": ReactDOMClient
|
|
473
|
+
},
|
|
474
|
+
"ComponentLoader"
|
|
475
|
+
);
|
|
476
|
+
applySharedModules(bundle, resolve);
|
|
477
|
+
} else {
|
|
478
|
+
logWarn(
|
|
479
|
+
"ComponentLoader",
|
|
480
|
+
"No bundle specified, skipping shared module setup"
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const scopedData = data.map(
|
|
484
|
+
(chunk) => chunk.replaceAll(`[${bundle}]`, `[${scope.scopedName}]`)
|
|
485
|
+
);
|
|
486
|
+
if (scopedData.length > 0) {
|
|
487
|
+
return await loadRSCComponent(rscName ?? name, scopedData);
|
|
488
|
+
} else if (nextData) {
|
|
489
|
+
return loadNextPagesComponent(bundle, route, nextData, name, container);
|
|
490
|
+
}
|
|
491
|
+
return loadRSCComponent(rscName ?? name, [`0:[null]
|
|
492
|
+
`]);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return {
|
|
495
|
+
component: null,
|
|
496
|
+
error: new RemoteComponentsError(
|
|
497
|
+
`Failed to load remote component "${name}".`,
|
|
498
|
+
{
|
|
499
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async function loadRSCComponent(rscName, data) {
|
|
506
|
+
const { createFromReadableStream } = await importRSCClientBrowser();
|
|
507
|
+
if (typeof createFromReadableStream !== "function") {
|
|
508
|
+
throw new RemoteComponentsError(
|
|
509
|
+
'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
const stream = createRSCStream(rscName, data);
|
|
513
|
+
const component = createFromReadableStream(stream);
|
|
514
|
+
return { component };
|
|
515
|
+
}
|
|
516
|
+
function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
517
|
+
const { Component, App } = nextClientPagesLoader(bundle, route, container);
|
|
518
|
+
if (!Component) {
|
|
519
|
+
throw new RemoteComponentsError(
|
|
520
|
+
`Remote Component "${name}" is trying to load the component for route "${route}" but it is not available.`
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
|
|
524
|
+
return { component };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/host/shared/pipeline.ts
|
|
528
|
+
function preparePipeline(input) {
|
|
529
|
+
const parser = new DOMParser();
|
|
530
|
+
const doc = parser.parseFromString(input.html, "text/html");
|
|
531
|
+
const parsed = parseRemoteComponentDocument(doc, input.name, input.url);
|
|
532
|
+
const remoteShared = input.remoteShared ?? parsed.remoteShared;
|
|
533
|
+
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
534
|
+
throw new RemoteComponentsError(
|
|
535
|
+
remoteShared.__remote_components_missing_shared__
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
applyOriginToNodes(doc, input.url, input.resolveClientUrl);
|
|
539
|
+
const scriptDescriptors = buildScriptDescriptors(parsed.scripts, input.url);
|
|
540
|
+
return { doc, parsed, scriptDescriptors };
|
|
541
|
+
}
|
|
542
|
+
async function loadPrepared(input) {
|
|
543
|
+
const { prepared, url, signal, resolveClientUrl, container, rscName } = input;
|
|
544
|
+
const { doc, parsed, scriptDescriptors } = prepared;
|
|
545
|
+
if (signal.aborted) {
|
|
546
|
+
return { status: "aborted" };
|
|
547
|
+
}
|
|
548
|
+
const userShared = await input.shared;
|
|
549
|
+
if (signal.aborted) {
|
|
550
|
+
return { status: "aborted" };
|
|
551
|
+
}
|
|
552
|
+
if (parsed.isRemoteComponent) {
|
|
553
|
+
return loadStaticPath({
|
|
554
|
+
parsed,
|
|
555
|
+
doc,
|
|
556
|
+
url,
|
|
557
|
+
resolveClientUrl
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return loadDynamicPath({
|
|
561
|
+
parsed,
|
|
562
|
+
doc,
|
|
563
|
+
url,
|
|
564
|
+
scriptDescriptors,
|
|
565
|
+
shared: userShared,
|
|
566
|
+
resolveClientUrl,
|
|
567
|
+
container,
|
|
568
|
+
rscName
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
function buildScriptDescriptors(scripts, url) {
|
|
572
|
+
return scripts.map((script) => {
|
|
573
|
+
const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
|
|
574
|
+
const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(scriptSrc)?.groups ?? {
|
|
575
|
+
prefix: void 0,
|
|
576
|
+
id: scriptSrc
|
|
577
|
+
};
|
|
578
|
+
return {
|
|
579
|
+
src: new URL(collapseDoubleSlashes(`${prefix ?? ""}${path}`), url).href
|
|
580
|
+
};
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
async function loadStaticPath(input) {
|
|
584
|
+
const { parsed, doc, url, resolveClientUrl } = input;
|
|
585
|
+
const scripts = Array.from(
|
|
586
|
+
parsed.component.querySelectorAll("script")
|
|
587
|
+
);
|
|
588
|
+
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
589
|
+
scripts,
|
|
590
|
+
url,
|
|
591
|
+
resolveClientUrl
|
|
592
|
+
);
|
|
593
|
+
return {
|
|
594
|
+
status: "static",
|
|
595
|
+
mount,
|
|
596
|
+
unmount,
|
|
597
|
+
metadata: parsed.metadata,
|
|
598
|
+
parsed,
|
|
599
|
+
doc
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
async function loadDynamicPath(input) {
|
|
603
|
+
const {
|
|
604
|
+
parsed,
|
|
605
|
+
doc,
|
|
606
|
+
url,
|
|
607
|
+
scriptDescriptors,
|
|
608
|
+
shared,
|
|
609
|
+
resolveClientUrl,
|
|
610
|
+
container
|
|
611
|
+
} = input;
|
|
612
|
+
const rscName = input.rscName ?? (parsed.rsc ? `__remote_component_rsc_${escapeString(url.href)}_${escapeString(parsed.name)}` : void 0);
|
|
613
|
+
const rscData = parsed.rsc ? (parsed.rsc.textContent || "").split("\n").filter(Boolean) : [];
|
|
614
|
+
const result = await loadRemoteComponent({
|
|
615
|
+
url,
|
|
616
|
+
name: parsed.name,
|
|
617
|
+
rscName,
|
|
618
|
+
bundle: parsed.metadata.bundle,
|
|
619
|
+
route: parsed.metadata.route,
|
|
620
|
+
runtime: parsed.metadata.runtime,
|
|
621
|
+
data: rscData,
|
|
622
|
+
nextData: parsed.nextData,
|
|
623
|
+
scripts: scriptDescriptors,
|
|
624
|
+
shared: buildHostShared(shared, resolveClientUrl),
|
|
625
|
+
remoteShared: parsed.remoteShared,
|
|
626
|
+
container,
|
|
627
|
+
resolveClientUrl
|
|
628
|
+
});
|
|
629
|
+
if (result.error) {
|
|
630
|
+
return { status: "error", error: result.error };
|
|
631
|
+
}
|
|
632
|
+
return {
|
|
633
|
+
status: "loaded",
|
|
634
|
+
component: result.component,
|
|
635
|
+
metadata: parsed.metadata,
|
|
636
|
+
parsed,
|
|
637
|
+
doc
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// src/host/shared/state.ts
|
|
642
|
+
function createHostState() {
|
|
643
|
+
return {
|
|
644
|
+
stage: "idle",
|
|
645
|
+
prevSrc: void 0,
|
|
646
|
+
prevUrl: void 0,
|
|
647
|
+
prevName: void 0,
|
|
648
|
+
prevIsRemoteComponent: false,
|
|
649
|
+
abortController: void 0
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// src/host/utils/resolve-name-from-src.ts
|
|
654
|
+
function resolveNameFromSrc(src, defaultName) {
|
|
655
|
+
if (!src) {
|
|
656
|
+
return defaultName;
|
|
657
|
+
}
|
|
658
|
+
const hash = typeof src === "string" ? src : src.hash;
|
|
659
|
+
const hashIndex = hash.indexOf("#");
|
|
660
|
+
if (hashIndex < 0) {
|
|
661
|
+
return defaultName;
|
|
662
|
+
}
|
|
663
|
+
const name = hash.slice(hashIndex + 1);
|
|
664
|
+
return name || defaultName;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// src/runtime/url/resolve-client-url.ts
|
|
668
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
669
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
670
|
+
return (url) => {
|
|
671
|
+
const urlOrigin = parseOrigin(url);
|
|
672
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
673
|
+
return void 0;
|
|
674
|
+
}
|
|
675
|
+
return resolveClientUrl(remoteSrc, url);
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
function parseOrigin(url) {
|
|
679
|
+
try {
|
|
680
|
+
return new URL(url).origin;
|
|
681
|
+
} catch {
|
|
682
|
+
return void 0;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/runtime/url/default-resolve-client-url.ts
|
|
687
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
688
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export {
|
|
692
|
+
fetchWithHooks,
|
|
693
|
+
getClientOrServerUrl,
|
|
694
|
+
makeReactEmitter,
|
|
695
|
+
makeEventEmitter,
|
|
696
|
+
createRSCStream,
|
|
697
|
+
preparePipeline,
|
|
698
|
+
loadPrepared,
|
|
699
|
+
createHostState,
|
|
700
|
+
resolveNameFromSrc,
|
|
701
|
+
bindResolveClientUrl
|
|
702
|
+
};
|
|
703
|
+
//# sourceMappingURL=chunk-NZAB7REE.js.map
|