solid-js 1.9.6 → 1.9.7

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 (44) hide show
  1. package/dist/dev.cjs +18 -8
  2. package/dist/dev.js +326 -557
  3. package/dist/server.js +81 -178
  4. package/dist/solid.cjs +18 -8
  5. package/dist/solid.js +282 -486
  6. package/h/dist/h.js +9 -40
  7. package/h/jsx-runtime/dist/jsx.js +1 -1
  8. package/h/jsx-runtime/types/index.d.ts +8 -11
  9. package/h/types/hyperscript.d.ts +11 -11
  10. package/html/dist/html.js +94 -219
  11. package/html/types/lit.d.ts +33 -52
  12. package/package.json +3 -3
  13. package/store/dist/dev.js +43 -123
  14. package/store/dist/server.js +8 -20
  15. package/store/dist/store.js +40 -114
  16. package/store/types/index.d.ts +7 -21
  17. package/store/types/modifiers.d.ts +3 -6
  18. package/store/types/mutable.d.ts +2 -5
  19. package/store/types/server.d.ts +5 -25
  20. package/store/types/store.d.ts +61 -218
  21. package/types/index.d.ts +11 -78
  22. package/types/reactive/array.d.ts +4 -12
  23. package/types/reactive/observable.d.ts +16 -22
  24. package/types/reactive/scheduler.d.ts +6 -9
  25. package/types/reactive/signal.d.ts +145 -236
  26. package/types/render/Suspense.d.ts +5 -5
  27. package/types/render/component.d.ts +37 -73
  28. package/types/render/flow.d.ts +31 -43
  29. package/types/render/hydration.d.ts +15 -15
  30. package/types/server/index.d.ts +2 -57
  31. package/types/server/reactive.d.ts +45 -76
  32. package/types/server/rendering.d.ts +98 -169
  33. package/universal/dist/dev.js +12 -28
  34. package/universal/dist/universal.js +12 -28
  35. package/universal/types/index.d.ts +1 -3
  36. package/universal/types/universal.d.ts +1 -0
  37. package/web/dist/dev.js +90 -644
  38. package/web/dist/server.cjs +1 -1
  39. package/web/dist/server.js +110 -647
  40. package/web/dist/web.js +88 -632
  41. package/web/storage/dist/storage.js +3 -3
  42. package/web/types/core.d.ts +1 -9
  43. package/web/types/index.d.ts +11 -31
  44. package/web/types/server-mock.d.ts +32 -47
package/dist/server.js CHANGED
@@ -17,7 +17,7 @@ function handleError(err, owner = Owner) {
17
17
  try {
18
18
  for (const f of fns) f(error);
19
19
  } catch (e) {
20
- handleError(e, (owner && owner.owner) || null);
20
+ handleError(e, owner && owner.owner || null);
21
21
  }
22
22
  }
23
23
  const UNOWNED = {
@@ -35,23 +35,19 @@ function createOwner() {
35
35
  cleanups: null
36
36
  };
37
37
  if (Owner) {
38
- if (!Owner.owned) Owner.owned = [o];
39
- else Owner.owned.push(o);
38
+ if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o);
40
39
  }
41
40
  return o;
42
41
  }
