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
|
@@ -534,12 +534,12 @@ var attrToProp = {
|
|
|
534
534
|
};
|
|
535
535
|
|
|
536
536
|
// src/runtime/constants.ts
|
|
537
|
+
var DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
538
|
+
var DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
537
539
|
var DEFAULT_ROUTE = "/";
|
|
538
540
|
var RUNTIME_WEBPACK = "webpack";
|
|
539
541
|
var RUNTIME_TURBOPACK = "turbopack";
|
|
540
542
|
var RUNTIME_SCRIPT = "script";
|
|
541
|
-
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
542
|
-
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
543
543
|
function getBundleKey(bundle) {
|
|
544
544
|
return escapeString(bundle);
|
|
545
545
|
}
|
|
@@ -606,6 +606,38 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
608
|
|
|
609
|
+
// src/runtime/metadata.ts
|
|
610
|
+
var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
611
|
+
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
612
|
+
"nextjs",
|
|
613
|
+
"remote-component",
|
|
614
|
+
"unknown"
|
|
615
|
+
]);
|
|
616
|
+
function isRuntime(value) {
|
|
617
|
+
return VALID_RUNTIMES.has(value);
|
|
618
|
+
}
|
|
619
|
+
function isComponentType(value) {
|
|
620
|
+
return VALID_TYPES.has(value);
|
|
621
|
+
}
|
|
622
|
+
function toRuntime(value) {
|
|
623
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
624
|
+
}
|
|
625
|
+
function toComponentType(value) {
|
|
626
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
627
|
+
}
|
|
628
|
+
function buildMetadata(attrs, url) {
|
|
629
|
+
const id = attrs.id || DEFAULT_COMPONENT_NAME;
|
|
630
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
|
|
631
|
+
return {
|
|
632
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
633
|
+
bundle,
|
|
634
|
+
route: attrs.route || url.pathname || DEFAULT_ROUTE,
|
|
635
|
+
runtime: toRuntime(attrs.runtime),
|
|
636
|
+
id,
|
|
637
|
+
type: toComponentType(attrs.type)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
609
641
|
// src/runtime/html/parse-remote-html.ts
|
|
610
642
|
function validateSingleComponent(doc, name, url) {
|
|
611
643
|
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}"]`)) {
|
|
@@ -625,14 +657,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
625
657
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
626
658
|
return { name, isRemoteComponent };
|
|
627
659
|
}
|
|
628
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
629
|
-
return {
|
|
630
|
-
name,
|
|
631
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
632
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
633
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
660
|
function extractRemoteShared(doc, name, nextData) {
|
|
637
661
|
const remoteSharedEl = doc.querySelector(
|
|
638
662
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -644,7 +668,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
644
668
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
645
669
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
646
670
|
throw new RemoteComponentsError(
|
|
647
|
-
`Remote Component not found on ${url}.${name !==
|
|
671
|
+
`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>?`
|
|
648
672
|
);
|
|
649
673
|
}
|
|
650
674
|
}
|
|
@@ -670,10 +694,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
670
694
|
name
|
|
671
695
|
);
|
|
672
696
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
673
|
-
const metadata =
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
697
|
+
const metadata = buildMetadata(
|
|
698
|
+
{
|
|
699
|
+
name: resolvedName,
|
|
700
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
701
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
702
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
703
|
+
id: component?.getAttribute("id"),
|
|
704
|
+
type: component?.getAttribute("data-type")
|
|
705
|
+
},
|
|
677
706
|
url
|
|
678
707
|
);
|
|
679
708
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -989,6 +1018,14 @@ function createRSCStream(rscName, data) {
|
|
|
989
1018
|
});
|
|
990
1019
|
}
|
|
991
1020
|
|
|
1021
|
+
// src/runtime/patterns.ts
|
|
1022
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
1023
|
+
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
1024
|
+
var DOUBLE_SLASH_RE = /(?<!:)\/\//g;
|
|
1025
|
+
function collapseDoubleSlashes(path) {
|
|
1026
|
+
return path.replace(DOUBLE_SLASH_RE, "/");
|
|
1027
|
+
}
|
|
1028
|
+
|
|
992
1029
|
// src/runtime/turbopack/patterns.ts
|
|
993
1030
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
994
1031
|
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
@@ -1578,7 +1615,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1578
1615
|
}
|
|
1579
1616
|
}
|
|
1580
1617
|
if (runtime === RUNTIME_TURBOPACK) {
|
|
1581
|
-
await Promise.
|
|
1618
|
+
const results = await Promise.allSettled(
|
|
1582
1619
|
scripts.map((script) => {
|
|
1583
1620
|
if (script.src) {
|
|
1584
1621
|
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
@@ -1586,6 +1623,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1586
1623
|
return Promise.resolve(void 0);
|
|
1587
1624
|
})
|
|
1588
1625
|
);
|
|
1626
|
+
for (const result of results) {
|
|
1627
|
+
if (result.status === "rejected") {
|
|
1628
|
+
logWarn(
|
|
1629
|
+
"WebpackRuntime",
|
|
1630
|
+
`Initial chunk load failed: ${String(result.reason)}`
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1589
1634
|
}
|
|
1590
1635
|
const coreShared = {
|
|
1591
1636
|
react: async () => (await import("react")).default,
|
|
@@ -2042,7 +2087,7 @@ function getRemoteComponentHtml(html) {
|
|
|
2042
2087
|
return ssrRemoteComponentContainer.innerHTML;
|
|
2043
2088
|
}
|
|
2044
2089
|
const remoteComponentContainer = temp.querySelectorAll(
|
|
2045
|
-
`div[data-bundle][data-route][data-runtime][id^="
|
|
2090
|
+
`div[data-bundle][data-route][data-runtime][id^="${DEFAULT_COMPONENT_NAME}"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
2046
2091
|
);
|
|
2047
2092
|
if (remoteComponentContainer.length > 0) {
|
|
2048
2093
|
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
@@ -2062,7 +2107,7 @@ function ConsumeRemoteComponent({
|
|
|
2062
2107
|
mode = "open",
|
|
2063
2108
|
reset,
|
|
2064
2109
|
credentials: credentialsProp,
|
|
2065
|
-
name: nameProp =
|
|
2110
|
+
name: nameProp = DEFAULT_COMPONENT_NAME,
|
|
2066
2111
|
shared: sharedProp,
|
|
2067
2112
|
children,
|
|
2068
2113
|
onBeforeLoad,
|
|
@@ -2401,10 +2446,7 @@ function ConsumeRemoteComponent({
|
|
|
2401
2446
|
};
|
|
2402
2447
|
return {
|
|
2403
2448
|
src: new URL(
|
|
2404
|
-
`${prefix ?? ""}${path}
|
|
2405
|
-
/(?<char>[^:])(?<double>\/\/)/g,
|
|
2406
|
-
"$1/"
|
|
2407
|
-
),
|
|
2449
|
+
collapseDoubleSlashes(`${prefix ?? ""}${path}`),
|
|
2408
2450
|
url
|
|
2409
2451
|
).href
|
|
2410
2452
|
};
|