solid-js 1.9.6 → 1.9.8

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 (51) hide show
  1. package/dist/dev.cjs +26 -15
  2. package/dist/dev.js +334 -564
  3. package/dist/server.cjs +3 -1
  4. package/dist/server.js +83 -178
  5. package/dist/solid.cjs +26 -15
  6. package/dist/solid.js +290 -493
  7. package/h/dist/h.js +9 -40
  8. package/h/jsx-runtime/dist/jsx.js +1 -1
  9. package/h/jsx-runtime/types/index.d.ts +8 -11
  10. package/h/jsx-runtime/types/jsx.d.ts +246 -234
  11. package/h/types/hyperscript.d.ts +11 -11
  12. package/html/dist/html.js +94 -219
  13. package/html/types/lit.d.ts +33 -52
  14. package/package.json +3 -3
  15. package/store/dist/dev.cjs +9 -5
  16. package/store/dist/dev.js +50 -126
  17. package/store/dist/server.js +8 -20
  18. package/store/dist/store.cjs +9 -5
  19. package/store/dist/store.js +47 -117
  20. package/store/types/index.d.ts +7 -21
  21. package/store/types/modifiers.d.ts +3 -6
  22. package/store/types/mutable.d.ts +2 -5
  23. package/store/types/server.d.ts +5 -25
  24. package/store/types/store.d.ts +61 -218
  25. package/types/index.d.ts +11 -78
  26. package/types/jsx.d.ts +245 -229
  27. package/types/reactive/array.d.ts +4 -12
  28. package/types/reactive/observable.d.ts +16 -22
  29. package/types/reactive/scheduler.d.ts +6 -9
  30. package/types/reactive/signal.d.ts +145 -236
  31. package/types/render/Suspense.d.ts +5 -5
  32. package/types/render/component.d.ts +37 -73
  33. package/types/render/flow.d.ts +31 -43
  34. package/types/render/hydration.d.ts +15 -15
  35. package/types/server/index.d.ts +2 -57
  36. package/types/server/reactive.d.ts +45 -76
  37. package/types/server/rendering.d.ts +98 -169
  38. package/universal/dist/dev.js +12 -28
  39. package/universal/dist/universal.js +12 -28
  40. package/universal/types/index.d.ts +2 -3
  41. package/universal/types/universal.d.ts +3 -2
  42. package/web/dist/dev.cjs +89 -6
  43. package/web/dist/dev.js +174 -646
  44. package/web/dist/server.cjs +90 -5
  45. package/web/dist/server.js +194 -647
  46. package/web/dist/web.cjs +89 -6
  47. package/web/dist/web.js +172 -634
  48. package/web/storage/dist/storage.js +3 -3
  49. package/web/types/core.d.ts +1 -9
  50. package/web/types/index.d.ts +11 -31
  51. package/web/types/server-mock.d.ts +32 -47
package/dist/server.cjs CHANGED
@@ -602,10 +602,12 @@ function createResource(source, fetcher, options = {}) {
602
602
  return ctx.resources[id].data;
603
603
  }
604
604
  if (options.ssrLoadFrom !== "initial") load();
