remote-components 0.0.33 → 0.0.34

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 (50) hide show
  1. package/dist/{component-loader-28ad0083.d.ts → component-loader-8951c052.d.ts} +6 -4
  2. package/dist/html/host.cjs +227 -13
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +227 -13
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/html/remote.cjs +198 -0
  7. package/dist/html/remote.cjs.map +1 -0
  8. package/dist/html/remote.d.ts +2 -0
  9. package/dist/html/remote.js +197 -0
  10. package/dist/html/remote.js.map +1 -0
  11. package/dist/internal/next/host/app-router-client.cjs +56 -4
  12. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  13. package/dist/internal/next/host/app-router-client.d.ts +3 -3
  14. package/dist/internal/next/host/app-router-client.js +58 -5
  15. package/dist/internal/next/host/app-router-client.js.map +1 -1
  16. package/dist/internal/shared/client/remote-component.cjs +99 -0
  17. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  18. package/dist/internal/shared/client/remote-component.d.ts +11 -4
  19. package/dist/internal/shared/client/remote-component.js +97 -0
  20. package/dist/internal/shared/client/remote-component.js.map +1 -1
  21. package/dist/internal/shared/error.cjs.map +1 -1
  22. package/dist/internal/shared/error.d.ts +1 -1
  23. package/dist/internal/shared/error.js.map +1 -1
  24. package/dist/internal/shared/ssr/dom-flight.cjs +17 -5
  25. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  26. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  27. package/dist/internal/shared/ssr/dom-flight.js +17 -5
  28. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-remote-component.cjs +7 -3
  30. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  31. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +2 -1
  32. package/dist/internal/shared/ssr/fetch-remote-component.js +7 -3
  33. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  34. package/dist/next/host/app-router-server.cjs +1 -0
  35. package/dist/next/host/app-router-server.cjs.map +1 -1
  36. package/dist/next/host/app-router-server.js +1 -0
  37. package/dist/next/host/app-router-server.js.map +1 -1
  38. package/dist/next/host/client/index.cjs +292 -103
  39. package/dist/next/host/client/index.cjs.map +1 -1
  40. package/dist/next/host/client/index.d.ts +1 -1
  41. package/dist/next/host/client/index.js +289 -102
  42. package/dist/next/host/client/index.js.map +1 -1
  43. package/dist/react/index.cjs +197 -103
  44. package/dist/react/index.cjs.map +1 -1
  45. package/dist/react/index.d.ts +2 -2
  46. package/dist/react/index.js +196 -102
  47. package/dist/react/index.js.map +1 -1
  48. package/dist/{types-7c207455.d.ts → types-4e7dea94.d.ts} +2 -1
  49. package/dist/{types-e4a3fa37.d.ts → types-cbf6c34f.d.ts} +2 -2
  50. package/package.json +8 -1
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { a as LoadRemoteComponentProps } from '../../../component-loader-28ad0083.js';
3
+ import { L as LoadRemoteComponentProps } from '../../../component-loader-8951c052.js';
4
4
 
