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.
Files changed (66) hide show
  1. package/dist/host/html.cjs +88 -53
  2. package/dist/host/html.cjs.map +1 -1
  3. package/dist/host/html.js +88 -53
  4. package/dist/host/html.js.map +1 -1
  5. package/dist/host/nextjs/app/client-only.cjs +64 -22
  6. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  7. package/dist/host/nextjs/app/client-only.js +64 -22
  8. package/dist/host/nextjs/app/client-only.js.map +1 -1
  9. package/dist/host/nextjs/app.cjs +5 -6
  10. package/dist/host/nextjs/app.cjs.map +1 -1
  11. package/dist/host/nextjs/app.js +5 -6
  12. package/dist/host/nextjs/app.js.map +1 -1
  13. package/dist/host/nextjs/pages.cjs +6 -11
  14. package/dist/host/nextjs/pages.cjs.map +1 -1
  15. package/dist/host/nextjs/pages.js +9 -11
  16. package/dist/host/nextjs/pages.js.map +1 -1
  17. package/dist/host/react.cjs +64 -22
  18. package/dist/host/react.cjs.map +1 -1
  19. package/dist/host/react.js +64 -22
  20. package/dist/host/react.js.map +1 -1
  21. package/dist/internal/host/nextjs/dom-flight.cjs +16 -7
  22. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  23. package/dist/internal/host/nextjs/dom-flight.d.ts +2 -2
  24. package/dist/internal/host/nextjs/dom-flight.js +16 -7
  25. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  26. package/dist/internal/host/server/fetch-remote-component.cjs +164 -149
  27. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  28. package/dist/internal/host/server/fetch-remote-component.js +166 -149
  29. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  30. package/dist/internal/runtime/constants.cjs +6 -6
  31. package/dist/internal/runtime/constants.cjs.map +1 -1
  32. package/dist/internal/runtime/constants.d.ts +3 -3
  33. package/dist/internal/runtime/constants.js +4 -4
  34. package/dist/internal/runtime/constants.js.map +1 -1
  35. package/dist/internal/runtime/html/parse-remote-html.cjs +11 -15
  36. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  37. package/dist/internal/runtime/html/parse-remote-html.d.ts +2 -12
  38. package/dist/internal/runtime/html/parse-remote-html.js +17 -15
  39. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  40. package/dist/internal/runtime/loaders/script-loader.cjs +2 -2
  41. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
  42. package/dist/internal/runtime/loaders/script-loader.js +1 -1
  43. package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
  44. package/dist/internal/runtime/metadata.cjs +42 -0
  45. package/dist/internal/runtime/metadata.cjs.map +1 -1
  46. package/dist/internal/runtime/metadata.d.ts +21 -1
  47. package/dist/internal/runtime/metadata.js +38 -0
  48. package/dist/internal/runtime/metadata.js.map +1 -1
  49. package/dist/internal/runtime/patterns.cjs +38 -0
  50. package/dist/internal/runtime/patterns.cjs.map +1 -0
  51. package/dist/internal/runtime/patterns.d.ts +5 -0
  52. package/dist/internal/runtime/patterns.js +12 -0
  53. package/dist/internal/runtime/patterns.js.map +1 -0
  54. package/dist/internal/runtime/turbopack/chunk-loader.cjs +4 -3
  55. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  56. package/dist/internal/runtime/turbopack/chunk-loader.js +1 -1
  57. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  58. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +11 -2
  59. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
  60. package/dist/internal/runtime/turbopack/webpack-runtime.js +10 -2
  61. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
  62. package/dist/remote/nextjs/app.cjs +2 -1
  63. package/dist/remote/nextjs/app.cjs.map +1 -1
  64. package/dist/remote/nextjs/app.js +2 -1
  65. package/dist/remote/nextjs/app.js.map +1 -1
  66. package/package.json +1 -1