605
- return resource.ref = [read, {
605
+ const ref = [read, {
606
606
  refetch: load,
607
607
  mutate: v => value = v
608
608
  }];
609
+ if (p) resource.ref = ref;
610
+ return ref;
609
611
  }
610
612
  function lazy(fn) {
611
613
  let p;
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,19 @@ 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
+ const ref = [read, {
604
+ refetch: load,
605
+ mutate: v => value = v
606
+ }];
607
+ if (p) resource.ref = ref;
608
+ return ref;
638
609
  }
639
610
  function lazy(fn) {
640
611
  let p;
641
612
  let load = id => {
642
613
  if (!p) {
643
614
  p = fn();
644
- p.then(mod => (p.resolved = mod.default));
615
+ p.then(mod => p.resolved = mod.default);
645
616
  if (id) sharedConfig.context.lazy[id] = p;
646
617
  }
647
618
  return p;
@@ -650,8 +621,7 @@ function lazy(fn) {
650
621
  const wrap = props => {
651
622
  const id = sharedConfig.context.id;
652
623
  let ref = sharedConfig.context.lazy[id];
653
- if (ref) p = ref;
654
- else load(id);
624
+ if (ref) p = ref;else load(id);
655
625
  if (p.resolved) return p.resolved(props);
656
626
  const ctx = useContext(SuspenseContext);
657
627
  const track = {
@@ -663,12 +633,10 @@ function lazy(fn) {
663
633
  contexts.add(ctx);
664
634
  }
665
635
  if (sharedConfig.context.async) {
666
- sharedConfig.context.block(
667
- p.then(() => {
668
- track.loading = false;
669
- notifySuspense(contexts);
670
- })
671
- );
636
+ sharedConfig.context.block(p.then(() => {
637
+ track.loading = false;
638
+ notifySuspense(contexts);
639
+ }));
672
640
  }
673
641
  return "";
674
642
  };
@@ -696,12 +664,9 @@ function startTransition(fn) {
696
664
  fn();
697
665
  }
698
666
  function useTransition() {
699
- return [
700
- () => false,
701
- fn => {
702
- fn();
703
- }
704
- ];
667
+ return [() => false, fn => {
668
+ fn();
669
+ }];
705
670
  }
706
671
  function SuspenseList(props) {
707
672
  return props.children;
@@ -711,17 +676,15 @@ function Suspense(props) {
711
676
  const ctx = sharedConfig.context;
712
677
  const id = sharedConfig.getContextId();
713
678
  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
- }
679
+ const value = ctx.suspense[id] || (ctx.suspense[id] = {
680
+ resources: new Map(),
681
+ completed: () => {
682
+ const res = runSuspense();
683
+ if (suspenseComplete(value)) {
684
+ done(resolveSSRNode(escape(res)));
723
685
  }
724
- });
686
+ }
687
+ });
725
688
  function suspenseError(err) {
726
689
  if (!done || !done(undefined, err)) {
727
690
  runWithOwner(o.owner, () => {
@@ -735,14 +698,12 @@ function Suspense(props) {
735
698
  count: 0
736
699
  });
737
700
  cleanNode(o);
738
- return runWithOwner(o, () =>
739
- createComponent(SuspenseContext.Provider, {
740
- value,
741
- get children() {
742
- return catchError(() => props.children, suspenseError);
743
- }
744
- })
745
- );
701
+ return runWithOwner(o, () => createComponent(SuspenseContext.Provider, {
702
+ value,
703
+ get children() {
704
+ return catchError(() => props.children, suspenseError);
705
+ }
706
+ }));
746
707
  }
747
708
  const res = runSuspense();
748
709
  if (suspenseComplete(value)) {
@@ -759,9 +720,7 @@ function Suspense(props) {
759
720
  noHydrate: true
760
721
  });
761
722
  const res = {
762
- t: `<template id="pl-${id}"></template>${resolveSSRNode(
763
- escape(props.fallback)
764
- )}<!--pl-${id}-->`
723
+ t: `<template id="pl-${id}"></template>${resolveSSRNode(escape(props.fallback))}<!--pl-${id}-->`
765
724
  };
766
725
  setHydrateContext(ctx);
767
726
  return res;
@@ -776,58 +735,4 @@ function Suspense(props) {
776
735
  }, suspenseError);
777
736
  }
778
737
 
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
- };
738
+ 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
@@ -9,6 +9,7 @@ let taskIdCounter = 1,
9
9
  yieldInterval = 5,
10
10
  deadline = 0,
11
11
  maxYieldInterval = 300,
12
+ maxDeadline = 0,
12
13
  scheduleCallback = null,
13
14
  scheduledCallback = null;
14
15
  const maxSigned31BitInt = 1073741823;
@@ -20,9 +21,9 @@ function setupScheduler() {
20
21
  if (scheduledCallback !== null) {
21
22
  const currentTime = performance.now();
22
23
  deadline = currentTime + yieldInterval;
23
- const hasTimeRemaining = true;
24
+ maxDeadline = currentTime + maxYieldInterval;
24
25
  try {
25
- const hasMoreWork = scheduledCallback(hasTimeRemaining, currentTime);
26
+ const hasMoreWork = scheduledCallback(currentTime);
26
27
  if (!hasMoreWork) {
27
28
  scheduledCallback = null;
28
29
  } else port.postMessage(null);
@@ -40,7 +41,7 @@ function setupScheduler() {
40
41
  if (scheduling.isInputPending()) {
41
42
  return true;
42
43
  }
43
- return currentTime >= maxYieldInterval;
44
+ return currentTime >= maxDeadline;
44
45
  } else {
45
46
  return false;
46
47
  }
@@ -84,21 +85,21 @@ function requestCallback(fn, options) {
84
85
  function cancelCallback(task) {
85
86
  task.fn = null;
86
87
  }
87
- function flushWork(hasTimeRemaining, initialTime) {
88
+ function flushWork(initialTime) {
88
89
  isCallbackScheduled = false;
89
90
  isPerformingWork = true;
90
91
  try {
91
- return workLoop(hasTimeRemaining, initialTime);
92
+ return workLoop(initialTime);
92
93
  } finally {
93
94
  currentTask = null;
94
95
  isPerformingWork = false;
95
96
  }
96
97
  }
97
- function workLoop(hasTimeRemaining, initialTime) {
98
+ function workLoop(initialTime) {
98
99
  let currentTime = initialTime;
99
100
  currentTask = taskQueue[0] || null;
100
101
  while (currentTask !== null) {
101
- if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
102
+ if (currentTask.expirationTime > currentTime && shouldYieldToHost()) {
102
103
  break;
103
104
  }
104
105
  const callback = currentTask.fn;
@@ -341,17 +342,27 @@ function createResource(pSource, pFetcher, pOptions) {
341
342
  return;
342
343
  }
343
344
  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)) {
345
+ let error;
346
+ const p = initP !== NO_INIT ? initP : untrack(() => {
347
+ try {
348
+ return fetcher(lookup, {
349
+ value: value(),
350
+ refetching
351
+ });
352
+ } catch (fetcherError) {
353
+ error = fetcherError;
354
+ }
355
+ });
356
+ if (error !== undefined) {
357
+ loadEnd(pr, undefined, castError(error), lookup);
358
+ return;
359
+ } else if (!isPromise(p)) {
349
360
  loadEnd(pr, p, undefined, lookup);
350
361
  return p;
351
362
  }
352
363
  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);
364
+ if ("v" in p) {
365
+ if (p.s === 1) loadEnd(pr, p.v, undefined, lookup);else loadEnd(pr, undefined, castError(p.v), lookup);
355
366
  return p;
356
367
  }
357
368
  scheduled = true;
@@ -1622,7 +1633,7 @@ function Suspense(props) {
1622
1633
  const key = sharedConfig.getContextId();
1623
1634
  let ref = sharedConfig.load(key);
1624
1635
  if (ref) {
1625
- if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key);
1636
+ if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(key);
1626
1637
  }
1627
1638
  if (p && p !== "$$f") {
1628
1639
  const [s, set] = createSignal(undefined, {