solid-js 1.4.8 → 1.5.0-beta.2

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.
Files changed (58) hide show
  1. package/dist/dev.cjs +119 -134
  2. package/dist/dev.js +119 -134
  3. package/dist/server.cjs +98 -49
  4. package/dist/server.js +98 -49
  5. package/dist/solid.cjs +119 -132
  6. package/dist/solid.js +119 -132
  7. package/h/jsx-runtime/types/jsx.d.ts +8 -1401
  8. package/h/types/hyperscript.d.ts +17 -0
  9. package/html/types/lit.d.ts +37 -0
  10. package/package.json +103 -41
  11. package/store/dist/dev.cjs +40 -22
  12. package/store/dist/dev.js +41 -23
  13. package/store/dist/store.cjs +40 -22
  14. package/store/dist/store.js +40 -22
  15. package/store/types/index.d.ts +4 -4
  16. package/store/types/mutable.d.ts +1 -1
  17. package/store/types/server.d.ts +1 -1
  18. package/store/types/store.d.ts +1 -1
  19. package/types/index.d.ts +8 -8
  20. package/types/jsx.d.ts +196 -1580
  21. package/types/reactive/array.d.ts +1 -1
  22. package/types/reactive/observable.d.ts +1 -1
  23. package/types/reactive/signal.d.ts +69 -34
  24. package/types/render/Suspense.d.ts +1 -1
  25. package/types/render/component.d.ts +22 -7
  26. package/types/render/flow.d.ts +2 -2
  27. package/types/render/index.d.ts +4 -4
  28. package/types/server/index.d.ts +3 -3
  29. package/types/server/reactive.d.ts +8 -3
  30. package/types/server/rendering.d.ts +11 -6
  31. package/universal/dist/dev.cjs +0 -0
  32. package/universal/dist/dev.js +0 -0
  33. package/universal/dist/universal.cjs +0 -0
  34. package/universal/dist/universal.js +0 -0
  35. package/universal/types/index.d.ts +1 -1
  36. package/web/dist/dev.cjs +3 -3
  37. package/web/dist/dev.js +3 -3
  38. package/web/dist/server.cjs +66 -90
  39. package/web/dist/server.js +66 -90
  40. package/web/dist/web.cjs +3 -3
  41. package/web/dist/web.js +3 -3
  42. package/web/types/client.d.ts +1 -1
  43. package/web/types/core.d.ts +3 -3
  44. package/web/types/index.d.ts +8 -9
  45. package/web/types/jsx.d.ts +1 -1
  46. package/web/types/server-mock.d.ts +4 -2
  47. package/web/types/server.d.ts +70 -0
  48. package/h/README.md +0 -99
  49. package/h/jsx-runtime/package.json +0 -8
  50. package/h/package.json +0 -8
  51. package/html/README.md +0 -84
  52. package/html/package.json +0 -8
  53. package/store/README.md +0 -23
  54. package/store/package.json +0 -35
  55. package/universal/README.md +0 -102
  56. package/universal/package.json +0 -18
  57. package/web/README.md +0 -7
  58. package/web/package.json +0 -35
package/dist/dev.cjs CHANGED
@@ -138,7 +138,6 @@ const signalOptions = {
138
138
  };
139
139
  let ERROR = null;
140
140
  let runEffects = runQueue;
141
- const NOTPENDING = {};
142
141
  const STALE = 1;
143
142
  const PENDING = 2;
144
143
  const UNOWNED = {
@@ -147,13 +146,13 @@ const UNOWNED = {
147
146
  context: null,
148
147
  owner: null
149
148
  };
149
+ const NO_INIT = {};
150
150
  const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
151
151
  var Owner = null;
152
152
  let Transition = null;
153
153
  let Scheduler = null;
154
154
  let ExternalSourceFactory = null;
155
155
  let Listener = null;
156
- let Pending = null;
157
156
  let Updates = null;
158
157
  let Effects = null;
159
158
  let ExecCount = 0;
@@ -190,13 +189,12 @@ function createSignal(value, options) {
190
189
  value,
191
190
  observers: null,
192
191
  observerSlots: null,
193
- pending: NOTPENDING,
194
192
  comparator: options.equals || undefined
195
193
  };
196
194
  if (!options.internal) s.name = registerGraph(options.name || hashValue(value), s);
197
195
  const setter = value => {
198
196
  if (typeof value === "function") {
199
- if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
197
+ if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value);
200
198
  }
201
199
  return writeSignal(s, value);
202
200
  };