@@ -223,17 +223,17 @@ var init_utils = __esm({
223
223
  function getBundleKey(bundle) {
224
224
  return escapeString(bundle);
225
225
  }
226
- var DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT, REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE;
226
+ var DEFAULT_BUNDLE_NAME, DEFAULT_COMPONENT_NAME, DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT;
227
227
  var init_constants2 = __esm({
228
228
  "src/runtime/constants.ts"() {
229
229
  "use strict";
230
230
  init_utils();
231
+ DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
232
+ DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
231
233
  DEFAULT_ROUTE = "/";
232
234
  RUNTIME_WEBPACK = "webpack";
233
235
  RUNTIME_TURBOPACK = "turbopack";
234
236
  RUNTIME_SCRIPT = "script";
235
- REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
236
- NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
237
237
  }
238
238
  });
239
239
 
@@ -607,6 +607,16 @@ var init_polyfill = __esm({
607
607
  }
608
608
  });
609
609
 
610
+ // src/runtime/patterns.ts
611
+ var REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE;
612
+ var init_patterns = __esm({
613
+ "src/runtime/patterns.ts"() {
614
+ "use strict";
615
+ REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
616
+ NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
617
+ }
618
+ });
619
+
610
620
  // src/runtime/loaders/script-loader.ts
611
621
  async function loadScripts(scripts, resolveClientUrl) {
612
622
  await Promise.all(
@@ -643,7 +653,7 @@ async function loadScripts(scripts, resolveClientUrl) {
643
653
  var init_script_loader = __esm({
644
654
  "src/runtime/loaders/script-loader.ts"() {
645
655
  "use strict";
646
- init_constants2();
656
+ init_patterns();
647
657
  init_protected_rc_fallback();
648
658
  init_error();
649
659
  init_logger();
@@ -744,15 +754,15 @@ var init_webpack = __esm({
744
754
  init_apply_shared_modules();
745
755
  init_next_client_pages_loader();
746
756
  init_polyfill();
747
- init_constants2();
748
757
  init_script_loader();
758
+ init_patterns();
749
759
  init_error();
750
760
  }
751
761
  });
752
762
 
753
763
  // src/runtime/turbopack/patterns.ts
754
764
  var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
755
- var init_patterns = __esm({
765
+ var init_patterns2 = __esm({
756
766
  "src/runtime/turbopack/patterns.ts"() {
757
767
  "use strict";
758
768
  REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
@@ -975,10 +985,11 @@ var init_chunk_loader = __esm({
975
985
  "src/runtime/turbopack/chunk-loader.ts"() {
976
986
  "use strict";
977
987
  init_constants2();
988
+ init_patterns();
978
989
  init_protected_rc_fallback();
979
990
  init_error();
980
991
  init_logger();
981
- init_patterns();
992
+ init_patterns2();
982
993
  }
983
994
  });
984
995
 
@@ -1344,7 +1355,7 @@ var init_shared_modules = __esm({
1344
1355
  init_constants2();
1345
1356
  init_logger();
1346
1357
  init_module();
1347
- init_patterns();
1358
+ init_patterns2();
1348
1359
  DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
1349
1360
  }
1350
1361
  });
@@ -1372,7 +1383,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1372
1383
  }
1373
1384
  }
1374
1385
  if (runtime === RUNTIME_TURBOPACK) {
1375
- await Promise.all(
1386
+ const results = await Promise.allSettled(
1376
1387
  scripts.map((script) => {
1377
1388
  if (script.src) {
1378
1389
  return self.__webpack_chunk_load__?.(script.src, bundle);
@@ -1380,6 +1391,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1380
1391
  return Promise.resolve(void 0);
1381
1392
  })
1382
1393
  );
1394
+ for (const result of results) {
1395
+ if (result.status === "rejected") {
1396
+ logWarn(
1397
+ "WebpackRuntime",
1398
+ `Initial chunk load failed: ${String(result.reason)}`
1399
+ );
1400
+ }
1401
+ }
1383
1402
  }
1384
1403
  const coreShared = {
1385
1404
  react: async () => (await import("react")).default,
@@ -1447,6 +1466,7 @@ var init_webpack_runtime = __esm({
1447
1466
  "src/runtime/turbopack/webpack-runtime.ts"() {
1448
1467
  "use strict";
1449
1468
  init_constants2();
1469
+ init_patterns();
1450
1470
  init_error();
1451
1471
  init_logger();
1452
1472
  init_chunk_loader();
@@ -1785,6 +1805,9 @@ function resolveNameFromSrc(src, defaultName) {
1785
1805
  return name || defaultName;
1786
1806
  }
1787
1807
 
1808
+ // src/host/html/index.tsx
1809
+ init_constants2();
1810
+
1788
1811
  // src/runtime/html/apply-origin.ts
1789
1812
  var tagNames = [
1790
1813
  "img",
@@ -1849,6 +1872,41 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
1849
1872
 
1850
1873
  // src/runtime/html/parse-remote-html.ts
1851
1874
  init_constants2();
1875
+
1876
+ // src/runtime/metadata.ts
1877
+ init_constants2();
1878
+ var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
1879
+ var VALID_TYPES = /* @__PURE__ */ new Set([
1880
+ "nextjs",
1881
+ "remote-component",
1882
+ "unknown"
1883
+ ]);
1884
+ function isRuntime(value) {
1885
+ return VALID_RUNTIMES.has(value);
1886
+ }
1887
+ function isComponentType(value) {
1888
+ return VALID_TYPES.has(value);
1889
+ }
1890
+ function toRuntime(value) {
1891
+ return value && isRuntime(value) ? value : "webpack";
1892
+ }
1893
+ function toComponentType(value) {
1894
+ return value && isComponentType(value) ? value : "unknown";
1895
+ }
1896
+ function buildMetadata(attrs, url) {
1897
+ const id = attrs.id || DEFAULT_COMPONENT_NAME;
1898
+ const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
1899
+ return {
1900
+ name: attrs.name || id.replace(/_ssr$/, ""),
1901
+ bundle,
1902
+ route: attrs.route || url.pathname || DEFAULT_ROUTE,
1903
+ runtime: toRuntime(attrs.runtime),
1904
+ id,
1905
+ type: toComponentType(attrs.type)
1906
+ };
1907
+ }
1908
+
1909
+ // src/runtime/html/parse-remote-html.ts
1852
1910
  init_error();
1853
1911
  function validateSingleComponent(doc, name, url) {
1854
1912
  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}"]`)) {
@@ -1868,14 +1926,6 @@ function resolveComponentName(component, nextData, fallbackName) {
1868
1926
  const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
1869
1927
  return { name, isRemoteComponent };
1870
1928
  }
1871
- function extractComponentMetadata(component, nextData, name, url) {
1872
- return {
1873
- name,
1874
- bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
1875
- route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
1876
- runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
1877
- };
1878
- }
1879
1929
  function extractRemoteShared(doc, name, nextData) {
1880
1930
  const remoteSharedEl = doc.querySelector(
1881
1931
  `#${name}_shared[data-remote-components-shared]`
@@ -1887,7 +1937,7 @@ function extractRemoteShared(doc, name, nextData) {
1887
1937
  function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
1888
1938
  if (!component || !(rsc || nextData || isRemoteComponent)) {
1889
1939
  throw new RemoteComponentsError(
1890
- `Remote Component not found on ${url}.${name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
1940
+ `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>?`
1891
1941
  );
1892
1942
  }
1893
1943
  }
@@ -1913,10 +1963,15 @@ function parseRemoteComponentDocument(doc, name, url) {
1913
1963
  name
1914
1964
  );
1915
1965
  const rsc = doc.querySelector(`#${resolvedName}_rsc`);
1916
- const metadata = extractComponentMetadata(
1917
- component,
1918
- nextData,
1919
- resolvedName,
1966
+ const metadata = buildMetadata(
1967
+ {
1968
+ name: resolvedName,
1969
+ bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
1970
+ route: component?.getAttribute("data-route") ?? nextData?.page,
1971
+ runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
1972
+ id: component?.getAttribute("id"),
1973
+ type: component?.getAttribute("data-type")
1974
+ },
1920
1975
  url
1921
1976
  );
1922
1977
  const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
@@ -2132,12 +2187,7 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2132
2187
  }
2133
2188
  if (type === "webpack") {
2134
2189
  const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
2135
- return webpackRuntime2(
2136
- bundle ?? "default",
2137
- shared,
2138
- remoteShared,
2139
- resolveClientUrl
2140
- );
2190
+ return webpackRuntime2(bundle, shared, remoteShared, resolveClientUrl);
2141
2191
  } else if (type === "turbopack") {
2142
2192
  const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
2143
2193
  return turbopackRuntime2(
@@ -2160,8 +2210,8 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2160
2210
  var import_jsx_runtime2 = require("react/jsx-runtime");
2161
2211
  if (typeof HTMLElement !== "undefined") {
2162
2212
  class RemoteComponent extends HTMLElement {
2163
- name;
2164
- bundle;
2213
+ name = DEFAULT_COMPONENT_NAME;
2214
+ bundle = DEFAULT_BUNDLE_NAME;
2165
2215
  fallbackSlot;
2166
2216
  __next = null;
2167
2217
  fouc = null;
@@ -2277,8 +2327,7 @@ if (typeof HTMLElement !== "undefined") {
2277
2327
  this.fallbackSlot = document.createElement("slot");
2278
2328
  this.root.appendChild(this.fallbackSlot);
2279
2329
  }
2280
- this.name = this.getAttribute("name") || "__vercel_remote_component";
2281
- this.bundle = "default";
2330
+ this.name = this.getAttribute("name") || this.name;
2282
2331
  this.hostState.stage = "loading";
2283
2332
  const src = this.src;
2284
2333
  this.hostState.abortController = new AbortController();
@@ -2298,10 +2347,7 @@ if (typeof HTMLElement !== "undefined") {
2298
2347
  let html = this.innerHTML;
2299
2348
  if (src) {
2300
2349
  url = getClientOrServerUrl(src, window.location.href);
2301
- this.name = resolveNameFromSrc(
2302
- src,
2303
- this.name ?? "__vercel_remote_component"
2304
- );
2350
+ this.name = resolveNameFromSrc(src, this.name);
2305
2351
  }
2306
2352
  const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
2307
2353
  if (!remoteComponentChild && url) {
@@ -2344,7 +2390,7 @@ if (typeof HTMLElement !== "undefined") {
2344
2390
  const doc = parser.parseFromString(html, "text/html");
2345
2391
  const parsed = parseRemoteComponentDocument(
2346
2392
  doc,
2347
- this.name ?? "__vercel_remote_component",
2393
+ this.name,
2348
2394
  url ?? new URL(window.location.href)
2349
2395
  );
2350
2396
  const {
@@ -2368,7 +2414,7 @@ if (typeof HTMLElement !== "undefined") {
2368
2414
  if (!self2.__remote_bundle_url__) {
2369
2415
  self2.__remote_bundle_url__ = {};
2370
2416
  }
2371
- self2.__remote_bundle_url__[this.bundle ?? "default"] = url;
2417
+ self2.__remote_bundle_url__[this.bundle] = url;
2372
2418
  }
2373
2419
  const metadataEl = document.createElement("script");
2374
2420
  metadataEl.type = "application/json";
@@ -2560,12 +2606,7 @@ if (typeof HTMLElement !== "undefined") {
2560
2606
  window.location.href
2561
2607
  );
2562
2608
  }
2563
- await preloadScripts(
2564
- Array.from(scripts),
2565
- url,
2566
- this.bundle ?? "default",
2567
- this.name ?? "__vercel_remote_component"
2568
- );
2609
+ await preloadScripts(Array.from(scripts), url, this.bundle, this.name);
2569
2610
  if (!isCurrentLoad()) {
2570
2611
  return abandonLoad();
2571
2612
  }
@@ -2644,7 +2685,7 @@ if (typeof HTMLElement !== "undefined") {
2644
2685
  RemoteComponentFromReadableStream,
2645
2686
  {
2646
2687
  initial: false,
2647
- name: this.name ?? "__vercel_remote_component"
2688
+ name: this.name
2648
2689
  }
2649
2690
  )
2650
2691
  );
@@ -2655,17 +2696,11 @@ if (typeof HTMLElement !== "undefined") {
2655
2696
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
2656
2697
  // @ts-expect-error support for shadow DOM
2657
2698
  this.root,
2658
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2659
- RemoteComponentFromReadableStream,
2660
- {
2661
- initial: true,
2662
- name: this.name ?? "__vercel_remote_component"
2663
- }
2664
- )
2699
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromReadableStream, { initial: true, name: this.name })
2665
2700
  );
2666
2701
  } else if (nextData) {
2667
2702
  const { Component, App } = nextClientPagesLoader2(
2668
- this.bundle ?? "default",
2703
+ this.bundle,
2669
2704
  nextData.page ?? "/",
2670
2705
  this.root
2671
2706
  );