43
42
  function createRoot(fn, detachedOwner) {
44
43
  const owner = Owner,
45
44
  current = detachedOwner === undefined ? owner : detachedOwner,
46
- root =
47
- fn.length === 0
48
- ? UNOWNED
49
- : {
50
- context: current ? current.context : null,
51
- owner: current,
52
- owned: null,
53
- cleanups: null
54
- };
45
+ root = fn.length === 0 ? UNOWNED : {
46
+ context: current ? current.context : null,
47
+ owner: current,
48
+ owned: null,
49
+ cleanups: null
50
+ };
55
51
  Owner = root;
56
52
  let result;
57
53
  try {
@@ -64,12 +60,9 @@ function createRoot(fn, detachedOwner) {
64
60
  return result;
65
61
  }
66
62
  function createSignal(value, options) {
67
- return [
68
- () => value,
69
- v => {
70
- return (value = typeof v === "function" ? v(value) : v);
71
- }
72
- ];
63
+ return [() => value, v => {
64
+ return value = typeof v === "function" ? v(value) : v;
65
+ }];
73
66
  }
74
67
  function createComputed(fn, value) {
75
68
  Owner = createOwner();
@@ -126,8 +119,7 @@ function on(deps, fn, options = {}) {
126
119
  function onMount(fn) {}
127
120
  function onCleanup(fn) {
128
121
  if (Owner) {
129
- if (!Owner.cleanups) Owner.cleanups = [fn];
130
- else Owner.cleanups.push(fn);
122
+ if (!Owner.cleanups) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
131
123
  }
132
124
  return fn;
133
125
  }
@@ -168,9 +160,7 @@ function createContext(defaultValue) {
168
160
  };
169
161
  }
170
162
  function useContext(context) {
171
- return Owner && Owner.context && Owner.context[context.id] !== undefined
172
- ? Owner.context[context.id]
173
- : context.defaultValue;
163
+ return Owner && Owner.context && Owner.context[context.id] !== undefined ? Owner.context[context.id] : context.defaultValue;
174
164
  }
175
165
  function getOwner() {
176
166
  return Owner;
@@ -247,8 +237,7 @@ function observable(input) {
247
237
  if (!(observer instanceof Object) || observer == null) {
248
238
  throw new TypeError("Expected the observer to be an object.");
249
239
  }
250
- const handler =
251
- typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
240
+ const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
252
241
  if (!handler) {
253
242
  return {
254
243
  unsubscribe() {}
@@ -277,7 +266,7 @@ function from(producer) {
277
266
  const [s, set] = createSignal(undefined);
278
267
  if ("subscribe" in producer) {
279
268
  const unsub = producer.subscribe(v => set(() => v));
280
- onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
269
+ onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
281
270
  } else {
282
271
  const clean = producer(set);
283
272
  onCleanup(clean);
@@ -348,13 +337,12 @@ function escape(s, attr) {
348
337
  left = iDelim + 1;
349
338
  iDelim = s.indexOf(delim, left);
350
339
  } while (iDelim >= 0);
351
- } else
352
- while (iAmp >= 0) {
353
- if (left < iAmp) out += s.substring(left, iAmp);
354
- out += "&amp;";
355
- left = iAmp + 1;
356
- iAmp = s.indexOf("&", left);
357
- }
340
+ } else while (iAmp >= 0) {
341
+ if (left < iAmp) out += s.substring(left, iAmp);
342
+ out += "&amp;";
343
+ left = iAmp + 1;
344
+ iAmp = s.indexOf("&", left);
345
+ }
358
346
  return left < s.length ? out + s.substring(left) : out;
359
347
  }
360
348
  function resolveSSRNode(node) {
@@ -366,7 +354,7 @@ function resolveSSRNode(node) {
366
354
  let mapped = "";
367
355
  for (let i = 0, len = node.length; i < len; i++) {
368
356
  if (typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`;
369
- mapped += resolveSSRNode((prev = node[i]));
357
+ mapped += resolveSSRNode(prev = node[i]);
370
358
  }
371
359
  return mapped;
372
360
  }
@@ -381,8 +369,7 @@ const sharedConfig = {
381
369
  return getContextId(this.context.count);
382
370
  },
383
371
  getNextContextId() {
384
- if (!this.context)
385
- throw new Error(`getNextContextId cannot be used under non-hydrating context`);
372
+ if (!this.context) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
386
373
  return getContextId(this.context.count++);
387
374
  }
388
375
  };
@@ -395,13 +382,11 @@ function setHydrateContext(context) {
395
382
  sharedConfig.context = context;
396
383
  }
397
384
  function nextHydrateContext() {
398
- return sharedConfig.context
399
- ? {
400
- ...sharedConfig.context,
401
- id: sharedConfig.getNextContextId(),
402
- count: 0
403
- }
404
- : undefined;
385
+ return sharedConfig.context ? {
386
+ ...sharedConfig.context,
387
+ id: sharedConfig.getNextContextId(),
388
+ count: 0
389
+ } : undefined;
405
390
  }
406
391
  function createUniqueId() {
407
392
  return sharedConfig.getNextContextId();
@@ -476,11 +461,7 @@ function Index(props) {
476
461
  }
477
462
  function Show(props) {
478
463
  let c;
479
- return props.when
480
- ? typeof (c = props.children) === "function"
481
- ? c(props.keyed ? props.when : () => props.when)
482
- : c
483
- : props.fallback || "";
464
+ return props.when ? typeof (c = props.children) === "function" ? c(props.keyed ? props.when : () => props.when) : c : props.fallback || "";
484
465
  }
485
466
  function Switch(props) {
486
467
  let conditions = props.children;
@@ -517,14 +498,11 @@ function ErrorBoundary(props) {
517
498
  }
518
499
  createMemo(() => {
519
500
  clean = Owner;
520
- return catchError(
521
- () => (res = props.children),
522
- err => {
523
- error = err;
524
- !sync && ctx.replace("e" + id, displayFallback);
525
- sync = true;
526
- }
527
- );
501
+ return catchError(() => res = props.children, err => {
502
+ error = err;
503
+ !sync && ctx.replace("e" + id, displayFallback);
504
+ sync = true;
505
+ });
528
506
  });
529
507
  if (error) return displayFallback();
530
508
  sync = false;
@@ -549,17 +527,13 @@ function createResource(source, fetcher, options = {}) {
549
527
  if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
550
528
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
551
529
  if (resource.ref) {
552
- if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error)
553
- resource.ref[1].refetch();
530
+ if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
554
531
  return resource.ref;
555
532
  }
556
533
  }
557
534
  const read = () => {
558
535
  if (error) throw error;
559
- const resolved =
560
- options.ssrLoadFrom !== "initial" &&
561
- sharedConfig.context.async &&
562
- "data" in sharedConfig.context.resources[id];
536
+ const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
563
537
  if (!resolved && resourceContext) resourceContext.push(id);
564
538
  if (!resolved && read.loading) {
565
539
  const ctx = useContext(SuspenseContext);
@@ -580,7 +554,7 @@ function createResource(source, fetcher, options = {}) {
580
554
  });
581
555
  function load() {
582
556
  const ctx = sharedConfig.context;
583
- if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source));
557
+ if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
584
558
  if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
585
559
  value = ctx.resources[id].data;
586
560
  return;
@@ -602,23 +576,21 @@ function createResource(source, fetcher, options = {}) {
602
576
  if (p != undefined && typeof p === "object" && "then" in p) {
603
577
  read.loading = true;
604
578
  read.state = "pending";
605
- p = p
606
- .then(res => {
607
- read.loading = false;
608
- read.state = "ready";
609
- ctx.resources[id].data = res;
610
- p = null;
611
- notifySuspense(contexts);
612
- return res;
613
- })
614
- .catch(err => {
615
- read.loading = false;
616
- read.state = "errored";
617
- read.error = error = castError(err);
618
- p = null;
619
- notifySuspense(contexts);
620
- throw error;
621
- });
579
+ p = p.then(res => {
580
+ read.loading = false;
581
+ read.state = "ready";
582
+ ctx.resources[id].data = res;
583
+ p = null;
584
+ notifySuspense(contexts);
585
+ return res;
586
+ }).catch(err => {
587
+ read.loading = false;
588
+ read.state = "errored";
589
+ read.error = error = castError(err);
590
+ p = null;
591
+ notifySuspense(contexts);
592
+ throw error;
593
+ });
622
594
  if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
623
595
  return p;
624
596
  }
@@ -628,20 +600,17 @@ function createResource(source, fetcher, options = {}) {
628
600
  return ctx.resources[id].data;
629
601
  }
630
602
  if (options.ssrLoadFrom !== "initial") load();
631
- return (resource.ref = [
632
- read,
633
- {
634
- refetch: load,
635
- mutate: v => (value = v)
636
- }
637
- ]);
603
+ return resource.ref = [read, {
604
+ refetch: load,
605
+ mutate: v => value = v
606
+ }];
638
607
  }
639
608
  function lazy(fn) {
640
609
  let p;
641
610
  let load = id => {
642
611
  if (!p) {
643
612
  p = fn();
644
- p.then(mod => (p.resolved = mod.default));
613
+ p.then(mod => p.resolved = mod.default);
645
614
  if (id) sharedConfig.context.lazy[id] = p;
646
615
  }
647
616
  return p;
@@ -650,8 +619,7 @@ function lazy(fn) {
650
619
  const wrap = props => {
651
620
  const id = sharedConfig.context.id;
652
621
  let ref = sharedConfig.context.lazy[id];
653
- if (ref) p = ref;
654
- else load(id);
622
+ if (ref) p = ref;else load(id);
655
623
  if (p.resolved) return p.resolved(props);
656
624
  const ctx = useContext(SuspenseContext);
657
625
  const track = {
@@ -663,12 +631,10 @@ function lazy(fn) {
663
631
  contexts.add(ctx);
664
632
  }
665
633
  if (sharedConfig.context.async) {
666
- sharedConfig.context.block(
667
- p.then(() => {
668
- track.loading = false;
669
- notifySuspense(contexts);
670
- })
671
- );
634
+ sharedConfig.context.block(p.then(() => {
635
+ track.loading = false;
636
+ notifySuspense(contexts);
637
+ }));
672
638
  }
673
639
  return "";
674
640
  };
@@ -696,12 +662,9 @@ function startTransition(fn) {
696
662
  fn();
697
663
  }
698
664
  function useTransition() {
699
- return [
700
- () => false,
701
- fn => {
702
- fn();
703
- }
704
- ];
665
+ return [() => false, fn => {
666
+ fn();
667
+ }];
705
668
  }
706
669
  function SuspenseList(props) {
707
670
  return props.children;
@@ -711,17 +674,15 @@ function Suspense(props) {
711
674
  const ctx = sharedConfig.context;
712
675
  const id = sharedConfig.getContextId();
713
676
  const o = createOwner();
714
- const value =
715
- ctx.suspense[id] ||
716
- (ctx.suspense[id] = {
717
- resources: new Map(),
718
- completed: () => {
719
- const res = runSuspense();
720
- if (suspenseComplete(value)) {
721
- done(resolveSSRNode(escape(res)));
722
- }
677
+ const value = ctx.suspense[id] || (ctx.suspense[id] = {
678
+ resources: new Map(),
679
+ completed: () => {
680
+ const res = runSuspense();
681
+ if (suspenseComplete(value)) {
682
+ done(resolveSSRNode(escape(res)));
723
683
  }
724
- });
684
+ }
685
+ });
725
686
  function suspenseError(err) {
726
687
  if (!done || !done(undefined, err)) {
727
688
  runWithOwner(o.owner, () => {
@@ -735,14 +696,12 @@ function Suspense(props) {
735
696
  count: 0
736
697
  });
737
698
  cleanNode(o);
738
- return runWithOwner(o, () =>
739
- createComponent(SuspenseContext.Provider, {
740
- value,
741
- get children() {
742
- return catchError(() => props.children, suspenseError);
743
- }
744
- })
745
- );
699
+ return runWithOwner(o, () => createComponent(SuspenseContext.Provider, {
700
+ value,
701
+ get children() {
702
+ return catchError(() => props.children, suspenseError);
703
+ }
704
+ }));
746
705
  }
747
706
  const res = runSuspense();
748
707
  if (suspenseComplete(value)) {
@@ -759,9 +718,7 @@ function Suspense(props) {
759
718
  noHydrate: true
760
719
  });
761
720
  const res = {
762
- t: `<template id="pl-${id}"></template>${resolveSSRNode(
763
- escape(props.fallback)
764
- )}<!--pl-${id}-->`
721
+ t: `<template id="pl-${id}"></template>${resolveSSRNode(escape(props.fallback))}<!--pl-${id}-->`
765
722
  };
766
723
  setHydrateContext(ctx);
767
724
  return res;
@@ -776,58 +733,4 @@ function Suspense(props) {
776
733
  }, suspenseError);
777
734
  }
778
735
 
779
- export {
780
- $DEVCOMP,
781
- $PROXY,
782
- $TRACK,
783
- DEV,
784
- ErrorBoundary,
785
- For,
786
- Index,
787
- Match,
788
- Show,
789
- Suspense,
790
- SuspenseList,
791
- Switch,
792
- batch,
793
- catchError,
794
- children,
795
- createComponent,
796
- createComputed,
797
- createContext,
798
- createDeferred,
799
- createEffect,
800
- createMemo,
801
- createReaction,
802
- createRenderEffect,
803
- createResource,
804
- createRoot,
805
- createSelector,
806
- createSignal,
807
- createUniqueId,
808
- enableExternalSource,
809
- enableHydration,
810
- enableScheduling,
811
- equalFn,
812
- from,
813
- getListener,
814
- getOwner,
815
- indexArray,
816
- lazy,
817
- mapArray,
818
- mergeProps,
819
- observable,
820
- on,
821
- onCleanup,
822
- onError,
823
- onMount,
824
- requestCallback,
825
- resetErrorBoundaries,
826
- runWithOwner,
827
- sharedConfig,
828
- splitProps,
829
- startTransition,
830
- untrack,
831
- useContext,
832
- useTransition
833
- };
736
+ export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, catchError, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
package/dist/solid.cjs CHANGED
@@ -341,17 +341,27 @@ function createResource(pSource, pFetcher, pOptions) {
341
341
  return;
342
342
  }
343
343
  if (Transition && pr) Transition.promises.delete(pr);
344
- const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, {
345
- value: value(),
346
- refetching
347
- }));
348
- if (!isPromise(p)) {
344
+ let error;
345
+ const p = initP !== NO_INIT ? initP : untrack(() => {
346
+ try {
347
+ return fetcher(lookup, {
348
+ value: value(),
349
+ refetching
350
+ });
351
+ } catch (fetcherError) {
352
+ error = fetcherError;
353
+ }
354
+ });
355
+ if (error !== undefined) {
356
+ loadEnd(pr, undefined, castError(error), lookup);
357
+ return;
358
+ } else if (!isPromise(p)) {
349
359
  loadEnd(pr, p, undefined, lookup);
350
360
  return p;
351
361
  }
352
362
  pr = p;
353
- if ("value" in p) {
354
- if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, castError(p.value), lookup);
363
+ if ("v" in p) {
364
+ if (p.s === 1) loadEnd(pr, p.v, undefined, lookup);else loadEnd(pr, undefined, castError(p.v), lookup);
355
365
  return p;
356
366
  }
357
367
  scheduled = true;
@@ -1622,7 +1632,7 @@ function Suspense(props) {
1622
1632
  const key = sharedConfig.getContextId();
1623
1633
  let ref = sharedConfig.load(key);
1624
1634
  if (ref) {
1625
- if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key);
1635
+ if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(key);
1626
1636
  }
1627
1637
  if (p && p !== "$$f") {
1628
1638
  const [s, set] = createSignal(undefined, {