@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.15

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.
@@ -1,5 +1,5 @@
1
1
  import { DEV, OBSERVE, getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
2
- import { insert } from '@solidjs/web';
2
+ import { installServerComponentHydration, insert } from '@solidjs/web';
3
3
  import { frameAddress, SINGLE_FLIGHT_HEADER, LIVE_WIRE, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
4
  import { sharedConfig, createLoadingBoundary } from 'solid-js/internal';
5
5
 
@@ -494,7 +494,7 @@ class FrameImpl {
494
494
  #syncSlots(root) {
495
495
  if (!this.#slots && !this.#outer) return;
496
496
  const found = new Map();
497
- if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
497
+ if (root) collectSlots(root, found, found);else this.#collectSlots(found, found);
498
498
  let waiting = false;
499
499
  const R = tierLoads.regions?.r;
500
500
  const B = tierLoads.bind?.r;
@@ -618,7 +618,7 @@ class FrameImpl {
618
618
  return props;
619
619
  }
620
620
  #collectSlots(found, elements) {
621
- collectSlots(this.#element.firstChild, null, found, elements);
621
+ collectSlots(this.#element, found, elements);
622
622
  }
623
623
  #findPlaceholder(name, root) {
624
624
  return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
@@ -889,27 +889,41 @@ function findPlaceholder(n, end, id) {
889
889
  }
890
890
  return null;
891
891
  }
892
- function collectSlots(n, end, out, elements) {
893
- while (n && n !== end) {
894
- const id = slotStartId(n);
895
- if (id !== null) {
896
- devCheckRange(n, id);
892
+ function collectSlots(root, out, elements) {
893
+ let announced;
894
+ const bind = elements && (tierLoads.bind || !(announced = globalThis._$HY?.r?.["sc:tiers"]) || announced.includes("bind"));
895
+ const B = bind && tierLoads.bind?.r;
896
+ const w = root.ownerDocument.createTreeWalker(root, bind ? 0x81 : 0x80);
897
+ let n, p;
898
+ while (n = w.nextNode()) {
899
+ if (n.nodeType !== COMMENT_NODE) {
900
+ if (!n.hasAttribute(FRAME_ID_ATTR)) {
901
+ if (n.hasAttributes()) B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
902
+ continue;
903
+ }
904
+ p = n;
905
+ } else if (n.data.startsWith("slot:")) {
906
+ const id = slotStartId(n);
907
+ if (!id) continue;
908
+ if (!bind) {
909
+ for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
910
+ if (p !== root) continue;
911
+ }
897
912
  if (!out.has(id)) out.set(id, n);
898
- n = afterRange(n, id);
899
- continue;
900
- }
901
- if (elements !== undefined && isTextStart(n)) {
902
- const B = tierLoads.bind?.r;
903
- B ? B.text(n, elements) : elements.b = true;
904
- }
905
- if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
906
- if (elements !== undefined && n.hasAttributes()) {
907
- const B = tierLoads.bind?.r;
908
- B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
913
+ const end = findMarker(n, slotEnd(id));
914
+ if (end) {
915
+ w.currentNode = end;
916
+ continue;
909
917
  }
910
- collectSlots(n.firstChild, null, out, elements);
918
+ devReportRange(id);
919
+ p = n.parentNode;
920
+ if (p === root) return;
921
+ } else {
922
+ if (bind && n.data.startsWith(SLOT_TEXT)) B ? B.text(n, elements) : elements.b = true;
923
+ continue;
911
924
  }
912
- n = n.nextSibling;
925
+ while (p.lastChild) p = p.lastChild;
926
+ w.currentNode = p;
913
927
  }
914
928
  }
915
929
  function eachInRange(start, key, cb) {
@@ -993,12 +1007,12 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
993
1007
  oldNode.data = newNode.data;
994
1008
  }
995
1009
  }
996
- const afterRange = (start, id) => afterMarker(start, slotEnd(id));
997
- const afterText = start => afterMarker(start, SLOT_TEXT_END);
998
- function afterMarker(start, end) {
1010
+ const afterRange = (start, id) => findMarker(start, slotEnd(id))?.nextSibling;
1011
+ const afterText = start => findMarker(start, SLOT_TEXT_END)?.nextSibling;
1012
+ function findMarker(start, end) {
999
1013
  let n = start.nextSibling;
1000
1014
  while (n) {
1001
- if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
1015
+ if (n.nodeType === COMMENT_NODE && n.data === end) return n;
1002
1016
  n = n.nextSibling;
1003
1017
  }
1004
1018
  return null;
@@ -1026,13 +1040,8 @@ function devSlotOrphan(frame, occurrence, consumers, why) {
1026
1040
  }
1027
1041
  }, null));
1028
1042
  }
1029
- function devCheckRange(start, id) {
1043
+ function devReportRange(id) {
1030
1044
  const end = slotEnd(id);
1031
- let n = start.nextSibling;
1032
- while (n) {
1033
- if (n.nodeType === COMMENT_NODE && n.data === end) return;
1034
- n = n.nextSibling;
1035
- }
1036
1045
  DEV.report(OBSERVE.diagnostics.emit({
1037
1046
  code: "FRAME_MARKER_CORRUPTED",
1038
1047
  kind: "ssr",
@@ -1516,7 +1525,7 @@ function createServerComponentHandler({
1516
1525
  const target = entry || host;
1517
1526
  const applied = applyFrameResponse(response, target, {
1518
1527
  as: address,
1519
- version
1528
+ version: frameId => frameId === address ? version : bump(frameId)
1520
1529
  }).catch(err => target.apply({
1521
1530
  type: "error",
1522
1531
  id: address,
@@ -1616,24 +1625,22 @@ function followAddress(host, frame, binding) {
1616
1625
  });
1617
1626
  }
1618
1627
  function landing(host, address, value, failed) {
1619
- let thrown = host.get(address)?.error;
1628
+ let frame, thrown;
1629
+ const errored = () => (frame = host.get(address))?.error !== undefined && (thrown === (thrown = frame.version) ? 1 : 2);
1630
+ errored();
1620
1631
  return createMemo(() => {
1621
1632
  failed();
1622
- const error = host.get(address)?.error;
1623
- if (error !== undefined && error !== thrown) {
1624
- thrown = error;
1625
- throw error;
1626
- }
1633
+ const state = errored();
1634
+ if (state > 1) throw frame.error;
1627
1635
  const wait = host.landing(address);
1628
1636
  if (!wait) return value;
1629
- const asked = error !== undefined ? reask(address) : undefined;
1630
- return (asked ? asked.then(() => wait) : wait).then(() => value);
1637
+ return (state ? reask(address, wait) : wait).then(() => value);
1631
1638
  });
1632
1639
  }
1633
- function reask(address) {
1640
+ function reask(address, wait) {
1634
1641
  const call = callFor(address);
1635
1642
  if (!call) console.error(`Server component boundary "${address}" errored, but no call is recorded for it; ` + `reset() cannot re-ask the server. (The address was written by hand, not by a call.)`);
1636
- return call && call.retry();
1643
+ return call ? call.retry().then(() => wait) : wait;
1637
1644
  }
1638
1645
  function failing() {
1639
1646
  const [failed, setFailed] = createSignal(0, {
@@ -1652,6 +1659,29 @@ function getFrameHost() {
1652
1659
  }
1653
1660
  return sharedHost;
1654
1661
  }
1662
+ function claimScope(el) {
1663
+ const registry = sharedConfig.registry;
1664
+ const buckets = new Map();
1665
+ const bucketOf = key => key.slice(0, key.lastIndexOf("-") + 1);
1666
+ const index = root => {
1667
+ if (registry) for (const n of root.querySelectorAll("[_hk]")) {
1668
+ const p = bucketOf(n.getAttribute("_hk"));
1669
+ const b = buckets.get(p);
1670
+ b ? b.push(n) : buckets.set(p, [n]);
1671
+ }
1672
+ };
1673
+ index(el);
1674
+ return {
1675
+ registry,
1676
+ gather(id) {
1677
+ for (const n of buckets.get(bucketOf(id)) || []) {
1678
+ const k = n.getAttribute("_hk");
1679
+ if (k.startsWith(id) && n.isConnected && !registry.has(k)) registry.set(k, n);
1680
+ }
1681
+ },
1682
+ index
1683
+ };
1684
+ }
1655
1685
  function claimRender(prefix, existing, render, scope, bound) {
1656
1686
  const sc = sharedConfig;
1657
1687
  if (!sc.hydrateWindow || !sc.registry) return render();
@@ -1867,7 +1897,10 @@ function findBoundaryElement(id) {
1867
1897
  boundaryIndex = new Map();
1868
1898
  if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1869
1899
  }
1870
- return boundaryIndex.get(id);
1900
+ for (let n = 0;; n++) {
1901
+ const key = n ? id + "~" + (n + 1) : id;
1902
+ if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
1903
+ }
1871
1904
  }
1872
1905
  const arrivals = new Map();
1873
1906
  const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
@@ -1890,6 +1923,7 @@ function boundaryMayArrive() {
1890
1923
  return !hy.done || !!(hy.fr && hy.fr.pending());
1891
1924
  }
1892
1925
  function installRevealHook() {
1926
+ installServerComponentHydration();
1893
1927
  const hy = globalThis._$HY;
1894
1928
  if (!hy || hy.$sc || !hy.fr) return;
1895
1929
  hy.$sc = true;
@@ -1913,22 +1947,22 @@ function installRevealHook() {
1913
1947
  }
1914
1948
  function documentBoundary(host, id, props, binding) {
1915
1949
  installRevealHook();
1916
- const claimed = claimedBoundaries.has(id);
1917
- const el = !claimed ? findBoundaryElement(id) : undefined;
1950
+ const el = findBoundaryElement(id);
1918
1951
  if (el) return adoptBoundary(host, id, el, props, binding);
1919
- if (!claimed && boundaryMayArrive()) {
1952
+ if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
1920
1953
  const owner = getOwner();
1921
1954
  let live = true;
1922
1955
  onCleanup(() => live = false);
1923
1956
  return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
1924
- const node = claimedBoundaries.has(id) ? undefined : findBoundaryElement(id);
1957
+ const node = findBoundaryElement(id);
1925
1958
  return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
1926
1959
  })));
1927
1960
  }
1928
1961
  return boundaryComponent(host, id)(props, binding);
1929
1962
  }
1930
1963
  function adoptBoundary(host, id, el, props, binding) {
1931
- claimedBoundaries.add(id);
1964
+ const siteId = el.getAttribute(FRAME_ID_ATTR);
1965
+ claimedBoundaries.add(siteId);
1932
1966
  const address = binding ? contentAddress(binding()) : id;
1933
1967
  const appliedRecords = new Set();
1934
1968
  const reportedFragments = new Set();
@@ -1947,7 +1981,7 @@ function adoptBoundary(host, id, el, props, binding) {
1947
1981
  const hy = globalThis._$HY;
1948
1982
  if (!hy || !hy.r) return;
1949
1983
  pumpLiveChannel();
1950
- const slotPrefix = `sc:slot:${id}:`;
1984
+ const slotPrefix = `sc:slot:${siteId}:`;
1951
1985
  for (const key of Object.keys(hy.r)) {
1952
1986
  if (appliedRecords.has(key)) continue;
1953
1987
  if (key.startsWith(slotPrefix)) {
@@ -1965,7 +1999,7 @@ function adoptBoundary(host, id, el, props, binding) {
1965
1999
  } else apply(value);
1966
2000
  } else if (key.startsWith("sc:region:")) {
1967
2001
  const childId = key.slice("sc:region:".length);
1968
- if (childId.startsWith(id + ".")) {
2002
+ if (childId.startsWith(siteId + ".")) {
1969
2003
  appliedRecords.add(key);
1970
2004
  const val = hy.r[key];
1971
2005
  const apply = html => host.apply({
@@ -1980,10 +2014,12 @@ function adoptBoundary(host, id, el, props, binding) {
1980
2014
  }
1981
2015
  };
1982
2016
  reportRegionFragments(el);
2017
+ const scope = claimScope(el);
1983
2018
  const fr = globalThis._$HY?.fr;
1984
2019
  let frame;
1985
2020
  const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
1986
2021
  const inside = !!parent && el.contains(parent);
2022
+ inside && scope.index(parent);
1987
2023
  inside && reportRegionFragments(parent);
1988
2024
  drainRecords();
1989
2025
  if (inside && frame) frame.apply({
@@ -1992,7 +2028,7 @@ function adoptBoundary(host, id, el, props, binding) {
1992
2028
  });
1993
2029
  }) : undefined;
1994
2030
  const applyLiveOp = op => {
1995
- if (op.fid && op.fid !== id) return;
2031
+ if (op.fid && op.fid !== siteId) return;
1996
2032
  host.apply({
1997
2033
  ...op,
1998
2034
  id: address,
@@ -2013,16 +2049,13 @@ function adoptBoundary(host, id, el, props, binding) {
2013
2049
  adopt: true,
2014
2050
  host,
2015
2051
  id: address,
2016
- slots: slotsFor(props, {
2017
- registry: sc.registry,
2018
- gather: sc.gather
2019
- }),
2052
+ slots: slotsFor(props, scope),
2020
2053
  ownerScope: boundaryScope(owner),
2021
2054
  reveal: revealSeam(owner),
2022
2055
  onApply,
2023
- hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + id))) : () => {},
2056
+ hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + siteId))) : () => {},
2024
2057
  ...{
2025
- claimScope: id
2058
+ claimScope: siteId
2026
2059
  }
2027
2060
  });
2028
2061
  if (binding) {
@@ -2068,9 +2101,8 @@ function installServerComponents(host = getFrameHost(), options) {
2068
2101
  intercept: ({
2069
2102
  id
2070
2103
  }) => {
2071
- if (claimedBoundaries.has(id)) return undefined;
2072
2104
  if (findBoundaryElement(id)) return true;
2073
- if (!boundaryMayArrive()) return undefined;
2105
+ if (claimedBoundaries.has(id) || !boundaryMayArrive()) return undefined;
2074
2106
  installRevealHook();
2075
2107
  return awaitBoundary(id);
2076
2108
  }
@@ -1,5 +1,5 @@
1
1
  import { getOwner, onCleanup, createMemo, runWithOwner, untrack, createRenderEffect, createSignal, createOwner } from 'solid-js';
2
- import { insert } from '@solidjs/web';
2
+ import { installServerComponentHydration, insert } from '@solidjs/web';
3
3
  import { LIVE_WIRE, ChunkReader, frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, deliverFlightData, ERROR_HEADER, hasFlightMetadata, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
4
4
  import { sharedConfig, createLoadingBoundary } from 'solid-js/internal';
5
5
 
@@ -481,7 +481,7 @@ class FrameImpl {
481
481
  #syncSlots(root) {
482
482
  if (!this.#slots && !this.#outer) return;
483
483
  const found = new Map();
484
- if (root) collectSlots(root.firstChild, null, found, found);else this.#collectSlots(found, found);
484
+ if (root) collectSlots(root, found, found);else this.#collectSlots(found, found);
485
485
  let waiting = false;
486
486
  const R = tierLoads.regions?.r;
487
487
  const B = tierLoads.bind?.r;
@@ -603,7 +603,7 @@ class FrameImpl {
603
603
  return props;
604
604
  }
605
605
  #collectSlots(found, elements) {
606
- collectSlots(this.#element.firstChild, null, found, elements);
606
+ collectSlots(this.#element, found, elements);
607
607
  }
608
608
  #findPlaceholder(name, root) {
609
609
  return findPlaceholder((root || this.#element).firstChild, null, placeholderId(name));
@@ -870,26 +870,40 @@ function findPlaceholder(n, end, id) {
870
870
  }
871
871
  return null;
872
872
  }
873
- function collectSlots(n, end, out, elements) {
874
- while (n && n !== end) {
875
- const id = slotStartId(n);
876
- if (id !== null) {
873
+ function collectSlots(root, out, elements) {
874
+ let announced;
875
+ const bind = elements && (tierLoads.bind || !(announced = globalThis._$HY?.r?.["sc:tiers"]) || announced.includes("bind"));
876
+ const B = bind && tierLoads.bind?.r;
877
+ const w = root.ownerDocument.createTreeWalker(root, bind ? 0x81 : 0x80);
878
+ let n, p;
879
+ while (n = w.nextNode()) {
880
+ if (n.nodeType !== COMMENT_NODE) {
881
+ if (!n.hasAttribute(FRAME_ID_ATTR)) {
882
+ if (n.hasAttributes()) B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
883
+ continue;
884
+ }
885
+ p = n;
886
+ } else if (n.data.startsWith("slot:")) {
887
+ const id = slotStartId(n);
888
+ if (!id) continue;
889
+ if (!bind) {
890
+ for (p = n.parentNode; p !== root; p = p.parentNode) if (p.hasAttribute(FRAME_ID_ATTR)) break;
891
+ if (p !== root) continue;
892
+ }
877
893
  if (!out.has(id)) out.set(id, n);
878
- n = afterRange(n, id);
879
- continue;
880
- }
881
- if (elements !== undefined && isTextStart(n)) {
882
- const B = tierLoads.bind?.r;
883
- B ? B.text(n, elements) : elements.b = true;
884
- }
885
- if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) {
886
- if (elements !== undefined && n.hasAttributes()) {
887
- const B = tierLoads.bind?.r;
888
- B ? B.positions(n, elements) : hasSlotMarker(n) && (elements.b = true);
894
+ const end = findMarker(n, slotEnd(id));
895
+ if (end) {
896
+ w.currentNode = end;
897
+ continue;
889
898
  }
890
- collectSlots(n.firstChild, null, out, elements);
899
+ p = n.parentNode;
900
+ if (p === root) return;
901
+ } else {
902
+ if (bind && n.data.startsWith(SLOT_TEXT)) B ? B.text(n, elements) : elements.b = true;
903
+ continue;
891
904
  }
892
- n = n.nextSibling;
905
+ while (p.lastChild) p = p.lastChild;
906
+ w.currentNode = p;
893
907
  }
894
908
  }
895
909
  function eachInRange(start, key, cb) {
@@ -973,12 +987,12 @@ function morphNode(oldNode, newNode, claim, ranges, grafts) {
973
987
  oldNode.data = newNode.data;
974
988
  }
975
989
  }
976
- const afterRange = (start, id) => afterMarker(start, slotEnd(id));
977
- const afterText = start => afterMarker(start, SLOT_TEXT_END);
978
- function afterMarker(start, end) {
990
+ const afterRange = (start, id) => findMarker(start, slotEnd(id))?.nextSibling;
991
+ const afterText = start => findMarker(start, SLOT_TEXT_END)?.nextSibling;
992
+ function findMarker(start, end) {
979
993
  let n = start.nextSibling;
980
994
  while (n) {
981
- if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
995
+ if (n.nodeType === COMMENT_NODE && n.data === end) return n;
982
996
  n = n.nextSibling;
983
997
  }
984
998
  return null;
@@ -1368,7 +1382,7 @@ function createServerComponentHandler({
1368
1382
  const target = entry || host;
1369
1383
  const applied = applyFrameResponse(response, target, {
1370
1384
  as: address,
1371
- version
1385
+ version: frameId => frameId === address ? version : bump(frameId)
1372
1386
  }).catch(err => target.apply({
1373
1387
  type: "error",
1374
1388
  id: address,
@@ -1468,23 +1482,21 @@ function followAddress(host, frame, binding) {
1468
1482
  });
1469
1483
  }
1470
1484
  function landing(host, address, value, failed) {
1471
- let thrown = host.get(address)?.error;
1485
+ let frame, thrown;
1486
+ const errored = () => (frame = host.get(address))?.error !== undefined && (thrown === (thrown = frame.version) ? 1 : 2);
1487
+ errored();
1472
1488
  return createMemo(() => {
1473
1489
  failed();
1474
- const error = host.get(address)?.error;
1475
- if (error !== undefined && error !== thrown) {
1476
- thrown = error;
1477
- throw error;
1478
- }
1490
+ const state = errored();
1491
+ if (state > 1) throw frame.error;
1479
1492
  const wait = host.landing(address);
1480
1493
  if (!wait) return value;
1481
- const asked = error !== undefined ? reask(address) : undefined;
1482
- return (asked ? asked.then(() => wait) : wait).then(() => value);
1494
+ return (state ? reask(address, wait) : wait).then(() => value);
1483
1495
  });
1484
1496
  }
1485
- function reask(address) {
1497
+ function reask(address, wait) {
1486
1498
  const call = callFor(address);
1487
- return call && call.retry();
1499
+ return call ? call.retry().then(() => wait) : wait;
1488
1500
  }
1489
1501
  function failing() {
1490
1502
  const [failed, setFailed] = createSignal(0, {
@@ -1503,6 +1515,29 @@ function getFrameHost() {
1503
1515
  }
1504
1516
  return sharedHost;
1505
1517
  }
1518
+ function claimScope(el) {
1519
+ const registry = sharedConfig.registry;
1520
+ const buckets = new Map();
1521
+ const bucketOf = key => key.slice(0, key.lastIndexOf("-") + 1);
1522
+ const index = root => {
1523
+ if (registry) for (const n of root.querySelectorAll("[_hk]")) {
1524
+ const p = bucketOf(n.getAttribute("_hk"));
1525
+ const b = buckets.get(p);
1526
+ b ? b.push(n) : buckets.set(p, [n]);
1527
+ }
1528
+ };
1529
+ index(el);
1530
+ return {
1531
+ registry,
1532
+ gather(id) {
1533
+ for (const n of buckets.get(bucketOf(id)) || []) {
1534
+ const k = n.getAttribute("_hk");
1535
+ if (k.startsWith(id) && n.isConnected && !registry.has(k)) registry.set(k, n);
1536
+ }
1537
+ },
1538
+ index
1539
+ };
1540
+ }
1506
1541
  function claimRender(prefix, existing, render, scope, bound) {
1507
1542
  const sc = sharedConfig;
1508
1543
  if (!sc.hydrateWindow || !sc.registry) return render();
@@ -1710,7 +1745,10 @@ function findBoundaryElement(id) {
1710
1745
  boundaryIndex = new Map();
1711
1746
  if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1712
1747
  }
1713
- return boundaryIndex.get(id);
1748
+ for (let n = 0;; n++) {
1749
+ const key = n ? id + "~" + (n + 1) : id;
1750
+ if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
1751
+ }
1714
1752
  }
1715
1753
  const arrivals = new Map();
1716
1754
  const FRAME_SELECTOR = `[${FRAME_ID_ATTR}]`;
@@ -1733,6 +1771,7 @@ function boundaryMayArrive() {
1733
1771
  return !hy.done || !!(hy.fr && hy.fr.pending());
1734
1772
  }
1735
1773
  function installRevealHook() {
1774
+ installServerComponentHydration();
1736
1775
  const hy = globalThis._$HY;
1737
1776
  if (!hy || hy.$sc || !hy.fr) return;
1738
1777
  hy.$sc = true;
@@ -1756,29 +1795,29 @@ function installRevealHook() {
1756
1795
  }
1757
1796
  function documentBoundary(host, id, props, binding) {
1758
1797
  installRevealHook();
1759
- const claimed = claimedBoundaries.has(id);
1760
- const el = !claimed ? findBoundaryElement(id) : undefined;
1798
+ const el = findBoundaryElement(id);
1761
1799
  if (el) return adoptBoundary(host, id, el, props, binding);
1762
- if (!claimed && boundaryMayArrive()) {
1800
+ if (!claimedBoundaries.has(id) && boundaryMayArrive()) {
1763
1801
  const owner = getOwner();
1764
1802
  let live = true;
1765
1803
  onCleanup(() => live = false);
1766
1804
  return createMemo(() => awaitBoundary(id).then(() => live && runWithOwner(owner, () => {
1767
- const node = claimedBoundaries.has(id) ? undefined : findBoundaryElement(id);
1805
+ const node = findBoundaryElement(id);
1768
1806
  return node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding);
1769
1807
  })));
1770
1808
  }
1771
1809
  return boundaryComponent(host, id)(props, binding);
1772
1810
  }
1773
1811
  function adoptBoundary(host, id, el, props, binding) {
1774
- claimedBoundaries.add(id);
1812
+ const siteId = el.getAttribute(FRAME_ID_ATTR);
1813
+ claimedBoundaries.add(siteId);
1775
1814
  const address = binding ? contentAddress(binding()) : id;
1776
1815
  const appliedRecords = new Set();
1777
1816
  const drainRecords = () => {
1778
1817
  const hy = globalThis._$HY;
1779
1818
  if (!hy || !hy.r) return;
1780
1819
  pumpLiveChannel();
1781
- const slotPrefix = `sc:slot:${id}:`;
1820
+ const slotPrefix = `sc:slot:${siteId}:`;
1782
1821
  for (const key of Object.keys(hy.r)) {
1783
1822
  if (appliedRecords.has(key)) continue;
1784
1823
  if (key.startsWith(slotPrefix)) {
@@ -1796,7 +1835,7 @@ function adoptBoundary(host, id, el, props, binding) {
1796
1835
  } else apply(value);
1797
1836
  } else if (key.startsWith("sc:region:")) {
1798
1837
  const childId = key.slice("sc:region:".length);
1799
- if (childId.startsWith(id + ".")) {
1838
+ if (childId.startsWith(siteId + ".")) {
1800
1839
  appliedRecords.add(key);
1801
1840
  const val = hy.r[key];
1802
1841
  const apply = html => host.apply({
@@ -1810,10 +1849,12 @@ function adoptBoundary(host, id, el, props, binding) {
1810
1849
  }
1811
1850
  }
1812
1851
  };
1852
+ const scope = claimScope(el);
1813
1853
  const fr = globalThis._$HY?.fr;
1814
1854
  let frame;
1815
1855
  const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
1816
1856
  const inside = !!parent && el.contains(parent);
1857
+ inside && scope.index(parent);
1817
1858
  drainRecords();
1818
1859
  if (inside && frame) frame.apply({
1819
1860
  version: frame.version ?? 0,
@@ -1821,7 +1862,7 @@ function adoptBoundary(host, id, el, props, binding) {
1821
1862
  });
1822
1863
  }) : undefined;
1823
1864
  const applyLiveOp = op => {
1824
- if (op.fid && op.fid !== id) return;
1865
+ if (op.fid && op.fid !== siteId) return;
1825
1866
  host.apply({
1826
1867
  ...op,
1827
1868
  id: address,
@@ -1842,16 +1883,13 @@ function adoptBoundary(host, id, el, props, binding) {
1842
1883
  adopt: true,
1843
1884
  host,
1844
1885
  id: address,
1845
- slots: slotsFor(props, {
1846
- registry: sc.registry,
1847
- gather: sc.gather
1848
- }),
1886
+ slots: slotsFor(props, scope),
1849
1887
  ownerScope: boundaryScope(owner),
1850
1888
  reveal: revealSeam(owner),
1851
1889
  onApply,
1852
- hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + id))) : () => {},
1890
+ hold: () => sc.isHydrationInProgress?.() ? runWithOwner(owner, () => untrack(() => sc.holdBoundary("sc:" + siteId))) : () => {},
1853
1891
  ...{
1854
- claimScope: id
1892
+ claimScope: siteId
1855
1893
  }
1856
1894
  });
1857
1895
  if (binding) {
@@ -1897,9 +1935,8 @@ function installServerComponents(host = getFrameHost(), options) {
1897
1935
  intercept: ({
1898
1936
  id
1899
1937
  }) => {
1900
- if (claimedBoundaries.has(id)) return undefined;
1901
1938
  if (findBoundaryElement(id)) return true;
1902
- if (!boundaryMayArrive()) return undefined;
1939
+ if (claimedBoundaries.has(id) || !boundaryMayArrive()) return undefined;
1903
1940
  installRevealHook();
1904
1941
  return awaitBoundary(id);
1905
1942
  }