remote-components 0.3.0 → 0.3.1
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/host/html.cjs +88 -53
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +88 -53
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +64 -22
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +64 -22
- 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 +64 -22
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +64 -22
- 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/server/fetch-remote-component.cjs +164 -149
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +166 -149
- package/dist/internal/host/server/fetch-remote-component.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 +4 -3
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +11 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.js +10 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.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
package/dist/host/react.js
CHANGED
|
@@ -420,12 +420,12 @@ var attrToProp = {
|
|
|
420
420
|
};
|
|
421
421
|
|
|
422
422
|
// src/runtime/constants.ts
|
|
423
|
+
var DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
424
|
+
var DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
423
425
|
var DEFAULT_ROUTE = "/";
|
|
424
426
|
var RUNTIME_WEBPACK = "webpack";
|
|
425
427
|
var RUNTIME_TURBOPACK = "turbopack";
|
|
426
428
|
var RUNTIME_SCRIPT = "script";
|
|
427
|
-
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
428
|
-
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
429
429
|
function getBundleKey(bundle) {
|
|
430
430
|
return escapeString(bundle);
|
|
431
431
|
}
|
|
@@ -492,6 +492,38 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
// src/runtime/metadata.ts
|
|
496
|
+
var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
497
|
+
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
498
|
+
"nextjs",
|
|
499
|
+
"remote-component",
|
|
500
|
+
"unknown"
|
|
501
|
+
]);
|
|
502
|
+
function isRuntime(value) {
|
|
503
|
+
return VALID_RUNTIMES.has(value);
|
|
504
|
+
}
|
|
505
|
+
function isComponentType(value) {
|
|
506
|
+
return VALID_TYPES.has(value);
|
|
507
|
+
}
|
|
508
|
+
function toRuntime(value) {
|
|
509
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
510
|
+
}
|
|
511
|
+
function toComponentType(value) {
|
|
512
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
513
|
+
}
|
|
514
|
+
function buildMetadata(attrs, url) {
|
|
515
|
+
const id = attrs.id || DEFAULT_COMPONENT_NAME;
|
|
516
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
|
|
517
|
+
return {
|
|
518
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
519
|
+
bundle,
|
|
520
|
+
route: attrs.route || url.pathname || DEFAULT_ROUTE,
|
|
521
|
+
runtime: toRuntime(attrs.runtime),
|
|
522
|
+
id,
|
|
523
|
+
type: toComponentType(attrs.type)
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
495
527
|
// src/runtime/html/parse-remote-html.ts
|
|
496
528
|
function validateSingleComponent(doc, name, url) {
|
|
497
529
|
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
@@ -511,14 +543,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
511
543
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
512
544
|
return { name, isRemoteComponent };
|
|
513
545
|
}
|
|
514
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
515
|
-
return {
|
|
516
|
-
name,
|
|
517
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
518
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
519
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
546
|
function extractRemoteShared(doc, name, nextData) {
|
|
523
547
|
const remoteSharedEl = doc.querySelector(
|
|
524
548
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -530,7 +554,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
530
554
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
531
555
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
532
556
|
throw new RemoteComponentsError(
|
|
533
|
-
`Remote Component not found on ${url}.${name !==
|
|
557
|
+
`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>?`
|
|
534
558
|
);
|
|
535
559
|
}
|
|
536
560
|
}
|
|
@@ -556,10 +580,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
556
580
|
name
|
|
557
581
|
);
|
|
558
582
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
559
|
-
const metadata =
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
583
|
+
const metadata = buildMetadata(
|
|
584
|
+
{
|
|
585
|
+
name: resolvedName,
|
|
586
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
587
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
588
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
589
|
+
id: component?.getAttribute("id"),
|
|
590
|
+
type: component?.getAttribute("data-type")
|
|
591
|
+
},
|
|
563
592
|
url
|
|
564
593
|
);
|
|
565
594
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -875,6 +904,14 @@ function createRSCStream(rscName, data) {
|
|
|
875
904
|
});
|
|
876
905
|
}
|
|
877
906
|
|
|
907
|
+
// src/runtime/patterns.ts
|
|
908
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
909
|
+
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
910
|
+
var DOUBLE_SLASH_RE = /(?<!:)\/\//g;
|
|
911
|
+
function collapseDoubleSlashes(path) {
|
|
912
|
+
return path.replace(DOUBLE_SLASH_RE, "/");
|
|
913
|
+
}
|
|
914
|
+
|
|
878
915
|
// src/runtime/turbopack/patterns.ts
|
|
879
916
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
880
917
|
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
@@ -1464,7 +1501,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1464
1501
|
}
|
|
1465
1502
|
}
|
|
1466
1503
|
if (runtime === RUNTIME_TURBOPACK) {
|
|
1467
|
-
await Promise.
|
|
1504
|
+
const results = await Promise.allSettled(
|
|
1468
1505
|
scripts.map((script) => {
|
|
1469
1506
|
if (script.src) {
|
|
1470
1507
|
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
@@ -1472,6 +1509,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1472
1509
|
return Promise.resolve(void 0);
|
|
1473
1510
|
})
|
|
1474
1511
|
);
|
|
1512
|
+
for (const result of results) {
|
|
1513
|
+
if (result.status === "rejected") {
|
|
1514
|
+
logWarn(
|
|
1515
|
+
"WebpackRuntime",
|
|
1516
|
+
`Initial chunk load failed: ${String(result.reason)}`
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1475
1520
|
}
|
|
1476
1521
|
const coreShared = {
|
|
1477
1522
|
react: async () => (await import("react")).default,
|
|
@@ -1954,7 +1999,7 @@ function getRemoteComponentHtml(html) {
|
|
|
1954
1999
|
return ssrRemoteComponentContainer.innerHTML;
|
|
1955
2000
|
}
|
|
1956
2001
|
const remoteComponentContainer = temp.querySelectorAll(
|
|
1957
|
-
`div[data-bundle][data-route][data-runtime][id^="
|
|
2002
|
+
`div[data-bundle][data-route][data-runtime][id^="${DEFAULT_COMPONENT_NAME}"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
1958
2003
|
);
|
|
1959
2004
|
if (remoteComponentContainer.length > 0) {
|
|
1960
2005
|
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
@@ -1971,7 +2016,7 @@ function ConsumeRemoteComponent({
|
|
|
1971
2016
|
mode = "open",
|
|
1972
2017
|
reset,
|
|
1973
2018
|
credentials: credentialsProp,
|
|
1974
|
-
name: nameProp =
|
|
2019
|
+
name: nameProp = DEFAULT_COMPONENT_NAME,
|
|
1975
2020
|
shared: sharedProp,
|
|
1976
2021
|
children,
|
|
1977
2022
|
onBeforeLoad,
|
|
@@ -2311,10 +2356,7 @@ function ConsumeRemoteComponent({
|
|
|
2311
2356
|
};
|
|
2312
2357
|
return {
|
|
2313
2358
|
src: new URL(
|
|
2314
|
-
`${prefix ?? ""}${path}
|
|
2315
|
-
/(?<char>[^:])(?<double>\/\/)/g,
|
|
2316
|
-
"$1/"
|
|
2317
|
-
),
|
|
2359
|
+
collapseDoubleSlashes(`${prefix ?? ""}${path}`),
|
|
2318
2360
|
url
|
|
2319
2361
|
).href
|
|
2320
2362
|
};
|