@@ -235,7 +233,6 @@ function createReaction(onInvalidate, options) {
235
233
  function createMemo(fn, value, options) {
236
234
  options = options ? Object.assign({}, signalOptions, options) : signalOptions;
237
235
  const c = createComputation(fn, value, true, 0, options );
238
- c.pending = NOTPENDING;
239
236
  c.observers = null;
240
237
  c.observerSlots = null;
241
238
  c.comparator = options.equals || undefined;
@@ -245,46 +242,46 @@ function createMemo(fn, value, options) {
245
242
  } else updateComputation(c);
246
243
  return readSignal.bind(c);
247
244
  }
248
- function createResource(source, fetcher, options) {
249
- if (arguments.length === 2) {
250
- if (typeof fetcher === "object") {
251
- options = fetcher;
252
- fetcher = source;
253
- source = true;
254
- }
255
- } else if (arguments.length === 1) {
256
- fetcher = source;
245
+ function createResource(pSource, pFetcher, pOptions) {
246
+ let source;
247
+ let fetcher;
248
+ let options;
249
+ if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) {
257
250
  source = true;
251
+ fetcher = pSource;
252
+ options = pFetcher || {};
253
+ } else {
254
+ source = pSource;
255
+ fetcher = pFetcher;
256
+ options = pOptions || {};
258
257
  }
259
- options || (options = {});
260
- const contexts = new Set(),
261
- [value, setValue] = createSignal(options.initialValue),
262
- [track, trigger] = createSignal(undefined, {
263
- equals: false
264
- }),
265
- [loading, setLoading] = createSignal(false),
266
- [error, setError] = createSignal();
267
258
  let err = undefined,
268
259
  pr = null,
269
- initP = null,
260
+ initP = NO_INIT,
270
261
  id = null,
271
262
  loadedUnderTransition = false,
272
263
  scheduled = false,
273
264
  resolved = ("initialValue" in options),
274
265
  dynamic = typeof source === "function" && createMemo(source);
266
+ const contexts = new Set(),
267
+ [value, setValue] = options.store ? options.store(options.initialValue) : createSignal(options.initialValue),
268
+ [track, trigger] = createSignal(undefined, {
269
+ equals: false
270
+ }),
271
+ [state, setState] = createSignal(resolved ? "ready" : "unresolved");
275
272
  if (sharedConfig.context) {
276
273
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
277
- if (sharedConfig.load) initP = sharedConfig.load(id);
274
+ let v;
275
+ if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
278
276
  }
279
- function loadEnd(p, v, e, key) {
277
+ function loadEnd(p, v, success, key) {
280
278
  if (pr === p) {
281
279
  pr = null;
282
280
  resolved = true;
283
- if (initP && (p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
281
+ if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
284
282
  value: v
285
283
  }));
286
- initP = null;
287
- setError(err = e);
284
+ initP = NO_INIT;
288
285
  if (Transition && p && loadedUnderTransition) {
289
286
  Transition.promises.delete(p);
290
287
  loadedUnderTransition = false;
@@ -294,19 +291,20 @@ function createResource(source, fetcher, options) {
294
291
  Effects.push.apply(Effects, Transition.effects);
295
292
  Transition.effects = [];
296
293
  }
297
- completeLoad(v);
294
+ completeLoad(v, success);
298
295
  }, false);
299
- } else completeLoad(v);
296
+ } else completeLoad(v, success);
300
297
  }
301
298
  return v;
302
299
  }
