@isoloop/runtime 0.0.0-next.5aa1a15 → 0.0.0-next.61245db

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/bootstrap.js CHANGED
@@ -627,7 +627,7 @@ var ISOLOOP_DOM_FMT;
627
627
  var init_records_wVZrPpqr = __esmMin((() => {
628
628
  ISOLOOP_DOM_FMT = "isoloop-dom@1";
629
629
  }));
630
- // ../dom/dist/dom-7EzPoV0N.js
630
+ // ../dom/dist/dom-yLsf0Z4e.js
631
631
  function createStyle(el) {
632
632
  const decls = /* @__PURE__ */ new Map();
633
633
  const write = () => {
@@ -754,75 +754,124 @@ function serialize(n) {
754
754
  children: n.childNodes.map(serialize)
755
755
  };
756
756
  }
757
- function learn(n, core) {
757
+ /** Whether `n` or anything under it was rendered under a root other than `owner`. */
758
+ function ownedElsewhere(n, owner) {
759
+ if (n.isoOwner && n.isoOwner !== owner) return true;
760
+ return !n.isoKnown && n.childNodes.some((c) => ownedElsewhere(c, owner));
761
+ }
762
+ function learn(n, core, owner) {
758
763
  n.isoKnown = true;
764
+ n.isoOwner = owner;
759
765
  core.known.set(n.isoId, n);
760
- for (const c of n.childNodes) learn(c, core);
766
+ for (const c of n.childNodes) learn(c, core, owner);
761
767
  }
762
768
  function forget(n, core) {
763
769
  n.isoKnown = false;
764
770
  core.known.delete(n.isoId);
765
771
  for (const c of n.childNodes) forget(c, core);
766
772
  }
767
- function createDom(opts) {
768
- const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
773
+ function setValueOf(node, value, o) {
774
+ if (!isControl(node)) throw new TypeError("setValue: not an input, textarea or select");
775
+ if (!o.force) {
776
+ node.value = value;
777
+ return;
778
+ }
779
+ node.isoSetProp("value", value, false);
780
+ if (node.isoKnown) emit(node, [
781
+ "prop",
782
+ node.isoWire,
783
+ "value",
784
+ value,
785
+ true
786
+ ]);
787
+ }
788
+ function deliverTo(node, event) {
789
+ if (!node) return;
790
+ if (isControl(node) && event.value !== void 0) node.isoSetProp("value", event.value, false);
791
+ if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
792
+ if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
793
+ top: event.scrollTop ?? 0,
794
+ left: event.scrollLeft ?? 0
795
+ };
796
+ node.dispatchEvent(toEvent(event));
797
+ }
798
+ /** A root's recorder: records batched per microtask (or `schedule`) into `onBatch`. */
799
+ function recorder(root, onBatch, schedule) {
769
800
  let pending = [];
770
801
  let scheduled = false;
802
+ let live = true;
771
803
  const flush = () => {
772
804
  scheduled = false;
773
805
  if (pending.length === 0) return;
774
806
  const batch = pending;
775
807
  pending = [];
776
- opts.onBatch(batch);
808
+ if (live) onBatch(batch);
777
809
  };
810
+ return {
811
+ owner: {
812
+ root,
813
+ push(r) {
814
+ if (!live) return;
815
+ pending.push(r);
816
+ if (!scheduled) {
817
+ scheduled = true;
818
+ schedule(flush);
819
+ }
820
+ }
821
+ },
822
+ flush,
823
+ stop: () => {
824
+ live = false;
825
+ pending = [];
826
+ }
827
+ };
828
+ }
829
+ function createDom(opts) {
830
+ const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
778
831
  const core = {
779
- root: null,
832
+ roots: /* @__PURE__ */ new Set(),
780
833
  nextId: 1,
781
834
  known: /* @__PURE__ */ new Map(),
782
- onHead: opts.onHead ?? (() => {}),
783
- record(r) {
784
- pending.push(r);
785
- if (!scheduled) {
786
- scheduled = true;
787
- schedule(flush);
788
- }
789
- }
835
+ onHead: opts.onHead ?? (() => {})
790
836
  };
791
837
  const document = new WDocument(core);
792
- const root = new WHTMLElement(document, 0, "iso-root", "html");
793
- root.isoKnown = true;
794
- core.known.set(0, root);
795
- core.root = root;
838
+ const makeRoot = (id) => {
839
+ const root = new WHTMLElement(document, id, "iso-root", "html");
840
+ root.isoKnown = true;
841
+ core.known.set(id, root);
842
+ core.roots.add(root);
843
+ return root;
844
+ };
845
+ const root = makeRoot(0);
846
+ const main = recorder(root, (b) => opts.onBatch(b), schedule);
847
+ root.isoOwner = main.owner;
796
848
  return {
797
849
  document,
798
850
  root,
799
- flush,
851
+ flush: main.flush,
800
852
  idOf: (node) => node.isoId,
801
- setValue(node, value, o = {}) {
802
- if (!(node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement)) throw new TypeError("setValue: not an input, textarea or select");
803
- if (!o.force) {
804
- node.value = value;
805
- return;
806
- }
807
- node.isoSetProp("value", value, false);
808
- if (node.isoKnown) core.record([
809
- "prop",
810
- node.isoId,
811
- "value",
812
- value,
813
- true
814
- ]);
815
- },
816
- deliver(event) {
817
- const node = core.known.get(event.target);
818
- if (!node) return;
819
- if ((node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement) && event.value !== void 0) node.isoSetProp("value", event.value, false);
820
- if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
821
- if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
822
- top: event.scrollTop ?? 0,
823
- left: event.scrollLeft ?? 0
853
+ setValue: (node, value, o = {}) => setValueOf(node, value, o),
854
+ deliver: (event) => deliverTo(core.known.get(event.target), event),
855
+ addRoot(o) {
856
+ const member = makeRoot(core.nextId++);
857
+ const rec = recorder(member, (b) => o.onBatch(b), o.schedule ?? schedule);
858
+ member.isoOwner = rec.owner;
859
+ const mine = (node) => node?.isoKnown && node.isoOwner === rec.owner ? node : void 0;
860
+ return {
861
+ root: member,
862
+ flush: rec.flush,
863
+ idOf: (node) => mine(node) ? node.isoWire : void 0,
864
+ setValue(node, value, so = {}) {
865
+ if (node.isoOwner && node.isoOwner !== rec.owner) throw new TypeError("setValue: not a node of this member's root");
866
+ setValueOf(node, value, so);
867
+ },
868
+ deliver: (event) => deliverTo(mine(event.target === 0 ? member : core.known.get(event.target)), event),
869
+ dispose() {
870
+ rec.stop();
871
+ core.roots.delete(member);
872
+ forget(member, core);
873
+ }
824
874
  };
825
- node.dispatchEvent(toEvent(event));
826
875
  }
827
876
  };
828
877
  }
@@ -854,8 +903,8 @@ function toEvent(e) {
854
903
  });
855
904
  return ev;
856
905
  }
857
- var HTML_NS, SVG_NS, str, domError, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument;
858
- var init_dom_7EzPoV0N = __esmMin((() => {
906
+ var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
907
+ var init_dom_yLsf0Z4e = __esmMin((() => {
859
908
  HTML_NS = "http://www.w3.org/1999/xhtml";
860
909
  SVG_NS = "http://www.w3.org/2000/svg";
861
910
  str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
@@ -864,6 +913,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
864
913
  e.name = name;
865
914
  return e;
866
915
  };
916
+ emit = (n, r) => {
917
+ n.isoOwner?.push(r);
918
+ };
867
919
  WEventTarget = class {
868
920
  /** @internal */ isoListeners = /* @__PURE__ */ new Map();
869
921
  /** @internal */ isoParentTarget() {
@@ -1006,6 +1058,12 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1006
1058
  /** @internal */ isoNext = null;
1007
1059
  /** @internal Whether the host knows this node (it's in the tree under the root). */
1008
1060
  isoKnown = false;
1061
+ /**
1062
+ * @internal The root this node was rendered under, once it has been. Kept
1063
+ * after the node leaves the tree, so it can't move to another member's root
1064
+ * in a pool (ADR 0015, decision 3).
1065
+ */
1066
+ isoOwner = null;
1009
1067
  constructor(doc, id) {
1010
1068
  super();
1011
1069
  this.ownerDocument = doc;
@@ -1014,10 +1072,17 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1014
1072
  /** @internal */ isoParentTarget() {
1015
1073
  return this.isoParent;
1016
1074
  }
1075
+ /**
1076
+ * @internal The id the host knows this node by: a render root is always
1077
+ * `ROOT_ID` to its own surface, whatever its id in the document.
1078
+ */
1079
+ get isoWire() {
1080
+ return this.isoOwner?.root === this ? 0 : this.isoId;
1081
+ }
1017
1082
  /** @internal */ isoListenChanged(type, on) {
1018
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1083
+ if (this.isoKnown) emit(this, [
1019
1084
  "listen",
1020
- this.isoId,
1085
+ this.isoWire,
1021
1086
  type,
1022
1087
  on
1023
1088
  ]);
@@ -1070,9 +1135,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1070
1135
  const data = str(v);
1071
1136
  if (data === this.isoData) return;
1072
1137
  this.isoData = data;
1073
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1138
+ if (this.isoKnown) emit(this, [
1074
1139
  "text",
1075
- this.isoId,
1140
+ this.isoWire,
1076
1141
  data
1077
1142
  ]);
1078
1143
  }
@@ -1207,27 +1272,28 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1207
1272
  return child;
1208
1273
  }
1209
1274
  if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
1275
+ if (this.isoKnown && ownedElsewhere(child, this.isoOwner)) throw domError("HierarchyRequestError", "insertBefore: a node can't move to another member's root in a pool");
1210
1276
  const wasKnown = child.isoKnown;
1211
1277
  child.isoParent?.isoUnlink(child);
1212
1278
  this.isoLink(child, ref);
1213
1279
  const core = this.ownerDocument.isoCore;
1214
- if (wasKnown && this.isoKnown) core.record([
1280
+ if (wasKnown && this.isoKnown) emit(this, [
1215
1281
  "move",
1216
- this.isoId,
1282
+ this.isoWire,
1217
1283
  child.isoId,
1218
1284
  ref?.isoId ?? null
1219
1285
  ]);
1220
1286
  else if (wasKnown) {
1221
- core.record(["remove", child.isoId]);
1287
+ emit(child, ["remove", child.isoId]);
1222
1288
  forget(child, core);
1223
1289
  } else if (this.isoKnown) {
1224
- core.record([
1290
+ emit(this, [
1225
1291
  "insert",
1226
- this.isoId,
1292
+ this.isoWire,
1227
1293
  serialize(child),
1228
1294
  ref?.isoId ?? null
1229
1295
  ]);
1230
- learn(child, core);
1296
+ learn(child, core, this.isoOwner);
1231
1297
  }
1232
1298
  return child;
1233
1299
  }
@@ -1235,9 +1301,8 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1235
1301
  if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
1236
1302
  this.isoUnlink(child);
1237
1303
  if (child.isoKnown) {
1238
- const core = this.ownerDocument.isoCore;
1239
- core.record(["remove", child.isoId]);
1240
- forget(child, core);
1304
+ emit(child, ["remove", child.isoId]);
1305
+ forget(child, this.ownerDocument.isoCore);
1241
1306
  }
1242
1307
  return child;
1243
1308
  }
@@ -1325,9 +1390,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1325
1390
  const v = str(value);
1326
1391
  if (this.isoAttrs.get(n) === v) return;
1327
1392
  this.isoAttrs.set(n, v);
1328
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1393
+ if (this.isoKnown) emit(this, [
1329
1394
  "attr",
1330
- this.isoId,
1395
+ this.isoWire,
1331
1396
  n,
1332
1397
  v
1333
1398
  ]);
@@ -1335,9 +1400,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1335
1400
  removeAttribute(name) {
1336
1401
  const n = this.isoAttrName(name);
1337
1402
  if (!this.isoAttrs.delete(n)) return;
1338
- if (this.isoKnown) this.ownerDocument.isoCore.record([
1403
+ if (this.isoKnown) emit(this, [
1339
1404
  "attr",
1340
- this.isoId,
1405
+ this.isoWire,
1341
1406
  n,
1342
1407
  null
1343
1408
  ]);
@@ -1377,9 +1442,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1377
1442
  /** @internal */ isoSetProp(name, value, record) {
1378
1443
  if (this.isoProps.get(name) === value) return;
1379
1444
  this.isoProps.set(name, value);
1380
- if (record && this.isoKnown) this.ownerDocument.isoCore.record([
1445
+ if (record && this.isoKnown) emit(this, [
1381
1446
  "prop",
1382
- this.isoId,
1447
+ this.isoWire,
1383
1448
  name,
1384
1449
  value
1385
1450
  ]);
@@ -1636,8 +1701,11 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1636
1701
  }
1637
1702
  return null;
1638
1703
  };
1639
- const root = this.isoCore.root;
1640
- return (root ? walk(root) : null) ?? walk(this.head);
1704
+ for (const root of this.isoCore.roots) {
1705
+ const hit = walk(root);
1706
+ if (hit) return hit;
1707
+ }
1708
+ return walk(this.head);
1641
1709
  }
1642
1710
  /**
1643
1711
  * Type selectors only, alone or as a `head > title` child chain: what React
@@ -1672,8 +1740,9 @@ var init_dom_7EzPoV0N = __esmMin((() => {
1672
1740
  }
1673
1741
  };
1674
1742
  defineHandlers(WDocument.prototype);
1743
+ isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
1675
1744
  }));
1676
- // ../dom/dist/install-DE1VIvyG.js
1745
+ // ../dom/dist/install-D7m7By8i.js
1677
1746
  /**
1678
1747
  * Exposes `dom` as the worker's `document`, `window` and DOM classes, so
1679
1748
  * frameworks find them where they look. Only for isolates with a surface; a
@@ -1693,8 +1762,8 @@ function install(dom, scope) {
1693
1762
  dom.document.defaultView = scope;
1694
1763
  }
1695
1764
  var DOM_GLOBALS;
1696
- var init_install_DE1VIvyG = __esmMin((() => {
1697
- init_dom_7EzPoV0N();
1765
+ var init_install_D7m7By8i = __esmMin((() => {
1766
+ init_dom_yLsf0Z4e();
1698
1767
  DOM_GLOBALS = {
1699
1768
  Node: WNode,
1700
1769
  Element: WElement,
@@ -1714,15 +1783,29 @@ var init_install_DE1VIvyG = __esmMin((() => {
1714
1783
  // ../dom/dist/worker.js
1715
1784
  var init_worker = __esmMin((() => {
1716
1785
  init_records_wVZrPpqr();
1717
- init_dom_7EzPoV0N();
1718
- init_install_DE1VIvyG();
1786
+ init_dom_yLsf0Z4e();
1787
+ init_install_D7m7By8i();
1719
1788
  }));
1720
1789
  // src/render/index.ts
1790
+ function sharedDom(scope) {
1791
+ if (!shared) {
1792
+ shared = createDom({
1793
+ onBatch: () => {},
1794
+ onHead: (tag) => {
1795
+ for (const fn of headListeners) fn(tag);
1796
+ }
1797
+ });
1798
+ if (scope) install(shared, scope);
1799
+ }
1800
+ return shared;
1801
+ }
1721
1802
  /**
1722
1803
  * Builds the DOM subset and posts its batches. With `scope`, also installs it
1723
- * as that global's `document` and DOM classes, which frameworks need.
1804
+ * as that global's `document` and DOM classes, which frameworks need. With
1805
+ * `pooled`, the isolate gets its own root in the worker's shared document
1806
+ * instead (ADR 0015).
1724
1807
  */
1725
- function createRender(post, scope) {
1808
+ function createRender(post, scope, pooled = false) {
1726
1809
  let pendingStyles = [];
1727
1810
  let pendingHead = [];
1728
1811
  /** Head tags already reported: each goes to the host once. */
@@ -1750,47 +1833,77 @@ function createRender(post, scope) {
1750
1833
  extrasScheduled = true;
1751
1834
  queueMicrotask(() => {
1752
1835
  extrasScheduled = false;
1753
- dom.flush();
1836
+ target.flush();
1754
1837
  if (pendingStyles.length > 0 || pendingHead.length > 0) postPatch([]);
1755
1838
  });
1756
1839
  };
1757
- const dom = createDom({
1758
- onBatch: postPatch,
1759
- schedule: (flush) => queueMicrotask(flush),
1760
- onHead(tag) {
1761
- if (headSeen.has(tag)) return;
1762
- headSeen.add(tag);
1763
- pendingHead.push(tag);
1764
- scheduleExtras();
1765
- }
1766
- });
1767
- if (scope) install(dom, scope);
1840
+ const onHead = (tag) => {
1841
+ if (headSeen.has(tag)) return;
1842
+ headSeen.add(tag);
1843
+ pendingHead.push(tag);
1844
+ scheduleExtras();
1845
+ };
1846
+ let target;
1847
+ if (pooled) {
1848
+ const member = sharedDom(scope).addRoot({ onBatch: postPatch });
1849
+ headListeners.add(onHead);
1850
+ target = {
1851
+ ...member,
1852
+ dispose() {
1853
+ headListeners.delete(onHead);
1854
+ member.dispose();
1855
+ }
1856
+ };
1857
+ } else {
1858
+ const dom = createDom({
1859
+ onBatch: postPatch,
1860
+ schedule: (flush) => queueMicrotask(flush),
1861
+ onHead
1862
+ });
1863
+ if (scope) install(dom, scope);
1864
+ target = {
1865
+ root: dom.root,
1866
+ flush: () => dom.flush(),
1867
+ deliver: (event) => dom.deliver(event),
1868
+ idOf: (node) => node.isConnected ? dom.idOf(node) : void 0,
1869
+ setValue: (node, value, o) => dom.setValue(node, value, o),
1870
+ dispose: () => {}
1871
+ };
1872
+ }
1768
1873
  return {
1769
1874
  fmt: ISOLOOP_DOM_FMT,
1770
- root: dom.root,
1771
- dom,
1875
+ root: target.root,
1876
+ flush: () => target.flush(),
1877
+ setValue: (node, value, o) => target.setValue(node, value, o),
1878
+ dispose: () => target.dispose(),
1772
1879
  styles(css) {
1773
1880
  pendingStyles.push(...typeof css === "string" ? [css] : css);
1774
1881
  scheduleExtras();
1775
1882
  },
1776
- idOf: (node) => node instanceof WNode && node.isConnected ? String(dom.idOf(node)) : void 0,
1883
+ idOf(node) {
1884
+ if (!(node instanceof WNode)) return void 0;
1885
+ const id = target.idOf(node);
1886
+ return id === void 0 ? void 0 : String(id);
1887
+ },
1777
1888
  receive(e) {
1778
- const target = nodeId(e.target);
1779
- if (target === void 0) return;
1889
+ const t = nodeId(e.target);
1890
+ if (t === void 0) return;
1780
1891
  const currentTargets = e.currentTargets.map(nodeId).filter((n) => n !== void 0);
1781
1892
  const { target: _t, currentTargets: _c, ...rest } = e;
1782
- dom.deliver({
1893
+ target.deliver({
1783
1894
  ...rest,
1784
- target,
1895
+ target: t,
1785
1896
  currentTargets
1786
1897
  });
1787
1898
  }
1788
1899
  };
1789
1900
  }
1790
- var nodeId;
1901
+ var nodeId, shared, headListeners;
1791
1902
  var init_render = __esmMin((() => {
1792
1903
  init_worker();
1793
1904
  nodeId = (s) => /^\d+$/.test(s) ? Number(s) : void 0;
1905
+ shared = null;
1906
+ headListeners = /* @__PURE__ */ new Set();
1794
1907
  }));
1795
1908
  // package.json
1796
1909
  var version = "0.0.0";
@@ -1811,11 +1924,11 @@ function defineIsolate(def) {
1811
1924
  };
1812
1925
  }
1813
1926
  /** Builds the context for `start(ctx)`. `scope` is the worker global the DOM subset installs on. */
1814
- function createVanillaIsolate(init, post, scope) {
1815
- const render = init.renderFmt === "none" ? null : createRender(post, scope);
1927
+ function createVanillaIsolate(init, post, scope, pooled = false) {
1928
+ const render = init.renderFmt === "none" ? null : createRender(post, scope, pooled);
1816
1929
  const calls = createHostCalls({
1817
1930
  post,
1818
- beforeCall: () => render?.dom.flush(),
1931
+ beforeCall: () => render?.flush(),
1819
1932
  idOf: (node) => render ? render.idOf(node) : void 0,
1820
1933
  surface: render !== null,
1821
1934
  navigate: init.grants.navigate === true
@@ -1839,24 +1952,58 @@ function createVanillaIsolate(init, post, scope) {
1839
1952
  }
1840
1953
  });
1841
1954
  const onShutdown = [];
1842
- return {
1843
- ctx: {
1844
- id: init.isolateId,
1845
- config: init.config,
1846
- root: render?.root,
1847
- host: calls.api,
1848
- bus: bus.client,
1849
- styles: (css) => render?.styles(css),
1850
- setValue(node, value, o) {
1851
- if (!render) return;
1852
- if (!(node instanceof WNode)) throw new TypeError("setValue: not a node of this isolate");
1853
- render.dom.setValue(node, value, o);
1854
- },
1855
- onShutdown: (fn) => {
1856
- onShutdown.push(fn);
1857
- },
1858
- keepAwake: () => awake.hold()
1955
+ let portal;
1956
+ const ctx = {
1957
+ id: init.isolateId,
1958
+ config: init.config,
1959
+ root: render?.root,
1960
+ portalRoot: void 0,
1961
+ reportError(error, o = {}) {
1962
+ const fatal = o.fatal ?? true;
1963
+ post({
1964
+ v: 1,
1965
+ t: "error",
1966
+ p: error instanceof Error ? {
1967
+ message: error.message,
1968
+ ...error.stack === void 0 ? {} : { stack: error.stack },
1969
+ fatal
1970
+ } : {
1971
+ message: String(error),
1972
+ fatal
1973
+ }
1974
+ });
1859
1975
  },
1976
+ host: calls.api,
1977
+ bus: bus.client,
1978
+ styles: (css) => render?.styles(css),
1979
+ setValue(node, value, o) {
1980
+ if (!render) return;
1981
+ if (!(node instanceof WNode)) throw new TypeError("setValue: not a node of this isolate");
1982
+ render.setValue(node, value, o);
1983
+ },
1984
+ onShutdown: (fn) => {
1985
+ onShutdown.push(fn);
1986
+ },
1987
+ keepAwake: () => awake.hold()
1988
+ };
1989
+ Object.defineProperty(ctx, "portalRoot", {
1990
+ enumerable: false,
1991
+ get() {
1992
+ if (!render) return void 0;
1993
+ if (!portal) {
1994
+ const { root } = render;
1995
+ const div = root.ownerDocument.createElement("div");
1996
+ div.setAttribute("data-isoloop-portal", "");
1997
+ queueMicrotask(() => {
1998
+ if (div.parentNode !== root) root.appendChild(div);
1999
+ });
2000
+ portal = div;
2001
+ }
2002
+ return portal;
2003
+ }
2004
+ });
2005
+ return {
2006
+ ctx,
1860
2007
  renderFmt: render ? render.fmt : "none",
1861
2008
  receive(msg) {
1862
2009
  if (isHostToIsolate(msg)) {
@@ -1875,7 +2022,8 @@ function createVanillaIsolate(init, post, scope) {
1875
2022
  },
1876
2023
  async shutdown(reason) {
1877
2024
  await Promise.allSettled(onShutdown.map(async (fn) => fn(reason)));
1878
- render?.dom.flush();
2025
+ render?.flush();
2026
+ render?.dispose();
1879
2027
  }
1880
2028
  };
1881
2029
  }
@@ -1979,7 +2127,7 @@ async function boot(m, init) {
1979
2127
  }
1980
2128
  startHeartbeat(init.heartbeatMs);
1981
2129
  const { createVanillaIsolate } = await Promise.resolve().then(() => (init_vanilla(), vanilla_exports));
1982
- const runtime = createVanillaIsolate(init, m.post, self);
2130
+ const runtime = createVanillaIsolate(init, m.post, self, mode === "pool");
1983
2131
  let mod;
1984
2132
  try {
1985
2133
  mod = await import(
@@ -2025,7 +2173,8 @@ async function startIsolate(m, runtime, start, requires) {
2025
2173
  fatal(m, `start() threw: ${err instanceof Error ? err.message : String(err)}`);
2026
2174
  }
2027
2175
  }
2028
- self.addEventListener("message", (e) => {
2176
+ /** Handles one message from the host: `init` boots a member, the rest is routed. */
2177
+ function onMessage(e) {
2029
2178
  const msg = e.data;
2030
2179
  if (!isHostToIsolate(msg)) return;
2031
2180
  if (msg.t !== "init") {
@@ -2051,4 +2200,14 @@ self.addEventListener("message", (e) => {
2051
2200
  boot(m, msg.p).catch((err) => {
2052
2201
  fatal(m, err instanceof Error ? err.message : String(err));
2053
2202
  });
2054
- });
2203
+ }
2204
+ const STARTED = Symbol.for("isoloop.bootstrap");
2205
+ function startOnce() {
2206
+ self.addEventListener("message", onMessage);
2207
+ }
2208
+ if (Reflect.get(self, STARTED) === true) {
2209
+ if (import.meta.env?.DEV === true) console.warn("isoloop: worker entry evaluated twice; ignoring");
2210
+ } else {
2211
+ Reflect.set(self, STARTED, true);
2212
+ startOnce();
2213
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as defineIsolate, c as ScrollIntoViewOptionsLike, i as REQUIRES, l as BusClient, n as IsolateDefinition, o as HostApi, r as IsolateRoot, s as HostCallError, t as IsolateContext, u as SubscribeOptions } from "./vanilla-NeyOhMib.js";
1
+ import { a as defineIsolate, c as ScrollIntoViewOptionsLike, i as REQUIRES, l as BusClient, n as IsolateDefinition, o as HostApi, r as IsolateRoot, s as HostCallError, t as IsolateContext, u as SubscribeOptions } from "./vanilla-nAEAFMUP.js";
2
2
  import { BusError } from "@isoloop/protocol";
3
3
  export { type BusClient, BusError, type HostApi, HostCallError, type IsolateContext, type IsolateDefinition, type IsolateRoot, REQUIRES, type ScrollIntoViewOptionsLike, type SubscribeOptions, defineIsolate };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as HostApi, t as IsolateContext } from "./vanilla-NeyOhMib.js";
1
+ import { o as HostApi, t as IsolateContext } from "./vanilla-nAEAFMUP.js";
2
2
  import { ShutdownReason } from "@isoloop/protocol";
3
3
  export type TestContextOptions = {
4
4
  id?: string;
@@ -12,6 +12,11 @@ export type TestContextOptions = {
12
12
  };
13
13
  export type TestContext = {
14
14
  readonly ctx: IsolateContext;
15
+ /** What `ctx.reportError` got, in order. */
16
+ readonly errors: {
17
+ error: unknown;
18
+ fatal: boolean;
19
+ }[];
15
20
  /** Delivers a record to every subscription on `topic`, in order. */
16
21
  emit: (topic: string, value: unknown, key?: string) => void;
17
22
  /** Runs `onReset` of every subscription on `topic` (a bus restart lost it, ADR 0007). */