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.js CHANGED
@@ -134,7 +134,6 @@ const signalOptions = {
134
134
  };
135
135
  let ERROR = null;
136
136
  let runEffects = runQueue;
137
- const NOTPENDING = {};
138
137
  const STALE = 1;
139
138
  const PENDING = 2;
140
139
  const UNOWNED = {
@@ -143,13 +142,13 @@ const UNOWNED = {
143
142
  context: null,
144
143
  owner: null
145
144
  };
145
+ const NO_INIT = {};
146
146
  const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
147
147
  var Owner = null;
148
148
  let Transition = null;
149
149
  let Scheduler = null;
150
150
  let ExternalSourceFactory = null;
151
151
  let Listener = null;
152
- let Pending = null;
153
152
  let Updates = null;
154
153
  let Effects = null;
155
154
  let ExecCount = 0;
@@ -186,13 +185,12 @@ function createSignal(value, options) {
186
185
  value,
187
186
  observers: null,
188
187
  observerSlots: null,
189
- pending: NOTPENDING,
190
188
  comparator: options.equals || undefined
191
189
  };
192
190
  if (!options.internal) s.name = registerGraph(options.name || hashValue(value), s);
193
191
  const setter = value => {
194
192
  if (typeof value === "function") {
195
- 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);
193
+ if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value);
196
194
  }
197
195
  return writeSignal(s, value);
198
196
  };
@@ -231,7 +229,6 @@ function createReaction(onInvalidate, options) {
231
229
  function createMemo(fn, value, options) {
232
230
  options = options ? Object.assign({}, signalOptions, options) : signalOptions;
233
231
  const c = createComputation(fn, value, true, 0, options );
234
- c.pending = NOTPENDING;
235
232
  c.observers = null;
236
233
  c.observerSlots = null;
237
234
  c.comparator = options.equals || undefined;
@@ -241,46 +238,46 @@ function createMemo(fn, value, options) {
241
238
  } else updateComputation(c);
242
239
  return readSignal.bind(c);
243
240
  }
244
- function createResource(source, fetcher, options) {
245
- if (arguments.length === 2) {
246
- if (typeof fetcher === "object") {
247
- options = fetcher;
248
- fetcher = source;
249
- source = true;
250
- }
251
- } else if (arguments.length === 1) {
252
- fetcher = source;
241
+ function createResource(pSource, pFetcher, pOptions) {
242
+ let source;
243
+ let fetcher;
244
+ let options;
245
+ if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) {
253
246
  source = true;
247
+ fetcher = pSource;
248
+ options = pFetcher || {};
249
+ } else {
250
+ source = pSource;
251
+ fetcher = pFetcher;
252
+ options = pOptions || {};
254
253
  }
255
- options || (options = {});
256
- const contexts = new Set(),
257
- [value, setValue] = createSignal(options.initialValue),
258
- [track, trigger] = createSignal(undefined, {
259
- equals: false
260
- }),
261
- [loading, setLoading] = createSignal(false),
262
- [error, setError] = createSignal();
263
254
  let err = undefined,
264
255
  pr = null,
265
- initP = null,
256
+ initP = NO_INIT,
266
257
  id = null,
267
258
  loadedUnderTransition = false,
268
259
  scheduled = false,
269
260
  resolved = ("initialValue" in options),
270
261
  dynamic = typeof source === "function" && createMemo(source);
262
+ const contexts = new Set(),
263
+ [value, setValue] = options.store ? options.store(options.initialValue) : createSignal(options.initialValue),
264
+ [track, trigger] = createSignal(undefined, {
265
+ equals: false
266
+ }),
267
+ [state, setState] = createSignal(resolved ? "ready" : "unresolved");
271
268
  if (sharedConfig.context) {
272
269
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
273
- if (sharedConfig.load) initP = sharedConfig.load(id);
270
+ let v;
271
+ if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
274
272
  }
275
- function loadEnd(p, v, e, key) {
273
+ function loadEnd(p, v, success, key) {
276
274
  if (pr === p) {
277
275
  pr = null;
278
276
  resolved = true;
279
- if (initP && (p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
277
+ if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
280
278
  value: v
281
279
  }));
282
- initP = null;
283
- setError(err = e);
280
+ initP = NO_INIT;
284
281
  if (Transition && p && loadedUnderTransition) {
285
282
  Transition.promises.delete(p);
286
283
  loadedUnderTransition = false;
@@ -290,19 +287,20 @@ function createResource(source, fetcher, options) {
290
287
  Effects.push.apply(Effects, Transition.effects);
291
288
  Transition.effects = [];
292
289
  }
293
- completeLoad(v);
290
+ completeLoad(v, success);
294
291
  }, false);
295
- } else completeLoad(v);
292
+ } else completeLoad(v, success);
296
293
  }
297
294
  return v;
298
295
  }
