solid-js 1.5.0-beta.2 → 1.5.0-beta.3

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
@@ -169,7 +169,7 @@ function createRoot(fn, detachedOwner) {
169
169
  },
170
170
  updateFn = unowned ? () => fn(() => {
171
171
  throw new Error("Dispose method must be an explicit argument to createRoot function");
172
- }) : () => fn(() => cleanNode(root));
172
+ }) : () => fn(() => untrack(() => cleanNode(root)));
173
173
  {
174
174
  if (owner) root.name = `${owner.name}-r${rootCount++}`;
175
175
  globalThis._$afterCreateRoot && globalThis._$afterCreateRoot(root);
@@ -272,7 +272,7 @@ function createResource(pSource, pFetcher, pOptions) {
272
272
  if (sharedConfig.context) {
273
273
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
274
274
  let v;
275
- if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
275
+ if (options.useInitialValue) initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
276
276
  }
277
277
  function loadEnd(p, v, success, key) {
278
278
  if (pr === p) {
@@ -969,7 +969,7 @@ function resolveChildren(children) {
969
969
  function createProvider(id) {
970
970
  return function provider(props) {
971
971
  let res;
972
- createComputed(() => res = untrack(() => {
972
+ createRenderEffect(() => res = untrack(() => {
973
973
  Owner.context = {
974
974
  [id]: props.value
975
975
  };
@@ -1370,6 +1370,7 @@ function Index(props) {
1370
1370
  }
1371
1371
  function Show(props) {
1372
1372
  let strictEqual = false;
1373
+ const keyed = props.keyed;
1373
1374
  const condition = createMemo(() => props.when, undefined, {
1374
1375
  equals: (a, b) => strictEqual ? a === b : !a === !b
1375
1376
  });
@@ -1377,20 +1378,26 @@ function Show(props) {
1377
1378
  const c = condition();
1378
1379
  if (c) {
1379
1380
  const child = props.children;
1380
- return (strictEqual = typeof child === "function" && child.length > 0) ? untrack(() => child(c)) : child;
1381
+ const fn = typeof child === "function" && child.length > 0;
1382
+ strictEqual = keyed || fn;
1383
+ return fn ? untrack(() => child(c)) : child;
1381
1384
  }
1382
1385
  return props.fallback;
1383
1386
  });
1384
1387
  }
1385
1388
  function Switch(props) {
1386
1389
  let strictEqual = false;
1390
+ let keyed = false;
1387
1391
  const conditions = children(() => props.children),
1388
1392
  evalConditions = createMemo(() => {
1389
1393
  let conds = conditions();
1390
1394
  if (!Array.isArray(conds)) conds = [conds];
1391
1395
  for (let i = 0; i < conds.length; i++) {
1392
1396
  const c = conds[i].when;
1393
- if (c) return [i, c, conds[i]];
1397
+ if (c) {
1398
+ keyed = !!conds[i].keyed;
1399
+ return [i, c, conds[i]];
1400
+ }
1394
1401
  }
1395
1402
  return [-1];
1396
1403
  }, undefined, {
@@ -1400,7 +1407,9 @@ function Switch(props) {
1400
1407
  const [index, when, cond] = evalConditions();
1401
1408
  if (index < 0) return props.fallback;
1402
1409
  const c = cond.children;
1403
- return (strictEqual = typeof c === "function" && c.length > 0) ? untrack(() => c(when)) : c;
1410
+ const fn = typeof c === "function" && c.length > 0;
1411
+ strictEqual = keyed || fn;
1412
+ return fn ? untrack(() => c(when)) : c;
1404
1413
  });
1405
1414
  }
1406
1415
  function Match(props) {
@@ -1432,74 +1441,85 @@ function ErrorBoundary(props) {
1432
1441
  });
1433
1442
  }
1434
1443
 
1444
+ const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback;
1435
1445
  const SuspenseListContext = createContext();
1436
1446
  function SuspenseList(props) {
1437
- let suspenseSetter, showContent, showFallback;
1447
+ let [wrapper, setWrapper] = createSignal(() => ({
1448
+ inFallback: false
1449
+ })),
1450
+ show;
1438
1451
  const listContext = useContext(SuspenseListContext);
1452
+ const [registry, setRegistry] = createSignal([]);
1439
1453
  if (listContext) {
1440
- const [inFallback, setFallback] = createSignal(false);
1441
- suspenseSetter = setFallback;
1442
- [showContent, showFallback] = listContext.register(inFallback);
1454
+ show = listContext.register(createMemo(() => wrapper()().inFallback));
1443
1455
  }
1444
- const [registry, setRegistry] = createSignal([]),
1445
- comp = createComponent(SuspenseListContext.Provider, {
1446
- value: {
1447
- register: inFallback => {
1448
- const [showingContent, showContent] = createSignal(false),
1449
- [showingFallback, showFallback] = createSignal(false);
1450
- setRegistry(registry => [...registry, {
1451
- inFallback,
1452
- showContent,
1453
- showFallback
1454
- }]);
1455
- return [showingContent, showingFallback];
1456
- }
1457
- },
1458
- get children() {
1459
- return props.children;
1460
- }
1461
- });
1462
- createComputed(() => {
1456
+ const resolved = createMemo(prev => {
1463
1457
  const reveal = props.revealOrder,
1464
1458
  tail = props.tail,
1465
- visibleContent = showContent ? showContent() : true,
1466
- visibleFallback = showFallback ? showFallback() : true,
1459
+ {
1460
+ showContent = true,
1461
+ showFallback = true
1462
+ } = show ? show() : {},
1467
1463
  reg = registry(),
1468
1464
  reverse = reveal === "backwards";
1469
1465
  if (reveal === "together") {
1470
- const all = reg.every(i => !i.inFallback());
1471
- suspenseSetter && suspenseSetter(!all);
1472
- reg.forEach(i => {
1473
- i.showContent(all && visibleContent);
1474
- i.showFallback(visibleFallback);
1475
- });
1476
- return;
1466
+ const all = reg.every(inFallback => !inFallback());
1467
+ const res = reg.map(() => ({
1468
+ showContent: all && showContent,
1469
+ showFallback
1470
+ }));
1471
+ res.inFallback = !all;
1472
+ return res;
1477
1473
  }
1478
1474
  let stop = false;
1475
+ let inFallback = prev.inFallback;
1476
+ const res = [];
1479
1477
  for (let i = 0, len = reg.length; i < len; i++) {
1480
1478
  const n = reverse ? len - i - 1 : i,
1481
- s = reg[n].inFallback();
1479
+ s = reg[n]();
1482
1480
  if (!stop && !s) {
1483
- reg[n].showContent(visibleContent);
1484
- reg[n].showFallback(visibleFallback);
1481
+ res[n] = {
1482
+ showContent,
1483
+ showFallback
1484
+ };
1485
1485
  } else {
1486
1486
  const next = !stop;
1487
- if (next && suspenseSetter) suspenseSetter(true);
1488
- if (!tail || next && tail === "collapsed") {
1489
- reg[n].showFallback(visibleFallback);
1490
- } else reg[n].showFallback(false);
1487
+ if (next) inFallback = true;
1488
+ res[n] = {
1489
+ showContent: next,
1490
+ showFallback: !tail || next && tail === "collapsed" ? showFallback : false
1491
+ };
1491
1492
  stop = true;
1492
- reg[n].showContent(next);
1493
1493
  }
1494
1494
  }
1495
- if (!stop && suspenseSetter) suspenseSetter(false);
1495
+ if (!stop) inFallback = false;
1496
+ res.inFallback = inFallback;
1497
+ return res;
1498
+ }, {
1499
+ inFallback: false
1500
+ });
1501
+ setWrapper(() => resolved);
1502
+ return createComponent(SuspenseListContext.Provider, {
1503
+ value: {
1504
+ register: inFallback => {
1505
+ let index;
1506
+ setRegistry(registry => {
1507
+ index = registry.length;
1508
+ return [...registry, inFallback];
1509
+ });
1510
+ return createMemo(() => resolved()[index], undefined, {
1511
+ equals: suspenseListEquals
1512
+ });
1513
+ }
1514
+ },
1515
+ get children() {
1516
+ return props.children;
1517
+ }
1496
1518
  });
1497
- return comp;
1498
1519
  }
1499
1520
  function Suspense(props) {
1500
1521
  let counter = 0,
1501
- showContent,
1502
- showFallback,
1522
+ show,
1503
1523
  ctx,
1504
1524
  p,
1505
1525
  flicker,
@@ -1540,7 +1560,7 @@ function Suspense(props) {
1540
1560
  }
1541
1561
  }
1542
1562
  const listContext = useContext(SuspenseListContext);
1543
- if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1563
+ if (listContext) show = listContext.register(store.inFallback);
1544
1564
  let dispose;
1545
1565
  onCleanup(() => dispose && dispose());
1546
1566
  return createComponent(SuspenseContext.Provider, {
@@ -1555,18 +1575,21 @@ function Suspense(props) {
1555
1575
  }
1556
1576
  if (ctx && p === "$$f") setHydrateContext();
1557
1577
  const rendered = createMemo(() => props.children);
1558
- return createMemo(() => {
1578
+ return createMemo(prev => {
1559
1579
  const inFallback = store.inFallback(),
1560
- visibleContent = showContent ? showContent() : true,
1561
- visibleFallback = showFallback ? showFallback() : true;
1562
- dispose && dispose();
1563
- if ((!inFallback || p && p !== "$$f") && visibleContent) {
1580
+ {
1581
+ showContent = true,
1582
+ showFallback = true
1583
+ } = show ? show() : {};
1584
+ if ((!inFallback || p && p !== "$$f") && showContent) {
1564
1585
  store.resolved = true;
1565
- ctx = p = undefined;
1586
+ dispose && dispose();
1587
+ dispose = ctx = p = undefined;
1566
1588
  resumeEffects(store.effects);
1567
1589
  return rendered();
1568
1590
  }
1569
- if (!visibleFallback) return;
1591
+ if (!showFallback) return;
1592
+ if (dispose) return prev;
1570
1593
  return createRoot(disposer => {
1571
1594
  dispose = disposer;
1572
1595
  if (ctx) {
package/dist/dev.js CHANGED
@@ -165,7 +165,7 @@ function createRoot(fn, detachedOwner) {
165
165
  },
166
166
  updateFn = unowned ? () => fn(() => {
167
167
  throw new Error("Dispose method must be an explicit argument to createRoot function");
168
- }) : () => fn(() => cleanNode(root));
168
+ }) : () => fn(() => untrack(() => cleanNode(root)));
169
169
  {
170
170
  if (owner) root.name = `${owner.name}-r${rootCount++}`;
171
171
  globalThis._$afterCreateRoot && globalThis._$afterCreateRoot(root);
@@ -268,7 +268,7 @@ function createResource(pSource, pFetcher, pOptions) {
268
268
  if (sharedConfig.context) {
269
269
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
270
270
  let v;
271
- if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
271
+ if (options.useInitialValue) initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
272
272
  }
273
273
  function loadEnd(p, v, success, key) {
274
274
  if (pr === p) {
@@ -965,7 +965,7 @@ function resolveChildren(children) {
965
965
  function createProvider(id) {
966
966
  return function provider(props) {
967
967
  let res;
968
- createComputed(() => res = untrack(() => {
968
+ createRenderEffect(() => res = untrack(() => {
969
969
  Owner.context = {
970
970
  [id]: props.value
971
971
  };
@@ -1366,6 +1366,7 @@ function Index(props) {
1366
1366
  }
1367
1367
  function Show(props) {
1368
1368
  let strictEqual = false;
1369
+ const keyed = props.keyed;
1369
1370
  const condition = createMemo(() => props.when, undefined, {
1370
1371
  equals: (a, b) => strictEqual ? a === b : !a === !b
1371
1372
  });
@@ -1373,20 +1374,26 @@ function Show(props) {
1373
1374
  const c = condition();
1374
1375
  if (c) {
1375
1376
  const child = props.children;
1376
- return (strictEqual = typeof child === "function" && child.length > 0) ? untrack(() => child(c)) : child;
1377
+ const fn = typeof child === "function" && child.length > 0;
1378
+ strictEqual = keyed || fn;
1379
+ return fn ? untrack(() => child(c)) : child;
1377
1380
  }
1378
1381
  return props.fallback;
1379
1382
  });
1380
1383
  }
1381
1384
  function Switch(props) {
1382
1385
  let strictEqual = false;
1386
+ let keyed = false;
1383
1387
  const conditions = children(() => props.children),
1384
1388
  evalConditions = createMemo(() => {
1385
1389
  let conds = conditions();
1386
1390
  if (!Array.isArray(conds)) conds = [conds];
1387
1391
  for (let i = 0; i < conds.length; i++) {
1388
1392
  const c = conds[i].when;
1389
- if (c) return [i, c, conds[i]];
1393
+ if (c) {
1394
+ keyed = !!conds[i].keyed;
1395
+ return [i, c, conds[i]];
1396
+ }
1390
1397
  }
1391
1398
  return [-1];
1392
1399
  }, undefined, {
@@ -1396,7 +1403,9 @@ function Switch(props) {
1396
1403
  const [index, when, cond] = evalConditions();
1397
1404
  if (index < 0) return props.fallback;
1398
1405
  const c = cond.children;
1399
- return (strictEqual = typeof c === "function" && c.length > 0) ? untrack(() => c(when)) : c;
1406
+ const fn = typeof c === "function" && c.length > 0;
1407
+ strictEqual = keyed || fn;
1408
+ return fn ? untrack(() => c(when)) : c;
1400
1409
  });
1401
1410
  }
1402
1411
  function Match(props) {
@@ -1428,74 +1437,85 @@ function ErrorBoundary(props) {
1428
1437
  });
1429
1438
  }
1430
1439
 
1440
+ const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback;
1431
1441
  const SuspenseListContext = createContext();
1432
1442
  function SuspenseList(props) {
1433
- let suspenseSetter, showContent, showFallback;
1443
+ let [wrapper, setWrapper] = createSignal(() => ({
1444
+ inFallback: false
1445
+ })),
1446
+ show;
1434
1447
  const listContext = useContext(SuspenseListContext);
1448
+ const [registry, setRegistry] = createSignal([]);
1435
1449
  if (listContext) {
1436
- const [inFallback, setFallback] = createSignal(false);
1437
- suspenseSetter = setFallback;
1438
- [showContent, showFallback] = listContext.register(inFallback);
1450
+ show = listContext.register(createMemo(() => wrapper()().inFallback));
1439
1451
  }
1440
- const [registry, setRegistry] = createSignal([]),
1441
- comp = createComponent(SuspenseListContext.Provider, {
1442
- value: {
1443
- register: inFallback => {
1444
- const [showingContent, showContent] = createSignal(false),
1445
- [showingFallback, showFallback] = createSignal(false);
1446
- setRegistry(registry => [...registry, {
1447
- inFallback,
1448
- showContent,
1449
- showFallback
1450
- }]);
1451
- return [showingContent, showingFallback];
1452
- }
1453
- },
1454
- get children() {
1455
- return props.children;
1456
- }
1457
- });
1458
- createComputed(() => {
1452
+ const resolved = createMemo(prev => {
1459
1453
  const reveal = props.revealOrder,
1460
1454
  tail = props.tail,
1461
- visibleContent = showContent ? showContent() : true,
1462
- visibleFallback = showFallback ? showFallback() : true,
1455
+ {
1456
+ showContent = true,
1457
+ showFallback = true
1458
+ } = show ? show() : {},
1463
1459
  reg = registry(),
1464
1460
  reverse = reveal === "backwards";
1465
1461
  if (reveal === "together") {
1466
- const all = reg.every(i => !i.inFallback());
1467
- suspenseSetter && suspenseSetter(!all);
1468
- reg.forEach(i => {
1469
- i.showContent(all && visibleContent);
1470
- i.showFallback(visibleFallback);
1471
- });
1472
- return;
1462
+ const all = reg.every(inFallback => !inFallback());
1463
+ const res = reg.map(() => ({
1464
+ showContent: all && showContent,
1465
+ showFallback
1466
+ }));
1467
+ res.inFallback = !all;
1468
+ return res;
1473
1469
  }
1474
1470
  let stop = false;
1471
+ let inFallback = prev.inFallback;
1472
+ const res = [];
1475
1473
  for (let i = 0, len = reg.length; i < len; i++) {
1476
1474
  const n = reverse ? len - i - 1 : i,
1477
- s = reg[n].inFallback();
1475
+ s = reg[n]();
1478
1476
  if (!stop && !s) {
1479
- reg[n].showContent(visibleContent);
1480
- reg[n].showFallback(visibleFallback);
1477
+ res[n] = {
1478
+ showContent,
1479
+ showFallback
1480
+ };
1481
1481
  } else {
1482
1482
  const next = !stop;
1483
- if (next && suspenseSetter) suspenseSetter(true);
1484
- if (!tail || next && tail === "collapsed") {
1485
- reg[n].showFallback(visibleFallback);
1486
- } else reg[n].showFallback(false);
1483
+ if (next) inFallback = true;
1484
+ res[n] = {
1485
+ showContent: next,
1486
+ showFallback: !tail || next && tail === "collapsed" ? showFallback : false
1487
+ };
1487
1488
  stop = true;
1488
- reg[n].showContent(next);
1489
1489
  }
1490
1490
  }
1491
- if (!stop && suspenseSetter) suspenseSetter(false);
1491
+ if (!stop) inFallback = false;
1492
+ res.inFallback = inFallback;
1493
+ return res;
1494
+ }, {
1495
+ inFallback: false
1496
+ });
1497
+ setWrapper(() => resolved);
1498
+ return createComponent(SuspenseListContext.Provider, {
1499
+ value: {
1500
+ register: inFallback => {
1501
+ let index;
1502
+ setRegistry(registry => {
1503
+ index = registry.length;
1504
+ return [...registry, inFallback];
1505
+ });
1506
+ return createMemo(() => resolved()[index], undefined, {
1507
+ equals: suspenseListEquals
1508
+ });
1509
+ }
1510
+ },
1511
+ get children() {
1512
+ return props.children;
1513
+ }
1492
1514
  });
1493
- return comp;
1494
1515
  }
1495
1516
  function Suspense(props) {
1496
1517
  let counter = 0,
1497
- showContent,
1498
- showFallback,
1518
+ show,
1499
1519
  ctx,
1500
1520
  p,
1501
1521
  flicker,
@@ -1536,7 +1556,7 @@ function Suspense(props) {
1536
1556
  }
1537
1557
  }
1538
1558
  const listContext = useContext(SuspenseListContext);
1539
- if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1559
+ if (listContext) show = listContext.register(store.inFallback);
1540
1560
  let dispose;
1541
1561
  onCleanup(() => dispose && dispose());
1542
1562
  return createComponent(SuspenseContext.Provider, {
@@ -1551,18 +1571,21 @@ function Suspense(props) {
1551
1571
  }
1552
1572
  if (ctx && p === "$$f") setHydrateContext();
1553
1573
  const rendered = createMemo(() => props.children);
1554
- return createMemo(() => {
1574
+ return createMemo(prev => {
1555
1575
  const inFallback = store.inFallback(),
1556
- visibleContent = showContent ? showContent() : true,
1557
- visibleFallback = showFallback ? showFallback() : true;
1558
- dispose && dispose();
1559
- if ((!inFallback || p && p !== "$$f") && visibleContent) {
1576
+ {
1577
+ showContent = true,
1578
+ showFallback = true
1579
+ } = show ? show() : {};
1580
+ if ((!inFallback || p && p !== "$$f") && showContent) {
1560
1581
  store.resolved = true;
1561
- ctx = p = undefined;
1582
+ dispose && dispose();
1583
+ dispose = ctx = p = undefined;
1562
1584
  resumeEffects(store.effects);
1563
1585
  return rendered();
1564
1586
  }
1565
- if (!visibleFallback) return;
1587
+ if (!showFallback) return;
1588
+ if (dispose) return prev;
1566
1589
  return createRoot(disposer => {
1567
1590
  dispose = disposer;
1568
1591
  if (ctx) {
package/dist/server.cjs CHANGED
@@ -394,7 +394,7 @@ function createResource(source, fetcher, options = {}) {
394
394
  let value = options.initialValue;
395
395
  let p;
396
396
  let error;
397
- if (sharedConfig.context.async) {
397
+ if (sharedConfig.context.async && !options.useInitialValue) {
398
398
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
399
399
  if (resource.ref) {
400
400
  if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
@@ -404,7 +404,7 @@ function createResource(source, fetcher, options = {}) {
404
404
  const read = () => {
405
405
  if (error) throw error;
406
406
  if (resourceContext && p) resourceContext.push(p);
407
- const resolved = sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
407
+ const resolved = !options.useInitialValue && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
408
408
  if (!resolved && read.loading) {
409
409
  const ctx = useContext(SuspenseContext);
410
410
  if (ctx) {
@@ -463,7 +463,7 @@ function createResource(source, fetcher, options = {}) {
463
463
  p = null;
464
464
  return ctx.resources[id].data;
465
465
  }
466
- load();
466
+ if (!options.useInitialValue) load();
467
467
  return resource.ref = [read, {
468
468
  refetch: load,
469
469
  mutate: v => value = v
package/dist/server.js CHANGED
@@ -390,7 +390,7 @@ function createResource(source, fetcher, options = {}) {
390
390
  let value = options.initialValue;
391
391
  let p;
392
392
  let error;
393
- if (sharedConfig.context.async) {
393
+ if (sharedConfig.context.async && !options.useInitialValue) {
394
394
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
395
395
  if (resource.ref) {
396
396
  if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
@@ -400,7 +400,7 @@ function createResource(source, fetcher, options = {}) {
400
400
  const read = () => {
401
401
  if (error) throw error;
402
402
  if (resourceContext && p) resourceContext.push(p);
403
- const resolved = sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
403
+ const resolved = !options.useInitialValue && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
404
404
  if (!resolved && read.loading) {
405
405
  const ctx = useContext(SuspenseContext);
406
406
  if (ctx) {
@@ -459,7 +459,7 @@ function createResource(source, fetcher, options = {}) {
459
459
  p = null;
460
460
  return ctx.resources[id].data;
461
461
  }
462
- load();
462
+ if (!options.useInitialValue) load();
463
463
  return resource.ref = [read, {
464
464
  refetch: load,
465
465
  mutate: v => value = v