solid-js 1.6.8 → 1.6.10

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
@@ -470,13 +471,16 @@ function getOwner() {
470
471
  }
471
472
  function runWithOwner(o, fn) {
472
473
  const prev = Owner;
474
+ const prevListener = Listener;
473
475
  Owner = o;
476
+ Listener = null;
474
477
  try {
475
478
  return runUpdates(fn, true);
476
479
  } catch (err) {
477
480
  handleError(err);
478
481
  } finally {
479
482
  Owner = prev;
483
+ Listener = prevListener;
480
484
  }
481
485
  }
482
486
  function enableScheduling(scheduler = requestCallback) {
@@ -523,11 +527,10 @@ function devComponent(Comp, props) {
523
527
  [$DEVCOMP]: true
524
528
  });
525
529
  return Comp(props);
526
- }), undefined, true);
530
+ }), undefined, true, 0);
527
531
  c.props = props;
528
532
  c.observers = null;
529
533
  c.observerSlots = null;
530
- c.state = 0;
531
534
  c.componentName = Comp.name;
532
535
  updateComputation(c);
533
536
  return c.tValue !== undefined ? c.tValue : c.value;
@@ -560,13 +563,15 @@ function registerGraph(name, value) {
560
563
  Owner.sourceMap || (Owner.sourceMap = {});
561
564
  while (Owner.sourceMap[tryName]) tryName = `${name}-${++i}`;
562
565
  Owner.sourceMap[tryName] = value;
566
+ value.graph = Owner;
563
567
  }
564
568
  return tryName;
565
569
  }