299
- function completeLoad(v) {
300
- batch(() => {
296
+ function completeLoad(v, success) {
297
+ !success && (err = castError(v));
298
+ runUpdates(() => {
301
299
  setValue(() => v);
302
- setLoading(false);
300
+ setState(success ? "ready" : "error");
303
301
  for (const c of contexts.keys()) c.decrement();
304
302
  contexts.clear();
305
- });
303
+ }, false);
306
304
  }
307
305
  function read() {
308
306
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
@@ -322,48 +320,54 @@ function createResource(source, fetcher, options) {
322
320
  return v;
323
321
  }
324
322
  function load(refetching = true) {
325
- if (refetching && scheduled) return;
323
+ if (refetching !== false && scheduled) return;
326
324
  scheduled = false;
327
- setError(err = undefined);
325
+ err = undefined;
328
326
  const lookup = dynamic ? dynamic() : source;
329
327
  loadedUnderTransition = Transition && Transition.running;
330
328
  if (lookup == null || lookup === false) {
331
- loadEnd(pr, untrack(value));
329
+ loadEnd(pr, untrack(value), true);
332
330
  return;
333
331
  }
334
332
  if (Transition && pr) Transition.promises.delete(pr);
335
- const p = initP || untrack(() => fetcher(lookup, {
333
+ const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, {
336
334
  value: value(),
337
335
  refetching
338
336
  }));
339
337
  if (typeof p !== "object" || !("then" in p)) {
340
- loadEnd(pr, p);
338
+ loadEnd(pr, p, true);
341
339
  return p;
342
340
  }
343
341
  pr = p;
344
342
  scheduled = true;
345
343
  queueMicrotask(() => scheduled = false);
346
- batch(() => {
347
- setLoading(true);
344
+ runUpdates(() => {
345
+ setState(resolved ? "refreshing" : "pending");
348
346
  trigger();
349
- });
350
- return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, e, e));
347
+ }, false);
348
+ return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
351
349
  }
352
350
  Object.defineProperties(read, {
351
+ state: {
352
+ get() {
353
+ return state();
354
+ }
355
+ },
353
356
  loading: {
354
357
  get() {
355
- return loading();
358
+ const s = state();
359
+ return s === "pending" || s === "refreshing";
356
360
  }
357
361
  },
358
362
  error: {
359
363
  get() {
360
- return error();
364
+ return state() === "error" ? err : undefined;
361
365
  }
362
366
  },
363
367
  latest: {
364
368
  get() {
365
369
  if (!resolved) return read();
366
- if (err) throw err;
370
+ if (state() === "error") throw err;
367
371
  return value();
368
372
  }
369
373
  }
@@ -416,25 +420,7 @@ function createSelector(source, fn = equalFn, options) {
416
420
  };
417
421
  }
418
422
  function batch(fn) {
419
- if (Pending) return fn();
420
- let result;
421
- const q = Pending = [];
422
- try {
423
- result = fn();
424
- } finally {
425
- Pending = null;
426
- }
427
- runUpdates(() => {
428
- for (let i = 0; i < q.length; i += 1) {
429
- const data = q[i];
430
- if (data.pending !== NOTPENDING) {
431
- const pending = data.pending;
432
- data.pending = NOTPENDING;
433
- writeSignal(data, pending);
434
- }
435
- }
436
- }, false);
437
- return result;
423
+ return runUpdates(fn, false);
438
424
  }
439
425
  function untrack(fn) {
440
426
  let result,
@@ -517,7 +503,7 @@ function startTransition(fn) {
517
503
  t.done || (t.done = new Promise(res => t.resolve = res));
518
504
  t.running = true;
519
505
  }
520
- batch(fn);
506
+ runUpdates(fn, false);
521
507
  Listener = Owner = null;
522
508
  return t ? t.done : undefined;
523
509
  });
@@ -536,7 +522,6 @@ function devComponent(Comp, props) {
536
522
  });
