solid-js 1.9.4 → 1.9.6

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016-2023 Ryan Carniato
3
+ Copyright (c) 2016-2025 Ryan Carniato
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/dev.cjs CHANGED
@@ -144,6 +144,7 @@ function nextHydrateContext() {
144
144
  };
145
145
  }
146
146
 
147
+ const IS_DEV = true;
147
148
  const equalFn = (a, b) => a === b;
148
149
  const $PROXY = Symbol("solid-proxy");
149
150
  const SUPPORTS_PROXY = typeof Proxy === "function";
@@ -174,7 +175,8 @@ let ExecCount = 0;
174
175
  const DevHooks = {
175
176
  afterUpdate: null,
176
177
  afterCreateOwner: null,
177
- afterCreateSignal: null
178
+ afterCreateSignal: null,
179
+ afterRegisterGraph: null
178
180
  };
179
181
  function createRoot(fn, detachedOwner) {
180
182
  const listener = Listener,
@@ -215,8 +217,12 @@ function createSignal(value, options) {
215
217
  };
216
218
  {
217
219
  if (options.name) s.name = options.name;
218
- if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
219
- if (!options.internal) registerGraph(s);
220
+ if (options.internal) {
221
+ s.internal = true;
222
+ } else {
223
+ registerGraph(s);
224
+ if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
225
+ }
220
226
  }
221
227
  const setter = value => {
222
228
  if (typeof value === "function") {
@@ -401,9 +407,10 @@ function createResource(pSource, pFetcher, pOptions) {
401
407
  }
402
408
  }
403
409
  });
404
- if (dynamic) createComputed(() => load(false));else load(false);
410
+ let owner = Owner;
411
+ if (dynamic) createComputed(() => (owner = Owner, load(false)));else load(false);
405
412
  return [read, {
406
- refetch: load,
413
+ refetch: info => runWithOwner(owner, () => load(info)),
407
414
  mutate: setValue
408
415
  }];
409
416
  }
@@ -578,9 +585,11 @@ function devComponent(Comp, props) {
578
585
  return c.tValue !== undefined ? c.tValue : c.value;
579
586
  }
580
587
  function registerGraph(value) {
581
- if (!Owner) return;
582
- if (Owner.sourceMap) Owner.sourceMap.push(value);else Owner.sourceMap = [value];
583
- value.graph = Owner;
588
+ if (Owner) {
589
+ if (Owner.sourceMap) Owner.sourceMap.push(value);else Owner.sourceMap = [value];
590
+ value.graph = Owner;
591
+ }
592
+ if (DevHooks.afterRegisterGraph) DevHooks.afterRegisterGraph(value);
584
593
  }
585
594
  function createContext(defaultValue, options) {
586
595
  const id = Symbol("context");
@@ -691,7 +700,7 @@ function writeSignal(node, value, isComp) {
691
700
  }
692
701
  if (Updates.length > 10e5) {
693
702
  Updates = [];
694
- if (true) throw new Error("Potential Infinite Loop Detected.");
703
+ if (IS_DEV) throw new Error("Potential Infinite Loop Detected.");
695
704
  throw new Error();
696
705
  }
697
706
  }, false);
@@ -1097,8 +1106,8 @@ function observable(input) {
1097
1106
  }
1098
1107
  };
1099
1108
  }
