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
package/dist/host/html.js CHANGED
@@ -201,17 +201,17 @@ var init_utils = __esm({
201
201
  function getBundleKey(bundle) {
202
202
  return escapeString(bundle);
203
203
  }
204
- var DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT, REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE;
204
+ var DEFAULT_BUNDLE_NAME, DEFAULT_COMPONENT_NAME, DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT;
205
205
  var init_constants2 = __esm({
206
206
  "src/runtime/constants.ts"() {
207
207
  "use strict";
208
208
  init_utils();
209
+ DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
210
+ DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
209
211
  DEFAULT_ROUTE = "/";
210
212
  RUNTIME_WEBPACK = "webpack";
211
213
  RUNTIME_TURBOPACK = "turbopack";
212
214
  RUNTIME_SCRIPT = "script";
213
- REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
214
- NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
215
215
  }
216
216
  });
217
217
 
@@ -584,6 +584,16 @@ var init_polyfill = __esm({
584
584
  }
585
585
  });
586
586
 
587
+ // src/runtime/patterns.ts
588
+ var REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE;
589
+ var init_patterns = __esm({
590
+ "src/runtime/patterns.ts"() {
591
+ "use strict";
592
+ REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
593
+ NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
594
+ }
595
+ });
596
+
587
597
  // src/runtime/loaders/script-loader.ts
588
598
  async function loadScripts(scripts, resolveClientUrl) {
589
599
  await Promise.all(
@@ -620,7 +630,7 @@ async function loadScripts(scripts, resolveClientUrl) {
620
630
  var init_script_loader = __esm({
621
631
  "src/runtime/loaders/script-loader.ts"() {
622
632
  "use strict";
623
- init_constants2();
633
+ init_patterns();
624
634
  init_protected_rc_fallback();
625
635
  init_error();
626
636
  init_logger();
@@ -721,15 +731,15 @@ var init_webpack = __esm({
721
731
  init_apply_shared_modules();
722
732
  init_next_client_pages_loader();
723
733
  init_polyfill();
724
- init_constants2();
725
734
  init_script_loader();
735
+ init_patterns();
726
736
  init_error();
727
737
  }
728
738
  });
729
739
 
730
740
  // src/runtime/turbopack/patterns.ts
731
741
  var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
732
- var init_patterns = __esm({
742
+ var init_patterns2 = __esm({
733
743
  "src/runtime/turbopack/patterns.ts"() {
734
744
  "use strict";
735
745
  REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
@@ -952,10 +962,11 @@ var init_chunk_loader = __esm({
952
962
  "src/runtime/turbopack/chunk-loader.ts"() {
953
963
  "use strict";
954
964
  init_constants2();
965
+ init_patterns();
955
966
  init_protected_rc_fallback();
956
967
  init_error();
957
968
  init_logger();
958
- init_patterns();
969
+ init_patterns2();
959
970
  }
960
971
  });
961
972
 
@@ -1321,7 +1332,7 @@ var init_shared_modules = __esm({
1321
1332
  init_constants2();
1322
1333
  init_logger();
1323
1334
  init_module();
1324
- init_patterns();
1335
+ init_patterns2();
1325
1336
  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).";
1326
1337
  }
1327
1338
  });
@@ -1349,7 +1360,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1349
1360
  }
1350
1361
  }
1351
1362
  if (runtime === RUNTIME_TURBOPACK) {
1352
- await Promise.all(
1363
+ const results = await Promise.allSettled(
1353
1364
  scripts.map((script) => {
1354
1365
  if (script.src) {
1355
1366
  return self.__webpack_chunk_load__?.(script.src, bundle);
@@ -1357,6 +1368,14 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1357
1368
  return Promise.resolve(void 0);
1358
1369
  })
1359
1370
  );
1371
+ for (const result of results) {
1372
+ if (result.status === "rejected") {
1373
+ logWarn(
1374
+ "WebpackRuntime",
1375
+ `Initial chunk load failed: ${String(result.reason)}`
1376
+ );
1377
+ }
1378
+ }
1360
1379
  }
1361
1380
  const coreShared = {
1362
1381
  react: async () => (await import("react")).default,
@@ -1424,6 +1443,7 @@ var init_webpack_runtime = __esm({
1424
1443
  "src/runtime/turbopack/webpack-runtime.ts"() {
1425
1444
  "use strict";
1426
1445
  init_constants2();
1446
+ init_patterns();
1427
1447
  init_error();
1428
1448
  init_logger();
1429
1449
  init_chunk_loader();
@@ -1757,6 +1777,9 @@ function resolveNameFromSrc(src, defaultName) {
1757
1777
  return name || defaultName;
1758
1778
  }
1759
1779
 
1780
+ // src/host/html/index.tsx
1781
+ init_constants2();
1782
+
1760
1783
  // src/runtime/html/apply-origin.ts
1761
1784
  var tagNames = [
1762
1785
  "img",
@@ -1821,6 +1844,41 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
1821
1844
 
1822
1845
  // src/runtime/html/parse-remote-html.ts
1823
1846
  init_constants2();
1847
+
1848
+ // src/runtime/metadata.ts
1849
+ init_constants2();
1850
+ var VALID_RUNTIMES = /* @__PURE__ */ new Set(["webpack", "turbopack", "script"]);
1851
+ var VALID_TYPES = /* @__PURE__ */ new Set([
1852
+ "nextjs",
1853
+ "remote-component",
1854
+ "unknown"
1855
+ ]);
1856
+ function isRuntime(value) {
1857
+ return VALID_RUNTIMES.has(value);
1858
+ }
1859
+ function isComponentType(value) {
1860
+ return VALID_TYPES.has(value);
1861
+ }
1862
+ function toRuntime(value) {
1863
+ return value && isRuntime(value) ? value : "webpack";
1864
+ }
1865
+ function toComponentType(value) {
1866
+ return value && isComponentType(value) ? value : "unknown";
1867
+ }
1868
+ function buildMetadata(attrs, url) {
1869
+ const id = attrs.id || DEFAULT_COMPONENT_NAME;
1870
+ const bundle = attrs.bundle || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || DEFAULT_BUNDLE_NAME;
1871
+ return {
1872
+ name: attrs.name || id.replace(/_ssr$/, ""),
1873
+ bundle,
1874
+ route: attrs.route || url.pathname || DEFAULT_ROUTE,
1875
+ runtime: toRuntime(attrs.runtime),
1876
+ id,
1877
+ type: toComponentType(attrs.type)
1878
+ };
1879
+ }
1880
+
1881
+ // src/runtime/html/parse-remote-html.ts
1824
1882
  init_error();
1825
1883
  function validateSingleComponent(doc, name, url) {
1826
1884
  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}"]`)) {
@@ -1840,14 +1898,6 @@ function resolveComponentName(component, nextData, fallbackName) {
1840
1898
  const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
1841
1899
  return { name, isRemoteComponent };
1842
1900
  }
1843
- function extractComponentMetadata(component, nextData, name, url) {
1844
- return {
1845
- name,
1846
- bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
1847
- route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
1848
- runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
1849
- };
1850
- }
1851
1901
  function extractRemoteShared(doc, name, nextData) {
1852
1902
  const remoteSharedEl = doc.querySelector(
1853
1903
  `#${name}_shared[data-remote-components-shared]`
@@ -1859,7 +1909,7 @@ function extractRemoteShared(doc, name, nextData) {
1859
1909
  function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
1860
1910
  if (!component || !(rsc || nextData || isRemoteComponent)) {
1861
1911
  throw new RemoteComponentsError(
1862
- `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>?`
1912
+ `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>?`
1863
1913
  );
1864
1914
  }
1865
1915
  }
@@ -1885,10 +1935,15 @@ function parseRemoteComponentDocument(doc, name, url) {
1885
1935
  name
1886
1936
  );
1887
1937
  const rsc = doc.querySelector(`#${resolvedName}_rsc`);
1888
- const metadata = extractComponentMetadata(
1889
- component,
1890
- nextData,
1891
- resolvedName,
1938
+ const metadata = buildMetadata(
1939
+ {
1940
+ name: resolvedName,
1941
+ bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
1942
+ route: component?.getAttribute("data-route") ?? nextData?.page,
1943
+ runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
1944
+ id: component?.getAttribute("id"),
1945
+ type: component?.getAttribute("data-type")
1946
+ },
1892
1947
  url
1893
1948
  );
1894
1949
  const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
@@ -2104,12 +2159,7 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2104
2159
  }
2105
2160
  if (type === "webpack") {
2106
2161
  const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
2107
- return webpackRuntime2(
2108
- bundle ?? "default",
2109
- shared,
2110
- remoteShared,
2111
- resolveClientUrl
2112
- );
2162
+ return webpackRuntime2(bundle, shared, remoteShared, resolveClientUrl);
2113
2163
  } else if (type === "turbopack") {
2114
2164
  const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
2115
2165
  return turbopackRuntime2(
@@ -2132,8 +2182,8 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2132
2182
  import { jsx as jsx2 } from "react/jsx-runtime";
2133
2183
  if (typeof HTMLElement !== "undefined") {
2134
2184
  class RemoteComponent extends HTMLElement {
2135
- name;
2136
- bundle;
2185
+ name = DEFAULT_COMPONENT_NAME;
2186
+ bundle = DEFAULT_BUNDLE_NAME;
2137
2187
  fallbackSlot;
2138
2188
  __next = null;
2139
2189
  fouc = null;
@@ -2249,8 +2299,7 @@ if (typeof HTMLElement !== "undefined") {
2249
2299
  this.fallbackSlot = document.createElement("slot");
2250
2300
  this.root.appendChild(this.fallbackSlot);
2251
2301
  }
2252
- this.name = this.getAttribute("name") || "__vercel_remote_component";
2253
- this.bundle = "default";
2302
+ this.name = this.getAttribute("name") || this.name;
2254
2303
  this.hostState.stage = "loading";
2255
2304
  const src = this.src;
2256
2305
  this.hostState.abortController = new AbortController();
@@ -2270,10 +2319,7 @@ if (typeof HTMLElement !== "undefined") {
2270
2319
  let html = this.innerHTML;
2271
2320
  if (src) {
2272
2321
  url = getClientOrServerUrl(src, window.location.href);
2273
- this.name = resolveNameFromSrc(
2274
- src,
2275
- this.name ?? "__vercel_remote_component"
2276
- );
2322
+ this.name = resolveNameFromSrc(src, this.name);
2277
2323
  }
2278
2324
  const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
2279
2325
  if (!remoteComponentChild && url) {
@@ -2316,7 +2362,7 @@ if (typeof HTMLElement !== "undefined") {
2316
2362
  const doc = parser.parseFromString(html, "text/html");
2317
2363
  const parsed = parseRemoteComponentDocument(
2318
2364
  doc,
2319
- this.name ?? "__vercel_remote_component",
2365
+ this.name,
2320
2366
  url ?? new URL(window.location.href)
2321
2367
  );
2322
2368
  const {
@@ -2340,7 +2386,7 @@ if (typeof HTMLElement !== "undefined") {
2340
2386
  if (!self2.__remote_bundle_url__) {
2341
2387
  self2.__remote_bundle_url__ = {};
2342
2388
  }
2343
- self2.__remote_bundle_url__[this.bundle ?? "default"] = url;
2389
+ self2.__remote_bundle_url__[this.bundle] = url;
2344
2390
  }
2345
2391
  const metadataEl = document.createElement("script");
2346
2392
  metadataEl.type = "application/json";
@@ -2532,12 +2578,7 @@ if (typeof HTMLElement !== "undefined") {
2532
2578
  window.location.href
2533
2579
  );
2534
2580
  }
2535
- await preloadScripts(
2536
- Array.from(scripts),
2537
- url,
2538
- this.bundle ?? "default",
2539
- this.name ?? "__vercel_remote_component"
2540
- );
2581
+ await preloadScripts(Array.from(scripts), url, this.bundle, this.name);
2541
2582
  if (!isCurrentLoad()) {
2542
2583
  return abandonLoad();
2543
2584
  }
@@ -2616,7 +2657,7 @@ if (typeof HTMLElement !== "undefined") {
2616
2657
  RemoteComponentFromReadableStream,
2617
2658
  {
2618
2659
  initial: false,
2619
- name: this.name ?? "__vercel_remote_component"
2660
+ name: this.name
2620
2661
  }
2621
2662
  )
2622
2663
  );
@@ -2627,17 +2668,11 @@ if (typeof HTMLElement !== "undefined") {
2627
2668
  // hydrateRoot expects a document or element, but it works for the shadow DOM too
2628
2669
  // @ts-expect-error support for shadow DOM
2629
2670
  this.root,
2630
- /* @__PURE__ */ jsx2(
2631
- RemoteComponentFromReadableStream,
2632
- {
2633
- initial: true,
2634
- name: this.name ?? "__vercel_remote_component"
2635
- }
2636
- )
2671
+ /* @__PURE__ */ jsx2(RemoteComponentFromReadableStream, { initial: true, name: this.name })
2637
2672
  );
2638
2673
  } else if (nextData) {
2639
2674
  const { Component, App } = nextClientPagesLoader2(
2640
- this.bundle ?? "default",
2675
+ this.bundle,
2641
2676
  nextData.page ?? "/",
2642
2677
  this.root
2643
2678
  );