solid-js 1.6.7 → 1.6.9

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/dev.cjs CHANGED
@@ -1,20 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  let taskIdCounter = 1,
4
- isCallbackScheduled = false,
5
- isPerformingWork = false,
6
- taskQueue = [],
7
- currentTask = null,
8
- shouldYieldToHost = null,
9
- yieldInterval = 5,
10
- deadline = 0,
11
- maxYieldInterval = 300,
12
- scheduleCallback = null,
13
- scheduledCallback = null;
4
+ isCallbackScheduled = false,
5
+ isPerformingWork = false,
6
+ taskQueue = [],
7
+ currentTask = null,
8
+ shouldYieldToHost = null,
9
+ yieldInterval = 5,
10
+ deadline = 0,
11
+ maxYieldInterval = 300,
12
+ scheduleCallback = null,
13
+ scheduledCallback = null;
14
14
  const maxSigned31BitInt = 1073741823;
15
15
  function setupScheduler() {
16
16
  const channel = new MessageChannel(),
17
- port = channel.port2;
17
+ port = channel.port2;
18
18
  scheduleCallback = () => port.postMessage(null);
19
19
  channel.port1.onmessage = () => {
20
20
  if (scheduledCallback !== null) {
@@ -65,7 +65,7 @@ function enqueue(taskQueue, task) {
65
65
  function requestCallback(fn, options) {
66
66
  if (!scheduleCallback) setupScheduler();
67
67
  let startTime = performance.now(),
68
- timeout = maxSigned31BitInt;
68
+ timeout = maxSigned31BitInt;
69
69
  if (options && options.timeout) timeout = options.timeout;
70
70
  const newTask = {
71
71
  id: taskIdCounter++,
@@ -121,7 +121,8 @@ function setHydrateContext(context) {
121
121
  sharedConfig.context = context;
122
122
  }
123
123
  function nextHydrateContext() {
124
- return { ...sharedConfig.context,
124
+ return {
125
+ ...sharedConfig.context,
125
126
  id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`,
126
127
  count: 0
127
128
  };
@@ -157,22 +158,22 @@ let rootCount = 0;
157
158
  const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
158
159
  function createRoot(fn, detachedOwner) {
159
160
  const listener = Listener,
160
- owner = Owner,
161
- unowned = fn.length === 0,
162
- root = unowned ? {
163
- owned: null,
164
- cleanups: null,
165
- context: null,
166
- owner: null
167
- } : {
168
- owned: null,
169
- cleanups: null,
170
- context: null,
171
- owner: detachedOwner || owner
172
- },
173
- updateFn = unowned ? () => fn(() => {
174
- throw new Error("Dispose method must be an explicit argument to createRoot function");
175
- }) : () => fn(() => untrack(() => cleanNode(root)));
161
+ owner = Owner,
162
+ unowned = fn.length === 0,
163
+ root = unowned ? {
164
+ owned: null,
165
+ cleanups: null,
166
+ context: null,
167
+ owner: null
168
+ } : {
169
+ owned: null,
170
+ cleanups: null,
171
+ context: null,
172
+ owner: detachedOwner || owner
173
+ },
174
+ updateFn = unowned ? () => fn(() => {
175
+ throw new Error("Dispose method must be an explicit argument to createRoot function");
176
+ }) : () => fn(() => untrack(() => cleanNode(root)));
176
177
  {
177
178
  if (owner) root.name = `${owner.name}-r${rootCount++}`;
178
179
  globalThis._$afterCreateRoot && globalThis._$afterCreateRoot(root);
@@ -214,7 +215,7 @@ function createRenderEffect(fn, value, options) {
214
215
  function createEffect(fn, value, options) {
215
216
  runEffects = runUserEffects;
216
217
  const c = createComputation(fn, value, false, STALE, options ),
217
- s = SuspenseContext && lookup(Owner, SuspenseContext.id);
218
+ s = SuspenseContext && lookup(Owner, SuspenseContext.id);
218
219
  if (s) c.suspense = s;
219
220
  c.user = true;
220
221
  Effects ? Effects.push(c) : updateComputation(c);
@@ -222,10 +223,10 @@ function createEffect(fn, value, options) {
222
223
  function createReaction(onInvalidate, options) {
223
224
  let fn;
224
225
  const c = createComputation(() => {
225
- fn ? fn() : untrack(onInvalidate);
226
- fn = undefined;
227
- }, undefined, false, 0, options ),
228
- s = SuspenseContext && lookup(Owner, SuspenseContext.id);
226
+ fn ? fn() : untrack(onInvalidate);
227
+ fn = undefined;
228
+ }, undefined, false, 0, options ),
229
+ s = SuspenseContext && lookup(Owner, SuspenseContext.id);
229
230
  if (s) c.suspense = s;
230
231
  c.user = true;
231
232
  return tracking => {
@@ -259,19 +260,19 @@ function createResource(pSource, pFetcher, pOptions) {
259
260
  options = pOptions || {};
260
261
  }
261
262
  let pr = null,
262
- initP = NO_INIT,
263
- id = null,
264
- loadedUnderTransition = false,
265
- scheduled = false,
266
- resolved = ("initialValue" in options),
267
- dynamic = typeof source === "function" && createMemo(source);
263
+ initP = NO_INIT,
264
+ id = null,
265
+ loadedUnderTransition = false,
266
+ scheduled = false,
267
+ resolved = ("initialValue" in options),
268
+ dynamic = typeof source === "function" && createMemo(source);
268
269
  const contexts = new Set(),
269
- [value, setValue] = (options.storage || createSignal)(options.initialValue),
270
- [error, setError] = createSignal(undefined),
271
- [track, trigger] = createSignal(undefined, {
272
- equals: false
273
- }),
274
- [state, setState] = createSignal(resolved ? "ready" : "unresolved");
270
+ [value, setValue] = (options.storage || createSignal)(options.initialValue),
271
+ [error, setError] = createSignal(undefined),
272
+ [track, trigger] = createSignal(undefined, {
273
+ equals: false
274
+ }),
275
+ [state, setState] = createSignal(resolved ? "ready" : "unresolved");
275
276
  if (sharedConfig.context) {
276
277
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
277
278
  let v;
@@ -307,8 +308,8 @@ function createResource(pSource, pFetcher, pOptions) {
307
308
  }
308
309
  function read() {
309
310
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
310
- v = value(),
311
- err = error();
311
+ v = value(),
312
+ err = error();
312
313
  if (err && !pr) throw err;
313
314
  if (Listener && !Listener.user && c) {
314
315
  createComputed(() => {
@@ -380,7 +381,7 @@ function createResource(pSource, pFetcher, pOptions) {
380
381
  }
381
382
  function createDeferred(source, options) {
382
383
  let t,
383
- timeout = options ? options.timeoutMs : undefined;
384
+ timeout = options ? options.timeoutMs : undefined;
384
385
  const node = createComputation(() => {
385
386
  if (!t || !t.fn) t = requestCallback(() => setDeferred(() => node.value), timeout !== undefined ? {
386
387
  timeout
@@ -523,11 +524,10 @@ function devComponent(Comp, props) {
523
524
  [$DEVCOMP]: true
524
525
  });
525
526
  return Comp(props);
526
- }), undefined, true);
527
+ }), undefined, true, 0);
527
528
  c.props = props;
528
529
  c.observers = null;
529
530
  c.observerSlots = null;
530
- c.state = 0;
531
531
  c.componentName = Comp.name;
532
532
  updateComputation(c);
533
533
  return c.tValue !== undefined ? c.tValue : c.value;
@@ -560,13 +560,15 @@ function registerGraph(name, value) {
560
560
  Owner.sourceMap || (Owner.sourceMap = {});
561
561
  while (Owner.sourceMap[tryName]) tryName = `${name}-${++i}`;
562
562
  Owner.sourceMap[tryName] = value;
563
+ value.graph = Owner;
563
564
  }
564
565
  return tryName;
565
566
  }
566
567
  function serializeGraph(owner) {
567
568
  owner || (owner = Owner);
568
569
  if (!owner) return {};
569
- return { ...serializeValues(owner.sourceMap),
570
+ return {
571
+ ...serializeValues(owner.sourceMap),
570
572
  ...(owner.owned ? serializeChildren(owner) : {})
571
573
  };
572
574
  }
@@ -682,8 +684,8 @@ function updateComputation(node) {
682
684
  if (!node.fn) return;
683
685
  cleanNode(node);
684
686
  const owner = Owner,
685
- listener = Listener,
686
- time = ExecCount;
687
+ listener = Listener,
688
+ time = ExecCount;
687
689
  Listener = Owner = node;
688
690
  runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time);
689
691
  if (Transition && !Transition.running && Transition.sources.has(node)) {
@@ -704,7 +706,17 @@ function runComputation(node, value, time) {
704
706
  try {
705
707
  nextValue = node.fn(value);
706
708
  } catch (err) {
707
- if (node.pure) Transition && Transition.running ? node.tState = STALE : node.state = STALE;
709
+ if (node.pure) {
710
+ if (Transition && Transition.running) {
711
+ node.tState = STALE;
712
+ node.tOwned && node.tOwned.forEach(cleanNode);
713
+ node.tOwned = undefined;
714
+ } else {
715
+ node.state = STALE;
716
+ node.owned && node.owned.forEach(cleanNode);
717
+ node.owned = null;
718
+ }
719
+ }
708
720
  handleError(err);
709
721
  }
710
722
  if (!node.updatedAt || node.updatedAt <= time) {
@@ -772,7 +784,7 @@ function runTop(node) {
772
784
  node = ancestors[i];
773
785
  if (runningTransition) {
774
786
  let top = node,
775
- prev = ancestors[i + 1];
787
+ prev = ancestors[i + 1];
776
788
  while ((top = top.owner) && top !== prev) {
777
789
  if (Transition.disposed.has(top)) return;
778
790
  }
@@ -869,7 +881,7 @@ function scheduleQueue(queue) {
869
881
  }
870
882
  function runUserEffects(queue) {
871
883
  let i,
872
- userLength = 0;
884
+ userLength = 0;
873
885
  for (i = 0; i < queue.length; i++) {
874
886
  const e = queue[i];
875
887
  if (!e.user) runTop(e);else queue[userLength++] = e;
@@ -905,11 +917,11 @@ function cleanNode(node) {
905
917
  if (node.sources) {
906
918
  while (node.sources.length) {
907
919
  const source = node.sources.pop(),
908
- index = node.sourceSlots.pop(),
909
- obs = source.observers;
920
+ index = node.sourceSlots.pop(),
921
+ obs = source.observers;
910
922
  if (obs && obs.length) {
911
923
  const n = obs.pop(),
912
- s = source.observerSlots.pop();
924
+ s = source.observerSlots.pop();
913
925
  if (index < obs.length) {
914
926
  n.sourceSlots[s] = index;
915
927
  obs[index] = n;
@@ -999,7 +1011,8 @@ function serializeChildren(root) {
999
1011
  const result = {};
1000
1012
  for (let i = 0, len = root.owned.length; i < len; i++) {
1001
1013
  const node = root.owned[i];
1002
- result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = { ...serializeValues(node.sourceMap),
1014
+ result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = {
1015
+ ...serializeValues(node.sourceMap),
1003
1016
  ...(node.owned ? serializeChildren(node) : {})
1004
1017
  };
1005
1018
  }
@@ -1057,27 +1070,27 @@ function dispose(d) {
1057
1070
  }
1058
1071
  function mapArray(list, mapFn, options = {}) {
1059
1072
  let items = [],
1060
- mapped = [],
1061
- disposers = [],
1062
- len = 0,
1063
- indexes = mapFn.length > 1 ? [] : null;
1073
+ mapped = [],
1074
+ disposers = [],
1075
+ len = 0,
1076
+ indexes = mapFn.length > 1 ? [] : null;
1064
1077
  onCleanup(() => dispose(disposers));
1065
1078
  return () => {
1066
1079
  let newItems = list() || [],
1067
- i,
1068
- j;
1080
+ i,
1081
+ j;
1069
1082
  newItems[$TRACK];
1070
1083
  return untrack(() => {
1071
1084
  let newLen = newItems.length,
1072
- newIndices,
1073
- newIndicesNext,
1074
- temp,
1075
- tempdisposers,
1076
- tempIndexes,
1077
- start,
1078
- end,
1079
- newEnd,
1080
- item;
1085
+ newIndices,
1086
+ newIndicesNext,
1087
+ temp,
1088
+ tempdisposers,
1089
+ tempIndexes,
1090
+ start,
1091
+ end,
1092
+ newEnd,
1093
+ item;
1081
1094
  if (newLen === 0) {
1082
1095
  if (len !== 0) {
1083
1096
  dispose(disposers);
@@ -1162,11 +1175,11 @@ function mapArray(list, mapFn, options = {}) {
1162
1175
  }
1163
1176
  function indexArray(list, mapFn, options = {}) {
1164
1177
  let items = [],
1165
- mapped = [],
1166
- disposers = [],
1167
- signals = [],
1168
- len = 0,
1169
- i;
1178
+ mapped = [],
1179
+ disposers = [],
1180
+ signals = [],
1181
+ len = 0,
1182
+ i;
1170
1183
  onCleanup(() => dispose(disposers));
1171
1184
  return () => {
1172
1185
  const newItems = list() || [];
@@ -1448,21 +1461,21 @@ function Switch(props) {
1448
1461
  let keyed = false;
1449
1462
  const equals = (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1450
1463
  const conditions = children(() => props.children),
1451
- evalConditions = createMemo(() => {
1452
- let conds = conditions();
1453
- if (!Array.isArray(conds)) conds = [conds];
1454
- for (let i = 0; i < conds.length; i++) {
1455
- const c = conds[i].when;
1456
- if (c) {
1457
- keyed = !!conds[i].keyed;
1458
- return [i, c, conds[i]];
1464
+ evalConditions = createMemo(() => {
1465
+ let conds = conditions();
1466
+ if (!Array.isArray(conds)) conds = [conds];
1467
+ for (let i = 0; i < conds.length; i++) {
1468
+ const c = conds[i].when;
1469
+ if (c) {
1470
+ keyed = !!conds[i].keyed;
1471
+ return [i, c, conds[i]];
1472
+ }
1459
1473
  }
1460
- }
1461
- return [-1];
1462
- }, undefined, {
1463
- equals,
1464
- name: "eval conditions"
1465
- } );
1474
+ return [-1];
1475
+ }, undefined, {
1476
+ equals,
1477
+ name: "eval conditions"
1478
+ } );
1466
1479
  return createMemo(() => {
1467
1480
  const [index, when, cond] = evalConditions();
1468
1481
  if (index < 0) return props.fallback;
@@ -1511,9 +1524,9 @@ const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFa
1511
1524
  const SuspenseListContext = createContext();
1512
1525
  function SuspenseList(props) {
1513
1526
  let [wrapper, setWrapper] = createSignal(() => ({
1514
- inFallback: false
1515
- })),
1516
- show;
1527
+ inFallback: false
1528
+ })),
1529
+ show;
1517
1530
  const listContext = useContext(SuspenseListContext);
1518
1531
  const [registry, setRegistry] = createSignal([]);
1519
1532
  if (listContext) {
@@ -1521,13 +1534,13 @@ function SuspenseList(props) {
1521
1534
  }
1522
1535
  const resolved = createMemo(prev => {
1523
1536
  const reveal = props.revealOrder,
1524
- tail = props.tail,
1525
- {
1526
- showContent = true,
1527
- showFallback = true
1528
- } = show ? show() : {},
1529
- reg = registry(),
1530
- reverse = reveal === "backwards";
1537
+ tail = props.tail,
1538
+ {
1539
+ showContent = true,
1540
+ showFallback = true
1541
+ } = show ? show() : {},
1542
+ reg = registry(),
1543
+ reverse = reveal === "backwards";
1531
1544
  if (reveal === "together") {
1532
1545
  const all = reg.every(inFallback => !inFallback());
1533
1546
  const res = reg.map(() => ({
@@ -1542,7 +1555,7 @@ function SuspenseList(props) {
1542
1555
  const res = [];
1543
1556
  for (let i = 0, len = reg.length; i < len; i++) {
1544
1557
  const n = reverse ? len - i - 1 : i,
1545
- s = reg[n]();
1558
+ s = reg[n]();
1546
1559
  if (!stop && !s) {
1547
1560
  res[n] = {
1548
1561
  showContent,
@@ -1585,25 +1598,25 @@ function SuspenseList(props) {
1585
1598
  }
1586
1599
  function Suspense(props) {
1587
1600
  let counter = 0,
1588
- show,
1589
- ctx,
1590
- p,
1591
- flicker,
1592
- error;
1601
+ show,
1602
+ ctx,
1603
+ p,
1604
+ flicker,
1605
+ error;
1593
1606
  const [inFallback, setFallback] = createSignal(false),
1594
- SuspenseContext = getSuspenseContext(),
1595
- store = {
1596
- increment: () => {
1597
- if (++counter === 1) setFallback(true);
1598
- },
1599
- decrement: () => {
1600
- if (--counter === 0) setFallback(false);
1607
+ SuspenseContext = getSuspenseContext(),
1608
+ store = {
1609
+ increment: () => {
1610
+ if (++counter === 1) setFallback(true);
1611
+ },
1612
+ decrement: () => {
1613
+ if (--counter === 0) setFallback(false);
1614
+ },
1615
+ inFallback,
1616
+ effects: [],
1617
+ resolved: false
1601
1618
  },
1602
- inFallback,
1603
- effects: [],
1604
- resolved: false
1605
- },
1606
- owner = getOwner();
1619
+ owner = getOwner();
1607
1620
  if (sharedConfig.context && sharedConfig.load) {
1608
1621
  const key = sharedConfig.context.id + sharedConfig.context.count;
1609
1622
  let ref = sharedConfig.load(key);
@@ -1643,10 +1656,10 @@ function Suspense(props) {
1643
1656
  const rendered = createMemo(() => props.children);
1644
1657
  return createMemo(prev => {
1645
1658
  const inFallback = store.inFallback(),
1646
- {
1647
- showContent = true,
1648
- showFallback = true
1649
- } = show ? show() : {};
1659
+ {
1660
+ showContent = true,
1661
+ showFallback = true
1662
+ } = show ? show() : {};
1650
1663
  if ((!inFallback || p && p !== "$$f") && showContent) {
1651
1664
  store.resolved = true;
1652
1665
  dispose && dispose();