1100
- function from(producer) {
1101
- const [s, set] = createSignal(undefined, {
1109
+ function from(producer, initalValue = undefined) {
1110
+ const [s, set] = createSignal(initalValue, {
1102
1111
  equals: false
1103
1112
  });
1104
1113
  if ("subscribe" in producer) {
@@ -1462,7 +1471,7 @@ function lazy(fn) {
1462
1471
  }
1463
1472
  let Comp;
1464
1473
  return createMemo(() => (Comp = comp()) ? untrack(() => {
1465
- if (true) Object.assign(Comp, {
1474
+ if (IS_DEV) Object.assign(Comp, {
1466
1475
  [$DEVCOMP]: true
1467
1476
  });
1468
1477
  if (!ctx || sharedConfig.done) return Comp(props);
@@ -1501,8 +1510,11 @@ function Index(props) {
1501
1510
  }
1502
1511
  function Show(props) {
1503
1512
  const keyed = props.keyed;
1504
- const condition = createMemo(() => props.when, undefined, {
1505
- equals: (a, b) => keyed ? a === b : !a === !b,
1513
+ const conditionValue = createMemo(() => props.when, undefined, {
1514
+ name: "condition value"
1515
+ } );
1516
+ const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
1517
+ equals: (a, b) => !a === !b,
1506
1518
  name: "condition"
1507
1519
  } );
1508
1520
  return createMemo(() => {
@@ -1512,7 +1524,7 @@ function Show(props) {
1512
1524
  const fn = typeof child === "function" && child.length > 0;
1513
1525
  return fn ? untrack(() => child(keyed ? c : () => {
1514
1526
  if (!untrack(condition)) throw narrowedError("Show");
1515
- return props.when;
1527
+ return conditionValue();
1516
1528
  })) : child;
1517
1529
  }
1518
1530
  return props.fallback;
@@ -1521,35 +1533,38 @@ function Show(props) {
1521
1533
  } );
1522
1534
  }
1523
1535
  function Switch(props) {
1524
- let keyed = false;
1525
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1526
- const conditions = children(() => props.children),
1527
- evalConditions = createMemo(() => {
1528
- let conds = conditions();
1529
- if (!Array.isArray(conds)) conds = [conds];
1530
- for (let i = 0; i < conds.length; i++) {
1531
- const c = conds[i].when;
1532
- if (c) {
1533
- keyed = !!conds[i].keyed;
1534
- return [i, c, conds[i]];
1535
- }
1536
- }
1537
- return [-1];
1538
- }, undefined, {
1539
- equals,
1540
- name: "eval conditions"
1541
- } );
1536
+ const chs = children(() => props.children);
1537
+ const switchFunc = createMemo(() => {
1538
+ const ch = chs();
1539
+ const mps = Array.isArray(ch) ? ch : [ch];
1540
+ let func = () => undefined;
1541
+ for (let i = 0; i < mps.length; i++) {
1542
+ const index = i;
1543
+ const mp = mps[i];
1544
+ const prevFunc = func;
1545
+ const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
1546
+ name: "condition value"
1547
+ } );
1548
+ const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
1549
+ equals: (a, b) => !a === !b,
1550
+ name: "condition"
1551
+ } );
1552
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
1553
+ }
1554
+ return func;
1555
+ });
1542
1556
  return createMemo(() => {
1543
- const [index, when, cond] = evalConditions();
1544
- if (index < 0) return props.fallback;
1545
- const c = cond.children;
1546
- const fn = typeof c === "function" && c.length > 0;
1547
- return fn ? untrack(() => c(keyed ? when : () => {
1548
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1549
- return cond.when;
1550
- })) : c;
1557
+ const sel = switchFunc()();
1558
+ if (!sel) return props.fallback;
1559
+ const [index, conditionValue, mp] = sel;
1560
+ const child = mp.children;
1561
+ const fn = typeof child === "function" && child.length > 0;
1562
+ return fn ? untrack(() => child(mp.keyed ? conditionValue() : () => {
1563
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
1564
+ return conditionValue();
1565
+ })) : child;
1551
1566
  }, undefined, {
1552
- name: "value"
1567
+ name: "eval conditions"
1553
1568
  } );
1554
1569
  }
1555
1570
  function Match(props) {
package/dist/dev.js CHANGED
@@ -144,6 +144,7 @@ function nextHydrateContext() {
144
144
  };
145
145
  }
146
146
 
147
+ const IS_DEV = true;
147
148
  const equalFn = (a, b) => a === b;
148
149
  const $PROXY = Symbol("solid-proxy");
149
150
  const SUPPORTS_PROXY = typeof Proxy === "function";
@@ -174,7 +175,8 @@ let ExecCount = 0;
174
175
  const DevHooks = {
175
176
  afterUpdate: null,
176
177
  afterCreateOwner: null,
177
- afterCreateSignal: null
178
+ afterCreateSignal: null,
179
+ afterRegisterGraph: null
178
180
  };
179
181
  function createRoot(fn, detachedOwner) {
180
182
  const listener = Listener,
@@ -220,8 +222,12 @@ function createSignal(value, options) {
220
222
  };
221
223
  {
222
224
  if (options.name) s.name = options.name;
223
- if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
224
- if (!options.internal) registerGraph(s);
225
+ if (options.internal) {
226
+ s.internal = true;
227
+ } else {
228
+ registerGraph(s);
229
+ if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
230
+ }
225
231
  }
226
232
  const setter = value => {
227
233
  if (typeof value === "function") {
@@ -429,12 +435,13 @@ function createResource(pSource, pFetcher, pOptions) {
429
435
  }
430
436
  }
431
437
  });
432
- if (dynamic) createComputed(() => load(false));
438
+ let owner = Owner;
439
+ if (dynamic) createComputed(() => ((owner = Owner), load(false)));
433
440
  else load(false);
434
441
  return [
435
442
  read,
436
443
  {
437
- refetch: load,
444
+ refetch: info => runWithOwner(owner, () => load(info)),
438
445
  mutate: setValue
439
446
  }
440
447
  ];
@@ -648,10 +655,12 @@ function devComponent(Comp, props) {
648
655
  return c.tValue !== undefined ? c.tValue : c.value;
649
656
  }
650
657
  function registerGraph(value) {
651
- if (!Owner) return;
652
- if (Owner.sourceMap) Owner.sourceMap.push(value);
653
- else Owner.sourceMap = [value];
654
- value.graph = Owner;
658
+ if (Owner) {
659
+ if (Owner.sourceMap) Owner.sourceMap.push(value);
660
+ else Owner.sourceMap = [value];
661
+ value.graph = Owner;
662
+ }
663
+ if (DevHooks.afterRegisterGraph) DevHooks.afterRegisterGraph(value);
655
664
  }
656
665
  function createContext(defaultValue, options) {
657
666
  const id = Symbol("context");
@@ -765,7 +774,7 @@ function writeSignal(node, value, isComp) {
765
774
  }
766
775
  if (Updates.length > 10e5) {
767
776
  Updates = [];
768
- if (true) throw new Error("Potential Infinite Loop Detected.");
777
+ if (IS_DEV) throw new Error("Potential Infinite Loop Detected.");
769
778
  throw new Error();
770
779
  }
771
780
  }, false);
@@ -1198,8 +1207,8 @@ function observable(input) {
1198
1207
  }
1199
1208
  };
1200
1209
  }
1201
- function from(producer) {
1202
- const [s, set] = createSignal(undefined, {
1210
+ function from(producer, initalValue = undefined) {
1211
+ const [s, set] = createSignal(initalValue, {
1203
1212
  equals: false
1204
1213
  });
1205
1214
  if ("subscribe" in producer) {
@@ -1595,7 +1604,7 @@ function lazy(fn) {
1595
1604
  return createMemo(() =>
1596
1605
  (Comp = comp())
1597
1606
  ? untrack(() => {
1598
- if (true)
1607
+ if (IS_DEV)
1599
1608
  Object.assign(Comp, {
1600
1609
  [$DEVCOMP]: true
1601
1610
  });
@@ -1646,10 +1655,15 @@ function Index(props) {
1646
1655
  }
1647
1656
  function Show(props) {
1648
1657
  const keyed = props.keyed;
1649
- const condition = createMemo(() => props.when, undefined, {
1650
- equals: (a, b) => (keyed ? a === b : !a === !b),
1651
- name: "condition"
1658
+ const conditionValue = createMemo(() => props.when, undefined, {
1659
+ name: "condition value"
1652
1660
  });
1661
+ const condition = keyed
1662
+ ? conditionValue
1663
+ : createMemo(conditionValue, undefined, {
1664
+ equals: (a, b) => !a === !b,
1665
+ name: "condition"
1666
+ });
1653
1667
  return createMemo(
1654
1668
  () => {
1655
1669
  const c = condition();
@@ -1663,7 +1677,7 @@ function Show(props) {
1663
1677
  ? c
1664
1678
  : () => {
1665
1679
  if (!untrack(condition)) throw narrowedError("Show");
1666
- return props.when;
1680
+ return conditionValue();
1667
1681
  }
1668
1682
  )
1669
1683
  )
@@ -1678,50 +1692,51 @@ function Show(props) {
1678
1692
  );
1679
1693
  }
1680
1694
  function Switch(props) {
1681
- let keyed = false;
1682
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1683
- const conditions = children(() => props.children),
1684
- evalConditions = createMemo(
1685
- () => {
1686
- let conds = conditions();
1687
- if (!Array.isArray(conds)) conds = [conds];
1688
- for (let i = 0; i < conds.length; i++) {
1689
- const c = conds[i].when;
1690
- if (c) {
1691
- keyed = !!conds[i].keyed;
1692
- return [i, c, conds[i]];
1693
- }
1694
- }
1695
- return [-1];
1696
- },
1697
- undefined,
1698
- {
1699
- equals,
1700
- name: "eval conditions"
1701
- }
1702
- );
1695
+ const chs = children(() => props.children);
1696
+ const switchFunc = createMemo(() => {
1697
+ const ch = chs();
1698
+ const mps = Array.isArray(ch) ? ch : [ch];
1699
+ let func = () => undefined;
1700
+ for (let i = 0; i < mps.length; i++) {
1701
+ const index = i;
1702
+ const mp = mps[i];
1703
+ const prevFunc = func;
1704
+ const conditionValue = createMemo(() => (prevFunc() ? undefined : mp.when), undefined, {
1705
+ name: "condition value"
1706
+ });
1707
+ const condition = mp.keyed
1708
+ ? conditionValue
1709
+ : createMemo(conditionValue, undefined, {
1710
+ equals: (a, b) => !a === !b,
1711
+ name: "condition"
1712
+ });
1713
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
1714
+ }
1715
+ return func;
1716
+ });
1703
1717
  return createMemo(
1704
1718
  () => {
1705
- const [index, when, cond] = evalConditions();
1706
- if (index < 0) return props.fallback;
1707
- const c = cond.children;
1708
- const fn = typeof c === "function" && c.length > 0;
1719
+ const sel = switchFunc()();
1720
+ if (!sel) return props.fallback;
1721
+ const [index, conditionValue, mp] = sel;
1722
+ const child = mp.children;
1723
+ const fn = typeof child === "function" && child.length > 0;
1709
1724
  return fn
1710
1725
  ? untrack(() =>
1711
- c(
1712
- keyed
1713
- ? when
1726
+ child(
1727
+ mp.keyed
1728
+ ? conditionValue()
1714
1729
  : () => {
1715
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1716
- return cond.when;
1730
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
1731
+ return conditionValue();
1717
1732
  }
1718
1733
  )
1719
1734
  )
1720
- : c;
1735
+ : child;
1721
1736
  },
1722
1737
  undefined,
1723
1738
  {
1724
- name: "value"
1739
+ name: "eval conditions"
1725
1740
  }
1726
1741
  );
1727
1742
  }
package/dist/solid.cjs CHANGED
@@ -144,6 +144,7 @@ function nextHydrateContext() {
144
144
  };
145
145
  }
146
146
 
147
+ const IS_DEV = false;
147
148
  const equalFn = (a, b) => a === b;
148
149
  const $PROXY = Symbol("solid-proxy");
149
150
  const SUPPORTS_PROXY = typeof Proxy === "function";
@@ -383,9 +384,10 @@ function createResource(pSource, pFetcher, pOptions) {
383
384
  }
384
385
  }
385
386
  });
386
- if (dynamic) createComputed(() => load(false));else load(false);
387
+ let owner = Owner;
388
+ if (dynamic) createComputed(() => (owner = Owner, load(false)));else load(false);
387
389
  return [read, {
388
- refetch: load,
390
+ refetch: info => runWithOwner(owner, () => load(info)),
389
391
  mutate: setValue
390
392
  }];
391
393
  }
@@ -651,7 +653,7 @@ function writeSignal(node, value, isComp) {
651
653
  }
652
654
  if (Updates.length > 10e5) {
653
655
  Updates = [];
654
- if (false) ;
656
+ if (IS_DEV) ;
655
657
  throw new Error();
656
658
  }
657
659
  }, false);
@@ -1054,8 +1056,8 @@ function observable(input) {
1054
1056
  }
1055
1057
  };
1056
1058
  }
1057
- function from(producer) {
1058
- const [s, set] = createSignal(undefined, {
1059
+ function from(producer, initalValue = undefined) {
1060
+ const [s, set] = createSignal(initalValue, {
1059
1061
  equals: false
1060
1062
  });
1061
1063
  if ("subscribe" in producer) {
@@ -1415,7 +1417,7 @@ function lazy(fn) {
1415
1417
  }
1416
1418
  let Comp;
1417
1419
  return createMemo(() => (Comp = comp()) ? untrack(() => {
1418
- if (false) ;
1420
+ if (IS_DEV) ;
1419
1421
  if (!ctx || sharedConfig.done) return Comp(props);
1420
1422
  const c = sharedConfig.context;
1421
1423
  setHydrateContext(ctx);
@@ -1448,8 +1450,9 @@ function Index(props) {
1448
1450
  }
1449
1451
  function Show(props) {
1450
1452
  const keyed = props.keyed;
1451
- const condition = createMemo(() => props.when, undefined, {
1452
- equals: (a, b) => keyed ? a === b : !a === !b
1453
+ const conditionValue = createMemo(() => props.when, undefined, undefined);
1454
+ const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
1455
+ equals: (a, b) => !a === !b
1453
1456
  });
1454
1457
  return createMemo(() => {
1455
1458
  const c = condition();
@@ -1458,39 +1461,40 @@ function Show(props) {
1458
1461
  const fn = typeof child === "function" && child.length > 0;
1459
1462
  return fn ? untrack(() => child(keyed ? c : () => {
1460
1463
  if (!untrack(condition)) throw narrowedError("Show");
1461
- return props.when;
1464
+ return conditionValue();
1462
1465
  })) : child;
1463
1466
  }
1464
1467
  return props.fallback;
1465
1468
  }, undefined, undefined);
1466
1469
  }
1467
1470
  function Switch(props) {
1468
- let keyed = false;
1469
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1470
- const conditions = children(() => props.children),
1471
- evalConditions = createMemo(() => {
1472
- let conds = conditions();
1473
- if (!Array.isArray(conds)) conds = [conds];
1474
- for (let i = 0; i < conds.length; i++) {
1475
- const c = conds[i].when;
1476
- if (c) {
1477
- keyed = !!conds[i].keyed;
1478
- return [i, c, conds[i]];
1479
- }
1480
- }
1481
- return [-1];
1482
- }, undefined, {
1483
- equals
1484
- });
1471
+ const chs = children(() => props.children);
1472
+ const switchFunc = createMemo(() => {
1473
+ const ch = chs();
1474
+ const mps = Array.isArray(ch) ? ch : [ch];
1475
+ let func = () => undefined;
1476
+ for (let i = 0; i < mps.length; i++) {
1477
+ const index = i;
1478
+ const mp = mps[i];
1479
+ const prevFunc = func;
1480
+ const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
1481
+ const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
1482
+ equals: (a, b) => !a === !b
1483
+ });
1484
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
1485
+ }
1486
+ return func;
1487
+ });
1485
1488
  return createMemo(() => {
1486
- const [index, when, cond] = evalConditions();
1487
- if (index < 0) return props.fallback;
1488
- const c = cond.children;
1489
- const fn = typeof c === "function" && c.length > 0;
1490
- return fn ? untrack(() => c(keyed ? when : () => {
1491
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1492
- return cond.when;
1493
- })) : c;
1489
+ const sel = switchFunc()();
1490
+ if (!sel) return props.fallback;
1491
+ const [index, conditionValue, mp] = sel;
1492
+ const child = mp.children;
1493
+ const fn = typeof child === "function" && child.length > 0;
1494
+ return fn ? untrack(() => child(mp.keyed ? conditionValue() : () => {
1495
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
1496
+ return conditionValue();
1497
+ })) : child;
1494
1498
  }, undefined, undefined);
1495
1499
  }
1496
1500
  function Match(props) {