537
523
  return Comp(props);
538
524
  }), undefined, true);
539
- c.pending = NOTPENDING;
540
525
  c.observers = null;
541
526
  c.observerSlots = null;
542
527
  c.state = 0;
@@ -623,10 +608,12 @@ function enableExternalSource(factory) {
623
608
  function readSignal() {
624
609
  const runningTransition = Transition && Transition.running;
625
610
  if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
626
- const updates = Updates;
627
- Updates = null;
628
- !runningTransition && this.state === STALE || runningTransition && this.tState === STALE ? updateComputation(this) : lookUpstream(this);
629
- Updates = updates;
611
+ if (!runningTransition && this.state === STALE || runningTransition && this.tState === STALE) updateComputation(this);else {
612
+ const updates = Updates;
613
+ Updates = null;
614
+ runUpdates(() => lookUpstream(this), false);
615
+ Updates = updates;
616
+ }
630
617
  }
631
618
  if (Listener) {
632
619
  const sSlot = this.observers ? this.observers.length : 0;
@@ -649,42 +636,35 @@ function readSignal() {
649
636
  return this.value;
650
637
  }
651
638
  function writeSignal(node, value, isComp) {
652
- if (Pending) {
653
- if (node.pending === NOTPENDING) Pending.push(node);
654
- node.pending = value;
655
- return value;
656
- }
657
- if (node.comparator) {
658
- if (Transition && Transition.running && Transition.sources.has(node)) {
659
- if (node.comparator(node.tValue, value)) return value;
660
- } else if (node.comparator(node.value, value)) return value;
661
- }
662
- let TransitionRunning = false;
663
- if (Transition) {
664
- TransitionRunning = Transition.running;
665
- if (TransitionRunning || !isComp && Transition.sources.has(node)) {
666
- Transition.sources.add(node);
667
- node.tValue = value;
668
- }
669
- if (!TransitionRunning) node.value = value;
670
- } else node.value = value;
671
- if (node.observers && node.observers.length) {
672
- runUpdates(() => {
673
- for (let i = 0; i < node.observers.length; i += 1) {
674
- const o = node.observers[i];
675
- if (TransitionRunning && Transition.disposed.has(o)) continue;
676
- if (TransitionRunning && !o.tState || !TransitionRunning && !o.state) {
677
- if (o.pure) Updates.push(o);else Effects.push(o);
678
- if (o.observers) markDownstream(o);
679
- }
680
- if (TransitionRunning) o.tState = STALE;else o.state = STALE;
681
- }
682
- if (Updates.length > 10e5) {
683
- Updates = [];
684
- if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
685
- throw new Error();
639
+ let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
640
+ if (!node.comparator || !node.comparator(current, value)) {
641
+ if (Transition) {
642
+ const TransitionRunning = Transition.running;
643
+ if (TransitionRunning || !isComp && Transition.sources.has(node)) {
644
+ Transition.sources.add(node);
645
+ node.tValue = value;
686
646
  }
687
- }, false);
647
+ if (!TransitionRunning) node.value = value;
648
+ } else node.value = value;
649
+ if (node.observers && node.observers.length) {
650
+ runUpdates(() => {
651
+ for (let i = 0; i < node.observers.length; i += 1) {
652
+ const o = node.observers[i];
653
+ const TransitionRunning = Transition && Transition.running;
654
+ if (TransitionRunning && Transition.disposed.has(o)) continue;
655
+ if (TransitionRunning && !o.tState || !TransitionRunning && !o.state) {
656
+ if (o.pure) Updates.push(o);else Effects.push(o);
657
+ if (o.observers) markDownstream(o);
658
+ }
659
+ if (TransitionRunning) o.tState = STALE;else o.state = STALE;
660
+ }
661
+ if (Updates.length > 10e5) {
662
+ Updates = [];
663
+ if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
664
+ throw new Error();
665
+ }
666
+ }, false);
667
+ }
688
668
  }
689
669
  return value;
690
670
  }
@@ -712,10 +692,11 @@ function runComputation(node, value, time) {
712
692
  try {
713
693
  nextValue = node.fn(value);
714
694
  } catch (err) {
695
+ if (node.pure) Transition && Transition.running ? node.tState = STALE : node.state = STALE;
715
696
  handleError(err);
716
697
  }
717
698
  if (!node.updatedAt || node.updatedAt <= time) {
718
- if (node.observers && node.observers.length) {
699
+ if (node.updatedAt && "observers" in node) {
719
700
  writeSignal(node, nextValue, true);
720
701
  } else if (Transition && Transition.running && node.pure) {
721
702
  Transition.sources.add(node);
@@ -789,7 +770,7 @@ function runTop(node) {
789
770
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
790
771
  const updates = Updates;
791
772
  Updates = null;
792
- lookUpstream(node, ancestors[0]);
773
+ runUpdates(() => lookUpstream(node, ancestors[0]), false);
793
774
  Updates = updates;
794
775
  }
795
776
  }
@@ -832,7 +813,7 @@ function completeUpdates(wait) {
832
813
  delete e.tState;
833
814
  }
834
815
  Transition = null;
835
- batch(() => {
816
+ runUpdates(() => {
836
817
  for (const d of disposed) cleanNode(d);
837
818
  for (const v of sources) {
838
819
  v.value = v.tValue;
@@ -845,15 +826,11 @@ function completeUpdates(wait) {
845
826
  v.tState = 0;
846
827
  }
847
828
  setTransPending(false);
848
- });
849
- }
850
- if (Effects.length) batch(() => {
851
- runEffects(Effects);
852
- Effects = null;
853
- });else {
854
- Effects = null;
855
- globalThis._$afterUpdate && globalThis._$afterUpdate();
829
+ }, false);
856
830
  }
831
+ const e = Effects;
832
+ Effects = null;
833
+ if (e.length) runUpdates(() => runEffects(e), false);else globalThis._$afterUpdate && globalThis._$afterUpdate();
857
834
  if (res) res();
858
835
  }
859
836
  function runQueue(queue) {
@@ -888,9 +865,9 @@ function runUserEffects(queue) {
888
865
  if (!e.user) runTop(e);else queue[userLength++] = e;
889
866
  }
890
867
  if (sharedConfig.context) setHydrateContext();
891
- const resume = queue.length;
868
+ Effects = [];
892
869
  for (i = 0; i < userLength; i++) runTop(queue[i]);
893
- for (i = resume; i < queue.length; i++) runTop(queue[i]);
870
+ if (Effects.length) runUserEffects(Effects);
894
871
  }
895
872
  function lookUpstream(node, ignore) {
896
873
  const runningTransition = Transition && Transition.running;
@@ -960,7 +937,12 @@ function reset(node, top) {
960
937
  for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
961
938
  }
962
939
  }
940
+ function castError(err) {
941
+ if (err instanceof Error || typeof err === "string") return err;
942
+ return new Error("Unknown error");
943
+ }
963
944
  function handleError(err) {
945
+ err = castError(err);
964
946
  const fns = ERROR && lookup(Owner, ERROR);
965
947
  if (!fns) throw err;
966
948
  for (const f of fns) f(err);
@@ -1029,7 +1011,7 @@ function observable(input) {
1029
1011
  };
1030
1012
  }
1031
1013
  const dispose = createRoot(disposer => {
1032
- createComputed(() => {
1014
+ createEffect(() => {
1033
1015
  const v = input();
1034
1016
  untrack(() => handler(v));
1035
1017
  });
@@ -1421,25 +1403,25 @@ function Match(props) {
1421
1403
  return props;
1422
1404
  }
1423
1405
  let Errors;
1424
- const NoErrors = {};
1425
1406
  function resetErrorBoundaries() {
1426
- Errors && [...Errors].forEach(fn => fn(NoErrors));
1407
+ Errors && [...Errors].forEach(fn => fn());
1427
1408
  }
1428
1409
  function ErrorBoundary(props) {
1429
- let err = NoErrors;
1430
- if (sharedConfig.context && sharedConfig.load) {
1431
- err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count) || NoErrors;
1432
- }
1410
+ let err;
1411
+ let v;
1412
+ if (sharedConfig.context && sharedConfig.load && (v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count))) err = v[0];
1433
1413
  const [errored, setErrored] = createSignal(err);
1434
1414
  Errors || (Errors = new Set());
1435
1415
  Errors.add(setErrored);
1436
1416
  onCleanup(() => Errors.delete(setErrored));
1437
1417
  return createMemo(() => {
1438
1418
  let e;
1439
- if ((e = errored()) !== NoErrors) {
1419
+ if (e = errored()) {
1440
1420
  const f = props.fallback;
1441
1421
  if ((typeof f !== "function" || f.length == 0)) console.error(e);
1442
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(NoErrors))) : f;
1422
+ const res = typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f;
1423
+ onError(setErrored);
1424
+ return res;
1443
1425
  }
1444
1426
  onError(setErrored);
1445
1427
  return props.children;
@@ -1534,21 +1516,24 @@ function Suspense(props) {
1534
1516
  owner = getOwner();
1535
1517
  if (sharedConfig.context && sharedConfig.load) {
1536
1518
  const key = sharedConfig.context.id + sharedConfig.context.count;
1537
- p = sharedConfig.load(key);
1538
- if (p) {
1519
+ let ref = sharedConfig.load(key);
1520
+ if (ref && (p = ref[0]) && p !== "$$f") {
1539
1521
  if (typeof p !== "object" || !("then" in p)) p = Promise.resolve(p);
1540
1522
  const [s, set] = createSignal(undefined, {
1541
1523
  equals: false
1542
1524
  });
1543
1525
  flicker = s;
1544
1526
  p.then(err => {
1545
- if ((error = err) || sharedConfig.done) return set();
1527
+ if (err || sharedConfig.done) {
1528
+ err && (error = err);
1529
+ return set();
1530
+ }
1546
1531
  sharedConfig.gather(key);
1547
1532
  setHydrateContext(ctx);
1548
1533
  set();
1549
1534
  setHydrateContext();
1550
1535
  });
1551
- } else if (p === null) sharedConfig.gather(key);
1536
+ }
1552
1537
  }
1553
1538
  const listContext = useContext(SuspenseListContext);
1554
1539
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
@@ -1564,14 +1549,14 @@ function Suspense(props) {
1564
1549
  flicker();
1565
1550
  return flicker = undefined;
1566
1551
  }
1567
- if (ctx && p === undefined) setHydrateContext();
1552
+ if (ctx && p === "$$f") setHydrateContext();
1568
1553
  const rendered = createMemo(() => props.children);
1569
1554
  return createMemo(() => {
1570
1555
  const inFallback = store.inFallback(),
1571
1556
  visibleContent = showContent ? showContent() : true,
1572
1557
  visibleFallback = showFallback ? showFallback() : true;
1573
1558
  dispose && dispose();
1574
- if ((!inFallback || p !== undefined) && visibleContent) {
1559
+ if ((!inFallback || p && p !== "$$f") && visibleContent) {
1575
1560
  store.resolved = true;
1576
1561
  ctx = p = undefined;
1577
1562
  resumeEffects(store.effects);