solid-js 1.8.1 → 1.8.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
@@ -286,7 +286,7 @@ function createResource(pSource, pFetcher, pOptions) {
286
286
  if (sharedConfig.context) {
287
287
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
288
288
  let v;
289
- if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = isPromise(v) && "value" in v ? v.value : v;
289
+ if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
290
290
  }
291
291
  function loadEnd(p, v, error, key) {
292
292
  if (pr === p) {
@@ -352,6 +352,10 @@ function createResource(pSource, pFetcher, pOptions) {
352
352
  loadEnd(pr, p, undefined, lookup);
353
353
  return p;
354
354
  }
355
+ if ("value" in p) {
356
+ if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, undefined, lookup);
357
+ return p;
358
+ }
355
359
  pr = p;
356
360
  scheduled = true;
357
361
  queueMicrotask(() => scheduled = false);
@@ -1660,7 +1664,7 @@ function Suspense(props) {
1660
1664
  if (sharedConfig.context && sharedConfig.load) {
1661
1665
  const key = sharedConfig.context.id + sharedConfig.context.count;
1662
1666
  let ref = sharedConfig.load(key);
1663
- if (ref && (typeof ref !== "object" || !("value" in ref))) p = ref;
1667
+ if (ref && (typeof ref !== "object" || ref.status !== 'success')) p = ref;
1664
1668
  if (p && p !== "$$f") {
1665
1669
  const [s, set] = createSignal(undefined, {
1666
1670
  equals: false
package/dist/dev.js CHANGED
@@ -301,8 +301,7 @@ function createResource(pSource, pFetcher, pOptions) {
301
301
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
302
302
  let v;
303
303
  if (options.ssrLoadFrom === "initial") initP = options.initialValue;
304
- else if (sharedConfig.load && (v = sharedConfig.load(id)))
305
- initP = isPromise(v) && "value" in v ? v.value : v;
304
+ else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
306
305
  }
307
306
  function loadEnd(p, v, error, key) {
308
307
  if (pr === p) {
@@ -377,6 +376,11 @@ function createResource(pSource, pFetcher, pOptions) {
377
376
  loadEnd(pr, p, undefined, lookup);
378
377
  return p;
379
378
  }
379
+ if ("value" in p) {
380
+ if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);
381
+ else loadEnd(pr, undefined, undefined, lookup);
382
+ return p;
383
+ }
380
384
  pr = p;
381
385
  scheduled = true;
382
386
  queueMicrotask(() => (scheduled = false));
@@ -1837,7 +1841,7 @@ function Suspense(props) {
1837
1841
  if (sharedConfig.context && sharedConfig.load) {
1838
1842
  const key = sharedConfig.context.id + sharedConfig.context.count;
1839
1843
  let ref = sharedConfig.load(key);
1840
- if (ref && (typeof ref !== "object" || !("value" in ref))) p = ref;
1844
+ if (ref && (typeof ref !== "object" || ref.status !== "success")) p = ref;
1841
1845
  if (p && p !== "$$f") {
1842
1846
  const [s, set] = createSignal(undefined, {
1843
1847
  equals: false
package/dist/server.cjs CHANGED
@@ -220,11 +220,19 @@ function requestCallback(fn, options) {
220
220
  function mapArray(list, mapFn, options = {}) {
221
221
  const items = list();
222
222
  let s = [];
223
- if (items.length) {
223
+ if (items && items.length) {
224
224
  for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(items[i], () => i));
225
225
  } else if (options.fallback) s = [options.fallback()];
226
226
  return () => s;
227
227
  }
228
+ function indexArray(list, mapFn, options = {}) {
229
+ const items = list();
230
+ let s = [];
231
+ if (items && items.length) {
232
+ for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(() => items[i], i));
233
+ } else if (options.fallback) s = [options.fallback()];
234
+ return () => s;
235
+ }
228
236
  function observable(input) {
229
237
  return {
230
238
  subscribe(observer) {
@@ -513,8 +521,7 @@ function createResource(source, fetcher, options = {}) {
513
521
  if (p != undefined && typeof p === "object" && "then" in p) {
514
522
  read.loading = true;
515
523
  read.state = "pending";
516
- if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
517
- return p.then(res => {
524
+ p = p.then(res => {
518
525
  read.loading = false;
519
526
  read.state = "ready";
520
527
  ctx.resources[id].data = res;
@@ -527,7 +534,10 @@ function createResource(source, fetcher, options = {}) {
527
534
  read.error = error = castError(err);
528
535
  p = null;
529
536
  notifySuspense(contexts);
537
+ throw error;
530
538
  });
539
+ if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
540
+ return p;
531
541
  }
532
542
  ctx.resources[id].data = p;
533
543
  if (ctx.serialize) ctx.serialize(id, p);
@@ -639,7 +649,10 @@ function Suspense(props) {
639
649
  }));
640
650
  }
641
651
  const res = runSuspense();
642
- if (suspenseComplete(value)) return res;
652
+ if (suspenseComplete(value)) {
653
+ delete ctx.suspense[id];
654
+ return res;
655
+ }
643
656
  done = ctx.async ? ctx.registerFragment(id) : undefined;
644
657
  return catchError(() => {
645
658
  if (ctx.async) {
@@ -700,6 +713,7 @@ exports.equalFn = equalFn;
700
713
  exports.from = from;
701
714
  exports.getListener = getListener;
702
715
  exports.getOwner = getOwner;
716
+ exports.indexArray = indexArray;
703
717
  exports.lazy = lazy;
704
718
  exports.mapArray = mapArray;
705
719
  exports.mergeProps = mergeProps;
package/dist/server.js CHANGED
@@ -228,11 +228,19 @@ function requestCallback(fn, options) {
228
228
  function mapArray(list, mapFn, options = {}) {
229
229
  const items = list();
230
230
  let s = [];
231
- if (items.length) {
231
+ if (items && items.length) {
232
232
  for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(items[i], () => i));
233
233
  } else if (options.fallback) s = [options.fallback()];
234
234
  return () => s;
235
235
  }
236
+ function indexArray(list, mapFn, options = {}) {
237
+ const items = list();
238
+ let s = [];
239
+ if (items && items.length) {
240
+ for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(() => items[i], i));
241
+ } else if (options.fallback) s = [options.fallback()];
242
+ return () => s;
243
+ }
236
244
  function observable(input) {
237
245
  return {
238
246
  subscribe(observer) {
@@ -537,8 +545,7 @@ function createResource(source, fetcher, options = {}) {
537
545
  if (p != undefined && typeof p === "object" && "then" in p) {
538
546
  read.loading = true;
539
547
  read.state = "pending";
540
- if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
541
- return p
548
+ p = p
542
549
  .then(res => {
543
550
  read.loading = false;
544
551
  read.state = "ready";
@@ -553,7 +560,10 @@ function createResource(source, fetcher, options = {}) {
553
560
  read.error = error = castError(err);
554
561
  p = null;
555
562
  notifySuspense(contexts);
563
+ throw error;
556
564
  });
565
+ if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
566
+ return p;
557
567
  }
558
568
  ctx.resources[id].data = p;
559
569
  if (ctx.serialize) ctx.serialize(id, p);
@@ -678,7 +688,10 @@ function Suspense(props) {
678
688
  );
679
689
  }
680
690
  const res = runSuspense();
681
- if (suspenseComplete(value)) return res;
691
+ if (suspenseComplete(value)) {
692
+ delete ctx.suspense[id];
693
+ return res;
694
+ }
682
695
  done = ctx.async ? ctx.registerFragment(id) : undefined;
683
696
  return catchError(() => {
684
697
  if (ctx.async) {
@@ -740,6 +753,7 @@ export {
740
753
  from,
741
754
  getListener,
742
755
  getOwner,
756
+ indexArray,
743
757
  lazy,
744
758
  mapArray,
745
759
  mergeProps,
package/dist/solid.cjs CHANGED
@@ -270,7 +270,7 @@ function createResource(pSource, pFetcher, pOptions) {
270
270
  if (sharedConfig.context) {
271
271
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
272
272
  let v;
273
- if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = isPromise(v) && "value" in v ? v.value : v;
273
+ if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
274
274
  }
275
275
  function loadEnd(p, v, error, key) {
276
276
  if (pr === p) {
@@ -336,6 +336,10 @@ function createResource(pSource, pFetcher, pOptions) {
336
336
  loadEnd(pr, p, undefined, lookup);
337
337
  return p;
338
338
  }
339
+ if ("value" in p) {
340
+ if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, undefined, lookup);
341
+ return p;
342
+ }
339
343
  pr = p;
340
344
  scheduled = true;
341
345
  queueMicrotask(() => scheduled = false);
@@ -1598,7 +1602,7 @@ function Suspense(props) {
1598
1602
  if (sharedConfig.context && sharedConfig.load) {
1599
1603
  const key = sharedConfig.context.id + sharedConfig.context.count;
1600
1604
  let ref = sharedConfig.load(key);
1601
- if (ref && (typeof ref !== "object" || !("value" in ref))) p = ref;
1605
+ if (ref && (typeof ref !== "object" || ref.status !== 'success')) p = ref;
1602
1606
  if (p && p !== "$$f") {
1603
1607
  const [s, set] = createSignal(undefined, {
1604
1608
  equals: false
package/dist/solid.js CHANGED
@@ -281,8 +281,7 @@ function createResource(pSource, pFetcher, pOptions) {
281
281
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
282
282
  let v;
283
283
  if (options.ssrLoadFrom === "initial") initP = options.initialValue;
284
- else if (sharedConfig.load && (v = sharedConfig.load(id)))
285
- initP = isPromise(v) && "value" in v ? v.value : v;
284
+ else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
286
285
  }
287
286
  function loadEnd(p, v, error, key) {
288
287
  if (pr === p) {
@@ -357,6 +356,11 @@ function createResource(pSource, pFetcher, pOptions) {
357
356
  loadEnd(pr, p, undefined, lookup);
358
357
  return p;
359
358
  }
359
+ if ("value" in p) {
360
+ if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);
361
+ else loadEnd(pr, undefined, undefined, lookup);
362
+ return p;
363
+ }
360
364
  pr = p;
361
365
  scheduled = true;
362
366
  queueMicrotask(() => (scheduled = false));
@@ -1748,7 +1752,7 @@ function Suspense(props) {
1748
1752
  if (sharedConfig.context && sharedConfig.load) {
1749
1753
  const key = sharedConfig.context.id + sharedConfig.context.count;
1750
1754
  let ref = sharedConfig.load(key);
1751
- if (ref && (typeof ref !== "object" || !("value" in ref))) p = ref;
1755
+ if (ref && (typeof ref !== "object" || ref.status !== "success")) p = ref;
1752
1756
  if (p && p !== "$$f") {
1753
1757
  const [s, set] = createSignal(undefined, {
1754
1758
  equals: false
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.8.1",
4
+ "version": "1.8.3",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -206,7 +206,7 @@
206
206
  ],
207
207
  "dependencies": {
208
208
  "csstype": "^3.1.0",
209
- "seroval": "^0.10.4"
209
+ "seroval": "^0.11.6"
210
210
  },
211
211
  "scripts": {
212
212
  "build": "npm-run-all -nl build:*",
@@ -1,4 +1,4 @@
1
- import { Computation } from "../reactive/signal";
1
+ import { Computation } from "../reactive/signal.js";
2
2
  export type HydrationContext = {
3
3
  id: string;
4
4
  count: number;
@@ -24,6 +24,7 @@ export {
24
24
  equalFn,
25
25
  requestCallback,
26
26
  mapArray,
27
+ indexArray,
27
28
  observable,
28
29
  from,
29
30
  $PROXY,
@@ -79,10 +79,17 @@ export declare function requestCallback(
79
79
  ): Task;
80
80
  export declare function cancelCallback(task: Task): void;
81
81
  export declare function mapArray<T, U>(
82
- list: () => T[],
83
- mapFn: (v: T, i: () => number) => U,
82
+ list: Accessor<readonly T[] | undefined | null | false>,
83
+ mapFn: (v: T, i: Accessor<number>) => U,
84
84
  options?: {
85
- fallback?: () => any;
85
+ fallback?: Accessor<any>;
86
+ }
87
+ ): () => U[];
88
+ export declare function indexArray<T, U>(
89
+ list: Accessor<readonly T[] | undefined | null | false>,
90
+ mapFn: (v: Accessor<T>, i: number) => U,
91
+ options?: {
92
+ fallback?: Accessor<any>;
86
93
  }
87
94
  ): () => U[];
88
95
  export type ObservableObserver<T> =
@@ -207,7 +207,7 @@ function renderToStream(code, options = {}) {
207
207
  } else {
208
208
  buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
209
209
  pushTask(`$df("${key}")${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
210
- resolve(true);
210
+ error ? reject(error) : resolve(true);
211
211
  scriptFlushed = true;
212
212
  }
213
213
  }
@@ -239,7 +239,7 @@ function renderToStream(code, options = {}) {
239
239
  } else {
240
240
  buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
241
241
  pushTask(`$df("${key}")${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
242
- resolve(true);
242
+ error ? reject(error) : resolve(true);
243
243
  scriptFlushed = true;
244
244
  }
245
245
  }