303
- function completeLoad(v) {
304
- batch(() => {
300
+ function completeLoad(v, success) {
301
+ !success && (err = castError(v));
302
+ runUpdates(() => {
305
303
  setValue(() => v);
306
- setLoading(false);
304
+ setState(success ? "ready" : "error");
307
305
  for (const c of contexts.keys()) c.decrement();
308
306
  contexts.clear();
309
- });
307
+ }, false);
310
308
  }
311
309
  function read() {
312
310
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
@@ -326,48 +324,54 @@ function createResource(source, fetcher, options) {
326
324
  return v;
327
325
  }
328
326
  function load(refetching = true) {
329
- if (refetching && scheduled) return;
327
+ if (refetching !== false && scheduled) return;
330
328
  scheduled = false;
331
- setError(err = undefined);
329
+ err = undefined;
332
330
  const lookup = dynamic ? dynamic() : source;
333
331
  loadedUnderTransition = Transition && Transition.running;
334
332
  if (lookup == null || lookup === false) {
335
- loadEnd(pr, untrack(value));
333
+ loadEnd(pr, untrack(value), true);
336
334
  return;
337
335
  }
338
336
  if (Transition && pr) Transition.promises.delete(pr);
339
- const p = initP || untrack(() => fetcher(lookup, {
337
+ const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, {
340
338
  value: value(),
341
339
  refetching
342
340
  }));
343
341
  if (typeof p !== "object" || !("then" in p)) {
344
- loadEnd(pr, p);
342
+ loadEnd(pr, p, true);
345
343
  return p;
346
344
  }
347
345
  pr = p;
348
346
  scheduled = true;
349
347
  queueMicrotask(() => scheduled = false);
350
- batch(() => {
351
- setLoading(true);
348
+ runUpdates(() => {
349
+ setState(resolved ? "refreshing" : "pending");
352
350
  trigger();
353
- });
354
- return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, e, e));
351
+ }, false);
352
+ return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
355
353
  }
356
354
  Object.defineProperties(read, {
355
+ state: {
356
+ get() {
357
+ return state();
358
+ }
359
+ },
357
360
  loading: {
358
361
  get() {
359
- return loading();
362
+ const s = state();
363
+ return s === "pending" || s === "refreshing";
360
364
  }
361
365
  },
362
366
  error: {
363
367
  get() {
364
- return error();
368
+ return state() === "error" ? err : undefined;
365
369
  }
366
370
  },
367
371
  latest: {
368
372
  get() {
369
373
  if (!resolved) return read();
370
- if (err) throw err;
374
+ if (state() === "error") throw err;
371
375
  return value();
372
376
  }
373
377
  }
@@ -420,25 +424,7 @@ function createSelector(source, fn = equalFn, options) {
420
424
  };
421
425
  }
422
426
  function batch(fn) {
423
- if (Pending) return fn();
424
- let result;
425
- const q = Pending = [];
426
- try {
427
- result = fn();
428
- } finally {
429
- Pending = null;
430
- }
431
- runUpdates(() => {
432
- for (let i = 0; i < q.length; i += 1) {
433
- const data = q[i];
434
- if (data.pending !== NOTPENDING) {
435
- const pending = data.pending;
436
- data.pending = NOTPENDING;
437
- writeSignal(data, pending);
438
- }
439
- }
440
- }, false);
441
- return result;
427
+ return runUpdates(fn, false);
442
428
  }
443
429
  function untrack(fn) {
444
430
  let result,
@@ -521,7 +507,7 @@ function startTransition(fn) {
521
507
  t.done || (t.done = new Promise(res => t.resolve = res));
522
508
  t.running = true;
523
509
  }
524
- batch(fn);
510
+ runUpdates(fn, false);
525
511
  Listener = Owner = null;
526
512
  return t ? t.done : undefined;
527
513
  });
@@ -540,7 +526,6 @@ function devComponent(Comp, props) {
540
526
  });
541
527
  return Comp(props);
542
528
  }), undefined, true);
543
- c.pending = NOTPENDING;
544
529
  c.observers = null;
545
530
  c.observerSlots = null;
546
531
  c.state = 0;
