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
|
@@ -514,12 +514,12 @@ var attrToProp = {
|
|
|
514
514
|
};
|
|
515
515
|
|
|
516
516
|
// src/runtime/constants.ts
|
|
517
|
+
var DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
518
|
+
var DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
517
519
|
var DEFAULT_ROUTE = "/";
|
|
518
520
|
var RUNTIME_WEBPACK = "webpack";
|
|
519
521
|
var RUNTIME_TURBOPACK = "turbopack";
|
|
520
522
|
var RUNTIME_SCRIPT = "script";
|
|
521
|
-
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
522
|
-
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
523
523
|
function getBundleKey(bundle) {
|
|
524
524
|
return escapeString(bundle);
|
|
525
525
|
}
|
|
@@ -586,6 +586,38 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
|
|
589
|
+
// src/runtime/metadata.ts
|
|
590
|
+
var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
|
|
591
|
+
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
592
|
+
"nextjs",
|
|
593
|
+
"remote-component",
|
|
594
|
+
"unknown"
|
|
595
|
+
]);
|
|
596
|
+
function isRuntime(value) {
|
|
597
|
+
return VALID_RUNTIMES.has(value);
|
|
598
|
+
}
|
|
599
|
+
function isComponentType(value) {
|
|
600
|
+
return VALID_TYPES.has(value);
|
|
601
|
+
}
|
|
602
|
+
function toRuntime(value) {
|
|
603
|
+
return value && isRuntime(value) ? value : "webpack";
|
|
604
|
+
}
|
|
605
|
+
function toComponentType(value) {
|
|
606
|
+
return value && isComponentType(value) ? value : "unknown";
|
|
607
|
+
}
|
|
608
|
+
function buildMetadata(attrs, url) {
|
|
609
|
+
const id = attrs.id || DEFAULT_COMPONENT_NAME;
|
|
610
|
+
const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
|
|
611
|
+
return {
|
|
612
|
+
name: attrs.name || id.replace(/_ssr$/, ""),
|
|
613
|
+
bundle,
|
|
614
|
+
route: attrs.route || url.pathname || DEFAULT_ROUTE,
|
|
615
|
+
runtime: toRuntime(attrs.runtime),
|
|
616
|
+
id,
|
|
617
|
+
type: toComponentType(attrs.type)
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
589
621
|
// src/runtime/html/parse-remote-html.ts
|
|
590
622
|
function validateSingleComponent(doc, name, url) {
|
|
591
623
|
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}"]`)) {
|
|
@@ -605,14 +637,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
605
637
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
606
638
|
return { name, isRemoteComponent };
|
|
607
639
|
}
|
|
608
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
609
|
-
return {
|
|
610
|
-
name,
|
|
611
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
612
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
613
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
640
|
function extractRemoteShared(doc, name, nextData) {
|
|
617
641
|
const remoteSharedEl = doc.querySelector(
|
|
618
642
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -624,7 +648,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
624
648
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
625
649
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
626
650
|
throw new RemoteComponentsError(
|
|
627
|
-
`Remote Component not found on ${url}.${name !==
|
|
651
|
+
`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>?`
|
|
628
652
|
);
|
|
629
653
|
}
|
|
630
654
|
}
|
|
@@ -650,10 +674,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
650
674
|
name
|
|
651
675
|
);
|
|
652
676
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
653
|
-
const metadata =
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
677
|
+
const metadata = buildMetadata(
|
|
678
|
+
{
|
|
679
|
+
name: resolvedName,
|
|
680
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
681
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
682
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
683
|
+
id: component?.getAttribute("id"),
|
|
684
|
+
type: component?.getAttribute("data-type")
|
|
685
|
+
},
|
|
657
686
|
url
|
|
658
687
|
);
|
|
659
688
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -969,6 +998,14 @@ function createRSCStream(rscName, data) {
|
|
|
969
998
|
});
|
|
970
999
|
}
|
|
971
1000
|
|
|
1001
|
+
// src/runtime/patterns.ts
|
|
1002
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
1003
|
+
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
1004
|
+
var DOUBLE_SLASH_RE = /(?<!:)\/\//g;
|
|
1005
|
+
function collapseDoubleSlashes(path) {
|
|
1006
|
+
return path.replace(DOUBLE_SLASH_RE, "/");
|
|
1007
|
+
}
|
|
1008
|
+
|
|
972
1009
|
// src/runtime/turbopack/patterns.ts
|
|
973
1010
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
974
1011
|
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
@@ -1558,7 +1595,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1558
1595
|
}
|
|
1559
1596
|
}
|
|
1560
1597
|
if (runtime === RUNTIME_TURBOPACK) {
|
|
1561
|
-
await Promise.
|
|
1598
|
+
const results = await Promise.allSettled(
|
|
1562
1599
|
scripts.map((script) => {
|
|
1563
1600
|
if (script.src) {
|
|
1564
1601
|
return self.__webpack_chunk_load__?.(script.src, bundle);
|
|
@@ -1566,6 +1603,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1566
1603
|
return Promise.resolve(void 0);
|
|
1567
1604
|
})
|
|
1568
1605
|
);
|
|
1606
|
+
for (const result of results) {
|
|
1607
|
+
if (result.status === "rejected") {
|
|
1608
|
+
logWarn(
|
|
1609
|
+
"WebpackRuntime",
|
|
1610
|
+
`Initial chunk load failed: ${String(result.reason)}`
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1569
1614
|
}
|
|
1570
1615
|
const coreShared = {
|
|
1571
1616
|
react: async () => (await import("react")).default,
|
|
@@ -2022,7 +2067,7 @@ function getRemoteComponentHtml(html) {
|
|
|
2022
2067
|
return ssrRemoteComponentContainer.innerHTML;
|
|
2023
2068
|
}
|
|
2024
2069
|
const remoteComponentContainer = temp.querySelectorAll(
|
|
2025
|
-
`div[data-bundle][data-route][data-runtime][id^="
|
|
2070
|
+
`div[data-bundle][data-route][data-runtime][id^="${DEFAULT_COMPONENT_NAME}"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
|
|
2026
2071
|
);
|
|
2027
2072
|
if (remoteComponentContainer.length > 0) {
|
|
2028
2073
|
return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
|
|
@@ -2039,7 +2084,7 @@ function ConsumeRemoteComponent({
|
|
|
2039
2084
|
mode = "open",
|
|
2040
2085
|
reset,
|
|
2041
2086
|
credentials: credentialsProp,
|
|
2042
|
-
name: nameProp =
|
|
2087
|
+
name: nameProp = DEFAULT_COMPONENT_NAME,
|
|
2043
2088
|
shared: sharedProp,
|
|
2044
2089
|
children,
|
|
2045
2090
|
onBeforeLoad,
|
|
@@ -2379,10 +2424,7 @@ function ConsumeRemoteComponent({
|
|
|
2379
2424
|
};
|
|
2380
2425
|
return {
|
|
2381
2426
|
src: new URL(
|
|
2382
|
-
`${prefix ?? ""}${path}
|
|
2383
|
-
/(?<char>[^:])(?<double>\/\/)/g,
|
|
2384
|
-
"$1/"
|
|
2385
|
-
),
|
|
2427
|
+
collapseDoubleSlashes(`${prefix ?? ""}${path}`),
|
|
2386
2428
|
url
|
|
2387
2429
|
).href
|
|
2388
2430
|
};
|