566
570
  function serializeGraph(owner) {
567
571
  owner || (owner = Owner);
568
572
  if (!owner) return {};
569
- return { ...serializeValues(owner.sourceMap),
573
+ return {
574
+ ...serializeValues(owner.sourceMap),
570
575
  ...(owner.owned ? serializeChildren(owner) : {})
571
576
  };
572
577
  }
@@ -682,8 +687,8 @@ function updateComputation(node) {
682
687
  if (!node.fn) return;
683
688
  cleanNode(node);
684
689
  const owner = Owner,
685
- listener = Listener,
686
- time = ExecCount;
690
+ listener = Listener,
691
+ time = ExecCount;
687
692
  Listener = Owner = node;
688
693
  runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time);
689
694
  if (Transition && !Transition.running && Transition.sources.has(node)) {
@@ -704,7 +709,17 @@ function runComputation(node, value, time) {
704
709
  try {
705
710
  nextValue = node.fn(value);
706
711
  } catch (err) {
707
- if (node.pure) Transition && Transition.running ? node.tState = STALE : node.state = STALE;
712
+ if (node.pure) {
713
+ if (Transition && Transition.running) {
714
+ node.tState = STALE;
715
+ node.tOwned && node.tOwned.forEach(cleanNode);
716
+ node.tOwned = undefined;
717
+ } else {
718
+ node.state = STALE;
719
+ node.owned && node.owned.forEach(cleanNode);
720
+ node.owned = null;
721
+ }
722
+ }
708
723
  handleError(err);
709
724
  }
710
725
  if (!node.updatedAt || node.updatedAt <= time) {
@@ -772,7 +787,7 @@ function runTop(node) {
772
787
  node = ancestors[i];
773
788
  if (runningTransition) {
774
789
  let top = node,
775
- prev = ancestors[i + 1];
790
+ prev = ancestors[i + 1];
776
791
  while ((top = top.owner) && top !== prev) {
777
792
  if (Transition.disposed.has(top)) return;
778
793
  }
@@ -799,6 +814,7 @@ function runUpdates(fn, init) {
799
814
  return res;
800
815
  } catch (err) {
801
816
  if (!Updates) Effects = null;
817
+ Updates = null;
802
818
  handleError(err);
803
819
  }
804
820
  }
@@ -869,7 +885,7 @@ function scheduleQueue(queue) {
869
885
  }
870
886
  function runUserEffects(queue) {
871
887
  let i,
872
- userLength = 0;
888
+ userLength = 0;
873
889
  for (i = 0; i < queue.length; i++) {
874
890
  const e = queue[i];
875
891
  if (!e.user) runTop(e);else queue[userLength++] = e;
@@ -905,11 +921,11 @@ function cleanNode(node) {
905
921
  if (node.sources) {
906
922
  while (node.sources.length) {
907
923
  const source = node.sources.pop(),
908
- index = node.sourceSlots.pop(),
909
- obs = source.observers;
924
+ index = node.sourceSlots.pop(),
925
+ obs = source.observers;
910
926
  if (obs && obs.length) {
911
927
  const n = obs.pop(),
912
- s = source.observerSlots.pop();
928
+ s = source.observerSlots.pop();
913
929
  if (index < obs.length) {
914
930
  n.sourceSlots[s] = index;
915
931
  obs[index] = n;
@@ -999,7 +1015,8 @@ function serializeChildren(root) {
999
1015
  const result = {};
1000
1016
  for (let i = 0, len = root.owned.length; i < len; i++) {
1001
1017
  const node = root.owned[i];
1002
- result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = { ...serializeValues(node.sourceMap),
1018
+ result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = {
1019
+ ...serializeValues(node.sourceMap),
1003
1020
  ...(node.owned ? serializeChildren(node) : {})
1004
1021
  };
1005
1022
  }
@@ -1057,27 +1074,27 @@ function dispose(d) {
1057
1074
  }
1058
1075
  function mapArray(list, mapFn, options = {}) {
1059
1076
  let items = [],
1060
- mapped = [],
1061
- disposers = [],
1062
- len = 0,
1063
- indexes = mapFn.length > 1 ? [] : null;
1077
+ mapped = [],
1078
+ disposers = [],
1079
+ len = 0,
1080
+ indexes = mapFn.length > 1 ? [] : null;
1064
1081
  onCleanup(() => dispose(disposers));
1065
1082
  return () => {
1066
1083
  let newItems = list() || [],
1067
- i,
1068
- j;
1084
+ i,
1085
+ j;
1069
1086
  newItems[$TRACK];
1070
1087
  return untrack(() => {
1071
1088
  let newLen = newItems.length,
1072
- newIndices,
1073
- newIndicesNext,
1074
- temp,
1075
- tempdisposers,
1076
- tempIndexes,
1077
- start,
1078
- end,
1079
- newEnd,
1080
- item;
1089
+ newIndices,
1090
+ newIndicesNext,
1091
+ temp,
1092
+ tempdisposers,
1093
+ tempIndexes,
1094
+ start,
1095
+ end,
1096
+ newEnd,
1097
+ item;
1081
1098
  if (newLen === 0) {
1082
1099
  if (len !== 0) {
1083
1100
  dispose(disposers);
@@ -1162,11 +1179,11 @@ function mapArray(list, mapFn, options = {}) {
1162
1179
  }
1163
1180
  function indexArray(list, mapFn, options = {}) {
1164
1181
  let items = [],
1165
- mapped = [],
1166
- disposers = [],
1167
- signals = [],
1168
- len = 0,
1169
- i;
1182
+ mapped = [],
1183
+ disposers = [],
1184
+ signals = [],
1185
+ len = 0,
1186
+ i;
1170
1187
  onCleanup(() => dispose(disposers));
1171
1188
  return () => {
1172
1189
  const newItems = list() || [];
@@ -1448,21 +1465,21 @@ function Switch(props) {
1448
1465
  let keyed = false;
1449
1466
  const equals = (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1450
1467
  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]];
1468
+ evalConditions = createMemo(() => {
1469
+ let conds = conditions();
1470
+ if (!Array.isArray(conds)) conds = [conds];
1471
+ for (let i = 0; i < conds.length; i++) {
1472
+ const c = conds[i].when;
1473
+ if (c) {
1474
+ keyed = !!conds[i].keyed;
1475
+ return [i, c, conds[i]];
1476
+ }
1459
1477
  }
1460
- }
1461
- return [-1];
1462
- }, undefined, {
1463
- equals,
1464
- name: "eval conditions"
1465
- } );
1478
+ return [-1];
1479
+ }, undefined, {
1480
+ equals,
1481
+ name: "eval conditions"
1482
+ } );
1466
1483
  return createMemo(() => {
1467
1484
  const [index, when, cond] = evalConditions();
1468
1485
  if (index < 0) return props.fallback;
@@ -1511,9 +1528,9 @@ const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFa
1511
1528
  const SuspenseListContext = createContext();
1512
1529
  function SuspenseList(props) {
1513
1530
  let [wrapper, setWrapper] = createSignal(() => ({
1514
- inFallback: false
1515
- })),
1516
- show;
1531
+ inFallback: false
1532
+ })),
1533
+ show;
1517
1534
  const listContext = useContext(SuspenseListContext);
1518
1535
  const [registry, setRegistry] = createSignal([]);
1519
1536
  if (listContext) {
@@ -1521,13 +1538,13 @@ function SuspenseList(props) {
1521
1538
  }
1522
1539
  const resolved = createMemo(prev => {
1523
1540
  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";
1541
+ tail = props.tail,
1542
+ {
1543
+ showContent = true,
1544
+ showFallback = true
1545
+ } = show ? show() : {},
1546
+ reg = registry(),
1547
+ reverse = reveal === "backwards";
1531
1548
  if (reveal === "together") {
1532
1549
  const all = reg.every(inFallback => !inFallback());
1533
1550
  const res = reg.map(() => ({
@@ -1542,7 +1559,7 @@ function SuspenseList(props) {
1542
1559
  const res = [];
1543
1560
  for (let i = 0, len = reg.length; i < len; i++) {
1544
1561
  const n = reverse ? len - i - 1 : i,
1545
- s = reg[n]();
1562
+ s = reg[n]();
1546
1563
  if (!stop && !s) {
1547
1564
  res[n] = {
1548
1565
  showContent,
@@ -1585,25 +1602,25 @@ function SuspenseList(props) {
1585
1602
  }
1586
1603
  function Suspense(props) {
1587
1604
  let counter = 0,
1588
- show,
1589
- ctx,
1590
- p,
1591
- flicker,
1592
- error;
1605
+ show,
1606
+ ctx,
1607
+ p,
1608
+ flicker,
1609
+ error;
1593
1610
  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);
1611
+ SuspenseContext = getSuspenseContext(),
1612
+ store = {
1613
+ increment: () => {
1614
+ if (++counter === 1) setFallback(true);
1615
+ },
1616
+ decrement: () => {
1617
+ if (--counter === 0) setFallback(false);
1618
+ },
1619
+ inFallback,
1620
+ effects: [],
1621
+ resolved: false
1601
1622
  },
1602
- inFallback,
1603
- effects: [],
1604
- resolved: false
1605
- },
1606
- owner = getOwner();
1623
+ owner = getOwner();
1607
1624
  if (sharedConfig.context && sharedConfig.load) {
1608
1625
  const key = sharedConfig.context.id + sharedConfig.context.count;
1609
1626
  let ref = sharedConfig.load(key);
@@ -1643,10 +1660,10 @@ function Suspense(props) {
1643
1660
  const rendered = createMemo(() => props.children);
1644
1661
  return createMemo(prev => {
1645
1662
  const inFallback = store.inFallback(),
1646
- {
1647
- showContent = true,
1648
- showFallback = true
1649
- } = show ? show() : {};
1663
+ {
1664
+ showContent = true,
1665
+ showFallback = true
1666
+ } = show ? show() : {};
1650
1667
  if ((!inFallback || p && p !== "$$f") && showContent) {
1651
1668
  store.resolved = true;
1652
1669
  dispose && dispose();