5
5
  declare module 'react/jsx-runtime' {
6
6
  namespace JSX {
@@ -196,6 +196,7 @@ var attrToProp = {
196
196
  var DEFAULT_ROUTE = "/";
197
197
  var RUNTIME_WEBPACK = "webpack";
198
198
  var RUNTIME_TURBOPACK = "turbopack";
199
+ var RUNTIME_SCRIPT = "script";
199
200
  var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
200
201
  function getBundleKey(bundle) {
201
202
  return escapeString(bundle);
@@ -903,6 +904,100 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
903
904
  return { component };
904
905
  }
905
906
 
907
+ // src/shared/client/static-loader.ts
908
+ async function loadStaticRemoteComponent(scripts, url) {
909
+ const self = globalThis;
910
+ if (self.__remote_script_entrypoint_mount__?.[url.href]) {
911
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
912
+ }
913
+ if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
914
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
915
+ }
916
+ const mountUnmountSets = await Promise.all(
917
+ scripts.map(async (script) => {
918
+ try {
919
+ let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
920
+ if (!src && script.textContent) {
921
+ const blob = new Blob(
922
+ [
923
+ script.textContent.replace(
924
+ /import\.meta\.url/g,
925
+ JSON.stringify(url)
926
+ )
927
+ ],
928
+ {
929
+ type: "text/javascript"
930
+ }
931
+ );
932
+ src = URL.createObjectURL(blob);
933
+ }
934
+ const mod = await import(
935
+ /* @vite-ignore */
936
+ /* webpackIgnore: true */
937
+ new URL(src, url).href
938
+ );
939
+ if (src.startsWith("blob:")) {
940
+ URL.revokeObjectURL(src);
941
+ }
942
+ if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
943
+ if (!self.__remote_script_entrypoint_mount__) {
944
+ self.__remote_script_entrypoint_mount__ = {};
945
+ }
946
+ if (!self.__remote_script_entrypoint_mount__[url.href]) {
947
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
948
+ }
949
+ self.__remote_script_entrypoint_mount__[url.href]?.add(
950
+ mod.mount || mod.default?.mount || (() => {
951
+ })
952
+ );
953
+ }
954
+ if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
955
+ if (!self.__remote_script_entrypoint_unmount__) {
956
+ self.__remote_script_entrypoint_unmount__ = {};
957
+ }
958
+ if (!self.__remote_script_entrypoint_unmount__[url.href]) {
959
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
960
+ }
961
+ self.__remote_script_entrypoint_unmount__[url.href]?.add(
962
+ mod.unmount || mod.default?.unmount || (() => {
963
+ })
964
+ );
965
+ }
966
+ return {
967
+ mount: mod.mount || mod.default?.mount,
968
+ unmount: mod.unmount || mod.default?.unmount
969
+ };
970
+ } catch (e) {
971
+ console.error(
972
+ new RemoteComponentsError(
973
+ `Error loading remote component script from "${script.src || url.href}".`,
974
+ { cause: e }
975
+ )
976
+ );
977
+ return {
978
+ mount: void 0,
979
+ unmount: void 0
980
+ };
981
+ }
982
+ })
983
+ );
984
+ return mountUnmountSets.reduce(
985
+ (acc, { mount, unmount }) => {
986
+ if (typeof mount === "function") {
987
+ acc.mount.add(mount);
988
+ }
989
+ if (typeof unmount === "function") {
990
+ acc.unmount.add(unmount);
991
+ }
992
+ return acc;
993
+ },
994
+ {
995
+ mount: /* @__PURE__ */ new Set(),
996
+ unmount: /* @__PURE__ */ new Set()
997
+ }
998
+ );
999
+ }
1000
+
906
1001
  // src/shared/client/set-attributes-from-props.ts