@@ -627,10 +612,12 @@ function enableExternalSource(factory) {
627
612
  function readSignal() {
628
613
  const runningTransition = Transition && Transition.running;
629
614
  if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
630
- const updates = Updates;
631
- Updates = null;
632
- !runningTransition && this.state === STALE || runningTransition && this.tState === STALE ? updateComputation(this) : lookUpstream(this);
633
- Updates = updates;
615
+ if (!runningTransition && this.state === STALE || runningTransition && this.tState === STALE) updateComputation(this);else {
616
+ const updates = Updates;
617
+ Updates = null;
618
+ runUpdates(() => lookUpstream(this), false);
619
+ Updates = updates;
620
+ }
634
621
  }
635
622
  if (Listener) {
636
623
  const sSlot = this.observers ? this.observers.length : 0;
@@ -653,42 +640,35 @@ function readSignal() {
653
640
  return this.value;
654
641
  }
655
642
  function writeSignal(node, value, isComp) {
656
- if (Pending) {
657
- if (node.pending === NOTPENDING) Pending.push(node);
658
- node.pending = value;
659
- return value;
660
- }
661
- if (node.comparator) {
662
- if (Transition && Transition.running && Transition.sources.has(node)) {
663
- if (node.comparator(node.tValue, value)) return value;
664
- } else if (node.comparator(node.value, value)) return value;
665
- }
666
- let TransitionRunning = false;
667
- if (Transition) {
668
- TransitionRunning = Transition.running;
669
- if (TransitionRunning || !isComp && Transition.sources.has(node)) {
670
- Transition.sources.add(node);
671
- node.tValue = value;
672
- }
673
- if (!TransitionRunning) node.value = value;
674
- } else node.value = value;
675
- if (node.observers && node.observers.length) {
676
- runUpdates(() => {
677
- for (let i = 0; i < node.observers.length; i += 1) {
678
- const o = node.observers[i];
679
- if (TransitionRunning && Transition.disposed.has(o)) continue;
680
- if (TransitionRunning && !o.tState || !TransitionRunning && !o.state) {
681
- if (o.pure) Updates.push(o);else Effects.push(o);
682
- if (o.observers) markDownstream(o);
683
- }
684
- if (TransitionRunning) o.tState = STALE;else o.state = STALE;
685
- }
686
- if (Updates.length > 10e5) {
687
- Updates = [];
688
- if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
689
- throw new Error();
643
+ let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
644
+ if (!node.comparator || !node.comparator(current, value)) {
645
+ if (Transition) {
646
+ const TransitionRunning = Transition.running;
647
+ if (TransitionRunning || !isComp && Transition.sources.has(node)) {
648
+ Transition.sources.add(node);
649
+ node.tValue = value;
690
650
  }
691
- }, false);
651
+ if (!TransitionRunning) node.value = value;
652
+ } else node.value = value;
653
+ if (node.observers && node.observers.length) {
654
+ runUpdates(() => {
655
+ for (let i = 0; i < node.observers.length; i += 1) {
656
+ const o = node.observers[i];
657
+ const TransitionRunning = Transition && Transition.running;
658
+ if (TransitionRunning && Transition.disposed.has(o)) continue;
659
+ if (TransitionRunning && !o.tState || !TransitionRunning && !o.state) {
660
+ if (o.pure) Updates.push(o);else Effects.push(o);
661
+ if (o.observers) markDownstream(o);
662
+ }
663
+ if (TransitionRunning) o.tState = STALE;else o.state = STALE;
664
+ }
665
+ if (Updates.length > 10e5) {
666
+ Updates = [];
667
+ if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
668
+ throw new Error();
669
+ }
670
+ }, false);
671
+ }
692
672
  }
693
673
  return value;
694
674
  }
@@ -716,10 +696,11 @@ function runComputation(node, value, time) {
716
696
  try {
717
697
  nextValue = node.fn(value);
718
698
  } catch (err) {
699
+ if (node.pure) Transition && Transition.running ? node.tState = STALE : node.state = STALE;
719
700
  handleError(err);
720
701
  }
721
702
  if (!node.updatedAt || node.updatedAt <= time) {
722
- if (node.observers && node.observers.length) {
703
+ if (node.updatedAt && "observers" in node) {
723
704
  writeSignal(node, nextValue, true);
724
705
  } else if (Transition && Transition.running && node.pure) {
725
706
  Transition.sources.add(node);
@@ -793,7 +774,7 @@ function runTop(node) {
793
774
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
794
775
  const updates = Updates;
795
776
  Updates = null;
796
- lookUpstream(node, ancestors[0]);
777
+ runUpdates(() => lookUpstream(node, ancestors[0]), false);
797
778
  Updates = updates;
798
779
  }
799
780
  }
@@ -836,7 +817,7 @@ function completeUpdates(wait) {
836
817
  delete e.tState;
837
818
  }
838
819
  Transition = null;
839
- batch(() => {
820
+ runUpdates(() => {
840
821
  for (const d of disposed) cleanNode(d);
841
822
  for (const v of sources) {
842
823
  v.value = v.tValue;
@@ -849,15 +830,11 @@ function completeUpdates(wait) {
849
830
  v.tState = 0;
850
831
  }
851
832
  setTransPending(false);
852
- });
853
- }
854
- if (Effects.length) batch(() => {
855
- runEffects(Effects);
856
- Effects = null;
857
- });else {
858
- Effects = null;
859
- globalThis._$afterUpdate && globalThis._$afterUpdate();
833
+ }, false);
860
834
  }
835
+ const e = Effects;
836
+ Effects = null;
837
+ if (e.length) runUpdates(() => runEffects(e), false);else globalThis._$afterUpdate && globalThis._$afterUpdate();
861
838
  if (res) res();
862
839
  }
863
840
  function runQueue(queue) {
@@ -892,9 +869,9 @@ function runUserEffects(queue) {
892
869
  if (!e.user) runTop(e);else queue[userLength++] = e;
893
870
  }
894
871
  if (sharedConfig.context) setHydrateContext();
895
- const resume = queue.length;
872
+ Effects = [];
896
873
  for (i = 0; i < userLength; i++) runTop(queue[i]);
897
- for (i = resume; i < queue.length; i++) runTop(queue[i]);
874
+ if (Effects.length) runUserEffects(Effects);
898
875
  }
899
876
  function lookUpstream(node, ignore) {
900
877
  const runningTransition = Transition && Transition.running;
@@ -964,7 +941,12 @@ function reset(node, top) {
964
941
  for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
965
942
  }
966
943
  }
944
+ function castError(err) {
945
+ if (err instanceof Error || typeof err === "string") return err;
946
+ return new Error("Unknown error");
947
+ }
967
948
  function handleError(err) {
949
+ err = castError(err);
968
950
  const fns = ERROR && lookup(Owner, ERROR);
969
951
  if (!fns) throw err;
970
952
  for (const f of fns) f(err);
@@ -1033,7 +1015,7 @@ function observable(input) {
1033
1015
  };
1034
1016
  }
1035
1017
  const dispose = createRoot(disposer => {
1036
- createComputed(() => {
1018
+ createEffect(() => {
1037
1019
  const v = input();
1038
1020
  untrack(() => handler(v));
1039
1021
  });
@@ -1425,25 +1407,25 @@ function Match(props) {
1425
1407
  return props;
1426
1408
  }
1427
1409
  let Errors;
1428
- const NoErrors = {};
1429
1410
  function resetErrorBoundaries() {
1430
- Errors && [...Errors].forEach(fn => fn(NoErrors));
1411
+ Errors && [...Errors].forEach(fn => fn());
1431
1412
  }
1432
1413
  function ErrorBoundary(props) {
1433
- let err = NoErrors;
1434
- if (sharedConfig.context && sharedConfig.load) {
1435
- err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
1436
- }
1414
+ let err;
1415
+ let v;
1416
+ if (sharedConfig.context && sharedConfig.load && (v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count))) err = v[0];
1437
1417
  const [errored, setErrored] = createSignal(err);
1438
1418
  Errors || (Errors = new Set());
1439
1419
  Errors.add(setErrored);
1440
1420
  onCleanup(() => Errors.delete(setErrored));
1441
1421
  return createMemo(() => {
1442
1422
  let e;
1443
- if ((e = errored()) !== NoErrors) {
1423
+ if (e = errored()) {
1444
1424
  const f = props.fallback;
1445
1425
  if ((typeof f !== "function" || f.length == 0)) console.error(e);
1446
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
1426
+ const res = typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f;
1427
+ onError(setErrored);
1428
+ return res;
1447
1429
  }
1448
1430
  onError(setErrored);
1449
1431
  return props.children;
@@ -1538,21 +1520,24 @@ function Suspense(props) {
1538
1520
  owner = getOwner();
1539
1521
  if (sharedConfig.context && sharedConfig.load) {
1540
1522
  const key = sharedConfig.context.id + sharedConfig.context.count;
1541
- p = sharedConfig.load(key);
1542
- if (p) {
1523
+ let ref = sharedConfig.load(key);
1524
+ if (ref && (p = ref[0]) && p !== "$$f") {
1543
1525
  if (typeof p !== "object" || !("then" in p)) p = Promise.resolve(p);
1544
1526
  const [s, set] = createSignal(undefined, {
1545
1527
  equals: false
1546
1528
  });
1547
1529
  flicker = s;
1548
1530
  p.then(err => {
1549
- if ((error = err) || sharedConfig.done) return set();
1531
+ if (err || sharedConfig.done) {
1532
+ err && (error = err);
1533
+ return set();
1534
+ }
1550
1535
  sharedConfig.gather(key);
1551
1536
  setHydrateContext(ctx);
1552
1537
  set();
1553
1538
  setHydrateContext();
1554
1539
  });
1555
- } else if (p === null) sharedConfig.gather(key);
1540
+ }
1556
1541
  }
1557
1542
  const listContext = useContext(SuspenseListContext);
1558
1543
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
@@ -1568,14 +1553,14 @@ function Suspense(props) {
1568
1553
  flicker();
1569
1554
  return flicker = undefined;
1570
1555
  }
1571
- if (ctx && p === undefined) setHydrateContext();
1556
+ if (ctx && p === "$$f") setHydrateContext();
1572
1557
  const rendered = createMemo(() => props.children);
1573
1558
  return createMemo(() => {
1574
1559
  const inFallback = store.inFallback(),
1575
1560
  visibleContent = showContent ? showContent() : true,
1576
1561
  visibleFallback = showFallback ? showFallback() : true;
1577
1562
  dispose && dispose();
1578
- if ((!inFallback || p !== undefined) && visibleContent) {
1563
+ if ((!inFallback || p && p !== "$$f") && visibleContent) {
1579
1564
  store.resolved = true;
1580
1565
  ctx = p = undefined;
1581
1566
  resumeEffects(store.effects);