907
1002
  var DOMAttributeNames = {
908
1003
  acceptCharset: "accept-charset",
@@ -1230,7 +1325,7 @@ function getRemoteComponentHtml(html) {
1230
1325
  return ssrRemoteComponentContainer.innerHTML;
1231
1326
  }
1232
1327
  const remoteComponentContainer = temp.querySelectorAll(
1233
- `div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next`
1328
+ `div[data-bundle][data-route][data-runtime][id^="__vercel_remote_component"],div[data-bundle][data-route],div#__next,remote-component:not([src])`
1234
1329
  );
1235
1330
  if (remoteComponentContainer.length > 0) {
1236
1331
  return `${Array.from(temp.querySelectorAll("link,script")).map((link) => link.outerHTML).join("")}${Array.from(remoteComponentContainer).map((container) => container.outerHTML).join("")}`;
@@ -1295,6 +1390,10 @@ function RemoteComponent({
1295
1390
  );
1296
1391
  const prevSrcRef = useRef(null);
1297
1392
  const componentHydrationHtml = useRef(null);
1393
+ const prevIsRemoteComponentRef = useRef(false);
1394
+ const prevUrlRef = useRef(null);
1395
+ const prevRemoteComponentContainerRef = useRef(null);
1396
+ const unmountRef = useRef(null);
1298
1397
  useLayoutEffect(() => {
1299
1398
  if (childrenRef.current.length > 0 && remoteComponent) {
1300
1399
  childrenRef.current.forEach((el) => {
@@ -1407,34 +1506,58 @@ function RemoteComponent({
1407
1506
  }
1408
1507
  const parser = new DOMParser();
1409
1508
  const doc = parser.parseFromString(html, "text/html");
1410
- if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`)) {
1509
+ if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
1510
+ `div[data-bundle][data-route][id^="${name}"]`
1511
+ ) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
1411
1512
  throw multipleRemoteComponentsError(url.href);
1412
1513
  }
1413
1514
  const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
1414
1515
  doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
1415
- doc.querySelector("div#__next");
1516
+ doc.querySelector("div#__next") ?? // fallback to the remote-component web component
1517
+ doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
1416
1518
  const nextData = JSON.parse(
1417
1519
  (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
1418
1520
  );
1419
1521
  const remoteName = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : name);
1420
1522
  const rsc = doc.querySelector(`#${remoteName}_rsc`);
1421
1523
  const bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default";
1524
+ const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
1422
1525
  const metadata = {
1423
1526
  name: remoteName,
1424
1527
  bundle,
1425
- route: component?.getAttribute("data-route") ?? nextData?.page ?? DEFAULT_ROUTE,
1426
- runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_WEBPACK)
1528
+ route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
1529
+ runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
1427
1530
  };
1428
1531
  const remoteSharedEl = doc.querySelector(
1429
1532
  `#${remoteName}_shared[data-remote-components-shared]`
1430
1533
  );
1431
1534
  const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
1432
1535
  remoteSharedEl?.remove();
1433
- if (!component || !(rsc || nextData)) {
1536
+ if (!component || !(rsc || nextData || isRemoteComponent)) {
1434
1537
  throw new RemoteComponentsError(
1435
1538
  `Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
1436
1539
  );
1437
1540
  }
1541
+ if (prevIsRemoteComponentRef.current) {
1542
+ if (shadowRoot) {
1543
+ shadowRoot.innerHTML = "";
1544
+ }
1545
+ const self = globalThis;
1546
+ const prevUrl = prevUrlRef.current;
1547
+ if (prevUrl && self.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
1548
+ const unmountPromises = Promise.all(
1549
+ Array.from(unmountRef.current ?? []).map(
1550
+ async (unmount) => unmount(
1551
+ shadowRoot ?? prevRemoteComponentContainerRef.current
1552
+ )
1553
+ )
1554
+ );
1555
+ unmountRef.current = null;
1556
+ await unmountPromises;
1557
+ }
1558
+ }
1559
+ prevIsRemoteComponentRef.current = isRemoteComponent;
1560
+ prevUrlRef.current = url;
1438
1561
  applyOriginToNodes(doc, url);
1439
1562
  const links = Array.from(
1440
1563
  doc.querySelectorAll("link[href]")
@@ -1449,64 +1572,64 @@ function RemoteComponent({
1449
1572
  return acc;
1450
1573
  }, {})
1451
1574
  }));
1452
- const scripts = doc.querySelectorAll(
1453
- "script[src],script[data-src]"
1454
- );
1455
- const inlineScripts = doc.querySelectorAll(
1575
+ const scripts = (isRemoteComponent ? component : doc).querySelectorAll("script[src],script[data-src]");
1576
+ const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
1456
1577
  "script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
1457
1578
  );
1458
- const self = globalThis;
1459
- const prevNextScripts = self.__next_s;
1460
- const nextScripts = [];
1461
- self.__next_s = nextScripts;
1462
- await Promise.all(
1463
- Array.from(inlineScripts).filter(
1464
- (script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
1465
- "data-remote-components-shared"
1466
- ) === "string")
1467
- ).map((script) => {
1468
- return new Promise((resolve) => {
1469
- if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
1470
- if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
1471
- const newScript = document.createElement("script");
1472
- const blob = new Blob([script.textContent], {
1473
- type: "application/javascript"
1474
- });
1475
- const blobUrl = URL.createObjectURL(blob);
1476
- newScript.onload = () => {
1477
- resolve(void 0);
1478
- URL.revokeObjectURL(blobUrl);
1479
- newScript.remove();
1480
- };
1481
- newScript.onerror = () => {
1482
- URL.revokeObjectURL(blobUrl);
1483
- newScript.remove();
1579
+ if (!isRemoteComponent) {
1580
+ const self = globalThis;
1581
+ const prevNextScripts = self.__next_s;
1582
+ const nextScripts = [];
1583
+ self.__next_s = nextScripts;
1584
+ await Promise.all(
1585
+ Array.from(inlineScripts).filter(
1586
+ (script) => !(script.id.endsWith("_shared") && script.getAttribute("type") === "application/json" && typeof script.getAttribute(
1587
+ "data-remote-components-shared"
1588
+ ) === "string")
1589
+ ).map((script) => {
1590
+ return new Promise((resolve) => {
1591
+ if (script.textContent && !script.textContent.includes("self.__next_f=") && !script.textContent.includes("self.__next_f.push")) {
1592
+ if (!script.getAttribute("type") || script.getAttribute("type") === "text/javascript" || script.getAttribute("type") === "application/javascript") {
1593
+ const newScript = document.createElement("script");
1594
+ const blob = new Blob([script.textContent], {
1595
+ type: "application/javascript"
1596
+ });
1597
+ const blobUrl = URL.createObjectURL(blob);
1598
+ newScript.onload = () => {
1599
+ resolve(void 0);
1600
+ URL.revokeObjectURL(blobUrl);
1601
+ newScript.remove();
1602
+ };
1603
+ newScript.onerror = () => {
1604
+ URL.revokeObjectURL(blobUrl);
1605
+ newScript.remove();
1606
+ resolve(void 0);
1607
+ };
1608
+ newScript.src = blobUrl;
1609
+ document.body.appendChild(newScript);
1610
+ } else {
1484
1611
  resolve(void 0);
1485
- };
1486
- newScript.src = blobUrl;
1487
- document.body.appendChild(newScript);
1612
+ document.body.appendChild(script);
1613
+ }
1488
1614
  } else {
1489
1615
  resolve(void 0);
1490
- document.body.appendChild(script);
1491
1616
  }
1492
- } else {
1493
- resolve(void 0);
1494
- }
1495
- });
1496
- })
1497
- );
1498
- nextScripts.forEach(([scriptSrc, props]) => {
1499
- const script = document.createElement("script");
1500
- if (scriptSrc) {
1501
- script.src = scriptSrc;
1502
- }
1503
- if (typeof props.children === "string") {
1504
- script.textContent = props.children;
1505
- }
1506
- setAttributesFromProps(script, props);
1507
- document.head.appendChild(script);
1508
- });
1509
- self.__next_s = prevNextScripts;
1617
+ });
1618
+ })
1619
+ );
1620
+ nextScripts.forEach(([scriptSrc, props]) => {
1621
+ const script = document.createElement("script");
1622
+ if (scriptSrc) {
1623
+ script.src = scriptSrc;
1624
+ }
1625
+ if (typeof props.children === "string") {
1626
+ script.textContent = props.children;
1627
+ }
1628
+ setAttributesFromProps(script, props);
1629
+ document.head.appendChild(script);
1630
+ });
1631
+ self.__next_s = prevNextScripts;
1632
+ }
1510
1633
  let rscName;
1511
1634
  if (rsc) {
1512
1635
  rscName = `__remote_component_rsc_${escapeString(url.href)}_${escapeString(remoteName)}`;
@@ -1523,7 +1646,11 @@ function RemoteComponent({
1523
1646
  url: url.href,
1524
1647
  data: rsc ? (rsc.textContent || "").split("\n").filter(Boolean) : []
1525
1648
  };
1526
- componentHydrationHtml.current = Array.from(doc.querySelectorAll("link,style")).map((link) => link.outerHTML).join("") + component.innerHTML;
1649
+ componentHydrationHtml.current = `${Array.from(
1650
+ doc.querySelectorAll("link,style")
1651
+ ).map((link) => link.outerHTML).join(
1652
+ ""
1653
+ )}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
1527
1654
  const userShared = await shared;
1528
1655
  if ("__remote_components_missing_shared__" in userShared) {
1529
1656
  userShared.__remote_components_missing_shared__().catch((e) => {
@@ -1534,48 +1661,89 @@ function RemoteComponent({
1534
1661
  remoteShared.__remote_components_missing_shared__
1535
1662
  );
1536
1663
  }
1537
- const result = await loadRemoteComponent({
1538
- url: new URL(url, location.origin),
1539
- name: remoteName,
1540
- rscName,
1541
- bundle,
1542
- route: metadata.route,
1543
- runtime: metadata.runtime,
1544
- data: newData.data,
1545
- nextData,
1546
- scripts: Array.from(scripts).map((script) => {
1547
- const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
1548
- const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
1549
- scriptSrc
1550
- )?.groups ?? {
1551
- prefix: void 0,
1552
- id: scriptSrc
1553
- };
1554
- return {
1555
- src: new URL(
1556
- `${prefix ?? ""}${path}`.replace(
1557
- /(?<char>[^:])(?<double>\/\/)/g,
1558
- "$1/"
1559
- ),
1560
- url
1561
- ).href
1562
- };
1563
- }),
1564
- shared: {
1565
- ...sharedPolyfills(userShared),
1566
- ...userShared
1567
- },
1568
- remoteShared,
1569
- container: shadowRoot
1570
- });
1571
- if (rsc) {
1572
- rsc.remove();
1573
- }
1574
- setData(newData);
1575
- if (result.error) {
1576
- setRemoteComponent(result.error);
1664
+ if (isRemoteComponent) {
1665
+ setData(newData);
1666
+ if (shadowRoot) {
1667
+ let shadowRootHtml = component.innerHTML;
1668
+ if (reset) {
1669
+ shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
1670
+ }
1671
+ shadowRoot.innerHTML = shadowRootHtml;
1672
+ setRemoteComponent(null);
1673
+ const { mount, unmount } = await loadStaticRemoteComponent(
1674
+ Array.from(shadowRoot.querySelectorAll("script")),
1675
+ url
1676
+ );
1677
+ unmountRef.current = unmount;
1678
+ await Promise.all(
1679
+ Array.from(mount).map((mountFn) => mountFn(shadowRoot))
1680
+ );
1681
+ } else if (isolate === false) {
1682
+ setRemoteComponent(
1683
+ // TODO: remove wrapper div by converting HTML to RSC or React tree
1684
+ /* @__PURE__ */ jsx2(
1685
+ "div",
1686
+ {
1687
+ dangerouslySetInnerHTML: { __html: component.innerHTML },
1688
+ ref: prevRemoteComponentContainerRef
1689
+ }
1690
+ )
1691
+ );
1692
+ const { mount, unmount } = await loadStaticRemoteComponent(
1693
+ Array.from(component.querySelectorAll("script")),
1694
+ url
1695
+ );
1696
+ unmountRef.current = unmount;
1697
+ await Promise.all(
1698
+ Array.from(mount).map(
1699
+ (mountFn) => mountFn(prevRemoteComponentContainerRef.current)
1700
+ )
1701
+ );
1702
+ }
1577
1703
  } else {
1578
- setRemoteComponent(result.component);
1704
+ const result = await loadRemoteComponent({
1705
+ url: new URL(url, location.origin),
1706
+ name: remoteName,
1707
+ rscName,
1708
+ bundle,
1709
+ route: metadata.route,
1710
+ runtime: metadata.runtime,
1711
+ data: newData.data,
1712
+ nextData,
1713
+ scripts: Array.from(scripts).map((script) => {
1714
+ const scriptSrc = script.getAttribute("data-src") || script.getAttribute("src") || script.src;
1715
+ const { prefix, id: path } = REMOTE_COMPONENT_REGEX.exec(
1716
+ scriptSrc
1717
+ )?.groups ?? {
1718
+ prefix: void 0,
1719
+ id: scriptSrc
1720
+ };
1721
+ return {
1722
+ src: new URL(
1723
+ `${prefix ?? ""}${path}`.replace(
1724
+ /(?<char>[^:])(?<double>\/\/)/g,
1725
+ "$1/"
1726
+ ),
1727
+ url
1728
+ ).href
1729
+ };
1730
+ }),
1731
+ shared: {
1732
+ ...sharedPolyfills(userShared),
1733
+ ...userShared
1734
+ },
1735
+ remoteShared,
1736
+ container: shadowRoot
1737
+ });
1738
+ if (rsc) {
1739
+ rsc.remove();
1740
+ }
1741
+ setData(newData);
1742
+ if (result.error) {
1743
+ setRemoteComponent(result.error);
1744
+ } else {
1745
+ setRemoteComponent(result.component);
1746
+ }
1579
1747
  }
1580
1748
  } catch (error) {
1581
1749
  setRemoteComponent(error);
@@ -1590,7 +1758,8 @@ function RemoteComponent({
1590
1758
  name,
1591
1759
  shared,
1592
1760
  shadowRoot,
1593
- additionalHeaders
1761
+ additionalHeaders,
1762
+ reset
1594
1763
  ]);
1595
1764
  if (remoteComponent instanceof Error) {
1596
1765
  throw remoteComponent;
@@ -1599,7 +1768,7 @@ function RemoteComponent({
1599
1768
  name: data?.name || name,
1600
1769
  bundle: data?.bundle || "default",
1601
1770
  route: data?.route || DEFAULT_ROUTE,
1602
- runtime: data?.runtime || RUNTIME_WEBPACK
1771
+ runtime: prevIsRemoteComponentRef.current ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
1603
1772
  }) });
1604
1773
  const resetStyle = reset ? /* @__PURE__ */ jsx2("style", { "data-remote-components-reset": "", children: `:host { all: initial; }` }) : null;
1605
1774
  const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement2(
@@ -1618,6 +1787,24 @@ function RemoteComponent({
1618
1787
  if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {
1619
1788
  shadowRoot.innerHTML = componentHydrationHtml.current;
1620
1789
  componentHydrationHtml.current = null;
1790
+ if (prevIsRemoteComponentRef.current) {
1791
+ loadStaticRemoteComponent(
1792
+ Array.from(shadowRoot.querySelectorAll("script")),
1793
+ url
1794
+ ).then(({ mount }) => {
1795
+ return Promise.all(
1796
+ Array.from(mount).map((mountFn) => mountFn(shadowRoot))
1797
+ );
1798
+ }).catch((e) => {
1799
+ const error = new RemoteComponentsError(
1800
+ `Error mounting remote component from "${url.href}"`,
1801
+ {
1802
+ cause: e
1803
+ }
1804
+ );
1805
+ setRemoteComponent(error);
1806
+ });
1807
+ }
1621
1808
  }
1622
1809
  if (isolate !== false) {
1623
1810
  const shadowRemoteComponentHtml = shadowRoot?.querySelector(`#__REMOTE_COMPONENT${name}`) ?? shadowRoot?.querySelector("div[data-bundle][data-route]");