solid-js 1.3.0-beta.2 → 1.3.0-beta.6

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/README.md CHANGED
@@ -1,4 +1,6 @@
1
- ## <img src="https://raw.githubusercontent.com/solidjs/solid/main/assets/logo.png" alt="Solid" width="350"/><br>
1
+ <p>
2
+ <img width="100%" src="https://raw.githubusercontent.com/solidjs/solid/master/banner.png" alt="SolidJS">
3
+ </p>
2
4
 
3
5
  [![Build Status](https://github.com/solidjs/solid/workflows/Solid%20CI/badge.svg)](https://github.com/solidjs/solid/actions/workflows/main-ci.yml)
4
6
  [![Coverage Status](https://img.shields.io/coveralls/github/solidjs/solid.svg?style=flat)](https://coveralls.io/github/solidjs/solid?branch=main)
package/dist/dev.cjs CHANGED
@@ -149,6 +149,7 @@ const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
149
149
  var Owner = null;
150
150
  let Transition = null;
151
151
  let Scheduler = null;
152
+ let ExternalSourceFactory = null;
152
153
  let Listener = null;
153
154
  let Pending = null;
154
155
  let Updates = null;
@@ -554,6 +555,24 @@ let SuspenseContext;
554
555
  function getSuspenseContext() {
555
556
  return SuspenseContext || (SuspenseContext = createContext({}));
556
557
  }
558
+ function enableExternalSource(factory) {
559
+ if (ExternalSourceFactory) {
560
+ const oldFactory = ExternalSourceFactory;
561
+ ExternalSourceFactory = (fn, trigger) => {
562
+ const oldSource = oldFactory(fn, trigger);
563
+ const source = factory(x => oldSource.track(x), trigger);
564
+ return {
565
+ track: x => source.track(x),
566
+ dispose() {
567
+ source.dispose();
568
+ oldSource.dispose();
569
+ }
570
+ };
571
+ };
572
+ } else {
573
+ ExternalSourceFactory = factory;
574
+ }
575
+ }
557
576
  function readSignal() {
558
577
  const runningTransition = Transition && Transition.running;
559
578
  if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
@@ -682,6 +701,19 @@ function createComputation(fn, init, pure, state = STALE, options) {
682
701
  }
683
702
  c.name = options && options.name || `${Owner.name || "c"}-${(Owner.owned || Owner.tOwned).length}`;
684
703
  }
704
+ if (ExternalSourceFactory) {
705
+ const [track, trigger] = createSignal(undefined, {
706
+ equals: false
707
+ });
708
+ const ordinary = ExternalSourceFactory(c.fn, trigger);
709
+ onCleanup(() => ordinary.dispose());
710
+ const triggerInTransition = () => startTransition(trigger, () => inTransition.dispose());
711
+ const inTransition = ExternalSourceFactory(c.fn, triggerInTransition);
712
+ c.fn = x => {
713
+ track();
714
+ return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
715
+ };
716
+ }
685
717
  return c;
686
718
  }
687
719
  function runTop(node) {
@@ -1139,13 +1171,19 @@ function indexArray(list, mapFn, options = {}) {
1139
1171
  };
1140
1172
  }
1141
1173
 
1174
+ let hydrationEnabled = false;
1175
+ function enableHydration() {
1176
+ hydrationEnabled = true;
1177
+ }
1142
1178
  function createComponent(Comp, props) {
1143
- if (sharedConfig.context) {
1144
- const c = sharedConfig.context;
1145
- setHydrateContext(nextHydrateContext());
1146
- const r = devComponent(Comp, props) ;
1147
- setHydrateContext(c);
1148
- return r;
1179
+ if (hydrationEnabled) {
1180
+ if (sharedConfig.context) {
1181
+ const c = sharedConfig.context;
1182
+ setHydrateContext(nextHydrateContext());
1183
+ const r = devComponent(Comp, props) ;
1184
+ setHydrateContext(c);
1185
+ return r;
1186
+ }
1149
1187
  }
1150
1188
  return devComponent(Comp, props);
1151
1189
  }
@@ -1234,19 +1272,20 @@ function splitProps(props, ...keys) {
1234
1272
  }
1235
1273
  function lazy(fn) {
1236
1274
  let comp;
1275
+ let p;
1237
1276
  const wrap = props => {
1238
1277
  const ctx = sharedConfig.context;
1239
1278
  if (ctx) {
1240
1279
  ctx.count++;
1241
1280
  const [s, set] = createSignal();
1242
- fn().then(mod => {
1281
+ (p || (p = fn())).then(mod => {
1243
1282
  setHydrateContext(ctx);
1244
1283
  set(() => mod.default);
1245
1284
  setHydrateContext(undefined);
1246
1285
  });
1247
1286
  comp = s;
1248
1287
  } else if (!comp) {
1249
- const [s] = createResource(() => fn().then(mod => mod.default));
1288
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1250
1289
  comp = s;
1251
1290
  } else {
1252
1291
  const c = comp();
@@ -1262,7 +1301,7 @@ function lazy(fn) {
1262
1301
  return r;
1263
1302
  }));
1264
1303
  };
1265
- wrap.preload = () => comp || fn().then(mod => comp = () => mod.default);
1304
+ wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
1266
1305
  return wrap;
1267
1306
  }
1268
1307
  let counter = 0;
@@ -1322,7 +1361,11 @@ function Match(props) {
1322
1361
  return props;
1323
1362
  }
1324
1363
  function ErrorBoundary(props) {
1325
- const [errored, setErrored] = createSignal();
1364
+ let err = undefined;
1365
+ if (sharedConfig.context && sharedConfig.load) {
1366
+ err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
1367
+ }
1368
+ const [errored, setErrored] = createSignal(err);
1326
1369
  let e;
1327
1370
  return createMemo(() => {
1328
1371
  if ((e = errored()) != null) {
@@ -1406,7 +1449,8 @@ function Suspense(props) {
1406
1449
  showFallback,
1407
1450
  ctx,
1408
1451
  waitingHydration,
1409
- flicker;
1452
+ flicker,
1453
+ error;
1410
1454
  const [inFallback, setFallback] = createSignal(false),
1411
1455
  SuspenseContext = getSuspenseContext(),
1412
1456
  store = {
@@ -1421,7 +1465,7 @@ function Suspense(props) {
1421
1465
  resolved: false
1422
1466
  },
1423
1467
  owner = getOwner();
1424
- if (sharedConfig.context && sharedConfig.load) {
1468
+ if (sharedConfig.context) {
1425
1469
  const key = sharedConfig.context.id + sharedConfig.context.count;
1426
1470
  const p = sharedConfig.load(key);
1427
1471
  if (p) {
@@ -1429,7 +1473,8 @@ function Suspense(props) {
1429
1473
  equals: false
1430
1474
  });
1431
1475
  flicker = s;
1432
- p.then(() => {
1476
+ p.then(err => {
1477
+ if (error = err) return set();
1433
1478
  sharedConfig.gather(key);
1434
1479
  waitingHydration = true;
1435
1480
  setHydrateContext(ctx);
@@ -1447,6 +1492,7 @@ function Suspense(props) {
1447
1492
  value: store,
1448
1493
  get children() {
1449
1494
  return createMemo(() => {
1495
+ if (error) throw error;
1450
1496
  if (flicker) {
1451
1497
  ctx = sharedConfig.context;
1452
1498
  flicker();
@@ -1466,7 +1512,10 @@ function Suspense(props) {
1466
1512
  if (!visibleFallback) return;
1467
1513
  return createRoot(disposer => {
1468
1514
  dispose = disposer;
1469
- if (sharedConfig.context) sharedConfig.context.count = 0;
1515
+ if (sharedConfig.context) setHydrateContext({
1516
+ id: sharedConfig.context.id + "f",
1517
+ count: 0
1518
+ });
1470
1519
  return props.fallback;
1471
1520
  }, owner);
1472
1521
  });
@@ -1512,6 +1561,8 @@ exports.createRoot = createRoot;
1512
1561
  exports.createSelector = createSelector;
1513
1562
  exports.createSignal = createSignal;
1514
1563
  exports.createUniqueId = createUniqueId;
1564
+ exports.enableExternalSource = enableExternalSource;
1565
+ exports.enableHydration = enableHydration;
1515
1566
  exports.enableScheduling = enableScheduling;
1516
1567
  exports.equalFn = equalFn;
1517
1568
  exports.from = from;
package/dist/dev.js CHANGED
@@ -145,6 +145,7 @@ const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
145
145
  var Owner = null;
146
146
  let Transition = null;
147
147
  let Scheduler = null;
148
+ let ExternalSourceFactory = null;
148
149
  let Listener = null;
149
150
  let Pending = null;
150
151
  let Updates = null;
@@ -550,6 +551,24 @@ let SuspenseContext;
550
551
  function getSuspenseContext() {
551
552
  return SuspenseContext || (SuspenseContext = createContext({}));
552
553
  }
554
+ function enableExternalSource(factory) {
555
+ if (ExternalSourceFactory) {
556
+ const oldFactory = ExternalSourceFactory;
557
+ ExternalSourceFactory = (fn, trigger) => {
558
+ const oldSource = oldFactory(fn, trigger);
559
+ const source = factory(x => oldSource.track(x), trigger);
560
+ return {
561
+ track: x => source.track(x),
562
+ dispose() {
563
+ source.dispose();
564
+ oldSource.dispose();
565
+ }
566
+ };
567
+ };
568
+ } else {
569
+ ExternalSourceFactory = factory;
570
+ }
571
+ }
553
572
  function readSignal() {
554
573
  const runningTransition = Transition && Transition.running;
555
574
  if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
@@ -678,6 +697,19 @@ function createComputation(fn, init, pure, state = STALE, options) {
678
697
  }
679
698
  c.name = options && options.name || `${Owner.name || "c"}-${(Owner.owned || Owner.tOwned).length}`;
680
699
  }
700
+ if (ExternalSourceFactory) {
701
+ const [track, trigger] = createSignal(undefined, {
702
+ equals: false
703
+ });
704
+ const ordinary = ExternalSourceFactory(c.fn, trigger);
705
+ onCleanup(() => ordinary.dispose());
706
+ const triggerInTransition = () => startTransition(trigger, () => inTransition.dispose());
707
+ const inTransition = ExternalSourceFactory(c.fn, triggerInTransition);
708
+ c.fn = x => {
709
+ track();
710
+ return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
711
+ };
712
+ }
681
713
  return c;
682
714
  }
683
715
  function runTop(node) {
@@ -1135,13 +1167,19 @@ function indexArray(list, mapFn, options = {}) {
1135
1167
  };
1136
1168
  }
1137
1169
 
1170
+ let hydrationEnabled = false;
1171
+ function enableHydration() {
1172
+ hydrationEnabled = true;
1173
+ }
1138
1174
  function createComponent(Comp, props) {
1139
- if (sharedConfig.context) {
1140
- const c = sharedConfig.context;
1141
- setHydrateContext(nextHydrateContext());
1142
- const r = devComponent(Comp, props) ;
1143
- setHydrateContext(c);
1144
- return r;
1175
+ if (hydrationEnabled) {
1176
+ if (sharedConfig.context) {
1177
+ const c = sharedConfig.context;
1178
+ setHydrateContext(nextHydrateContext());
1179
+ const r = devComponent(Comp, props) ;
1180
+ setHydrateContext(c);
1181
+ return r;
1182
+ }
1145
1183
  }
1146
1184
  return devComponent(Comp, props);
1147
1185
  }
@@ -1230,19 +1268,20 @@ function splitProps(props, ...keys) {
1230
1268
  }
1231
1269
  function lazy(fn) {
1232
1270
  let comp;
1271
+ let p;
1233
1272
  const wrap = props => {
1234
1273
  const ctx = sharedConfig.context;
1235
1274
  if (ctx) {
1236
1275
  ctx.count++;
1237
1276
  const [s, set] = createSignal();
1238
- fn().then(mod => {
1277
+ (p || (p = fn())).then(mod => {
1239
1278
  setHydrateContext(ctx);
1240
1279
  set(() => mod.default);
1241
1280
  setHydrateContext(undefined);
1242
1281
  });
1243
1282
  comp = s;
1244
1283
  } else if (!comp) {
1245
- const [s] = createResource(() => fn().then(mod => mod.default));
1284
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1246
1285
  comp = s;
1247
1286
  } else {
1248
1287
  const c = comp();
@@ -1258,7 +1297,7 @@ function lazy(fn) {
1258
1297
  return r;
1259
1298
  }));
1260
1299
  };
1261
- wrap.preload = () => comp || fn().then(mod => comp = () => mod.default);
1300
+ wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
1262
1301
  return wrap;
1263
1302
  }
1264
1303
  let counter = 0;
@@ -1318,7 +1357,11 @@ function Match(props) {
1318
1357
  return props;
1319
1358
  }
1320
1359
  function ErrorBoundary(props) {
1321
- const [errored, setErrored] = createSignal();
1360
+ let err = undefined;
1361
+ if (sharedConfig.context && sharedConfig.load) {
1362
+ err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
1363
+ }
1364
+ const [errored, setErrored] = createSignal(err);
1322
1365
  let e;
1323
1366
  return createMemo(() => {
1324
1367
  if ((e = errored()) != null) {
@@ -1402,7 +1445,8 @@ function Suspense(props) {
1402
1445
  showFallback,
1403
1446
  ctx,
1404
1447
  waitingHydration,
1405
- flicker;
1448
+ flicker,
1449
+ error;
1406
1450
  const [inFallback, setFallback] = createSignal(false),
1407
1451
  SuspenseContext = getSuspenseContext(),
1408
1452
  store = {
@@ -1417,7 +1461,7 @@ function Suspense(props) {
1417
1461
  resolved: false
1418
1462
  },
1419
1463
  owner = getOwner();
1420
- if (sharedConfig.context && sharedConfig.load) {
1464
+ if (sharedConfig.context) {
1421
1465
  const key = sharedConfig.context.id + sharedConfig.context.count;
1422
1466
  const p = sharedConfig.load(key);
1423
1467
  if (p) {
@@ -1425,7 +1469,8 @@ function Suspense(props) {
1425
1469
  equals: false
1426
1470
  });
1427
1471
  flicker = s;
1428
- p.then(() => {
1472
+ p.then(err => {
1473
+ if (error = err) return set();
1429
1474
  sharedConfig.gather(key);
1430
1475
  waitingHydration = true;
1431
1476
  setHydrateContext(ctx);
@@ -1443,6 +1488,7 @@ function Suspense(props) {
1443
1488
  value: store,
1444
1489
  get children() {
1445
1490
  return createMemo(() => {
1491
+ if (error) throw error;
1446
1492
  if (flicker) {
1447
1493
  ctx = sharedConfig.context;
1448
1494
  flicker();
@@ -1462,7 +1508,10 @@ function Suspense(props) {
1462
1508
  if (!visibleFallback) return;
1463
1509
  return createRoot(disposer => {
1464
1510
  dispose = disposer;
1465
- if (sharedConfig.context) sharedConfig.context.count = 0;
1511
+ if (sharedConfig.context) setHydrateContext({
1512
+ id: sharedConfig.context.id + "f",
1513
+ count: 0
1514
+ });
1466
1515
  return props.fallback;
1467
1516
  }, owner);
1468
1517
  });
@@ -1484,4 +1533,4 @@ if (globalThis) {
1484
1533
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
1485
1534
  }
1486
1535
 
1487
- export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1536
+ export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
package/dist/server.cjs CHANGED
@@ -41,8 +41,15 @@ function createComputed(fn, value) {
41
41
  owner: Owner,
42
42
  context: null
43
43
  };
44
- fn(value);
45
- Owner = Owner.owner;
44
+ try {
45
+ fn(value);
46
+ } catch (err) {
47
+ const fns = lookup(Owner, ERROR);
48
+ if (!fns) throw err;
49
+ fns.forEach(f => f(err));
50
+ } finally {
51
+ Owner = Owner.owner;
52
+ }
46
53
  }
47
54
  const createRenderEffect = createComputed;
48
55
  function createEffect(fn, value) {}
@@ -51,8 +58,16 @@ function createMemo(fn, value) {
51
58
  owner: Owner,
52
59
  context: null
53
60
  };
54
- const v = fn(value);
55
- Owner = Owner.owner;
61
+ let v;
62
+ try {
63
+ v = fn(value);
64
+ } catch (err) {
65
+ const fns = lookup(Owner, ERROR);
66
+ if (!fns) throw err;
67
+ fns.forEach(f => f(err));
68
+ } finally {
69
+ Owner = Owner.owner;
70
+ }
56
71
  return () => v;
57
72
  }
58
73
  function createDeferred(source) {
@@ -193,6 +208,7 @@ function from(producer) {
193
208
  }
194
209
  return s;
195
210
  }
211
+ function enableExternalSource(factory) {}
196
212
 
197
213
  function resolveSSRNode(node) {
198
214
  const t = typeof node;
@@ -290,7 +306,20 @@ function Match(props) {
290
306
  return props;
291
307
  }
292
308
  function ErrorBoundary(props) {
293
- return props.children;
309
+ let error, res;
310
+ const ctx = sharedConfig.context;
311
+ const id = ctx.id + ctx.count;
312
+ onError(err => error = err);
313
+ createMemo(() => res = props.children);
314
+ if (error) {
315
+ ctx.writeResource(id, error, true);
316
+ setHydrateContext({ ...ctx,
317
+ count: 0
318
+ });
319
+ const f = props.fallback;
320
+ return typeof f === "function" && f.length ? f(error, () => {}) : f;
321
+ }
322
+ return res;
294
323
  }
295
324
  const SuspenseContext = createContext();
296
325
  let resourceContext = null;
@@ -310,6 +339,7 @@ function createResource(fn, fetcher, options = {}) {
310
339
  let resource = {};
311
340
  let value = options.initialValue;
312
341
  let p;
342
+ let error;
313
343
  if (sharedConfig.context.async) {
314
344
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
315
345
  if (resource.ref) {
@@ -318,9 +348,10 @@ function createResource(fn, fetcher, options = {}) {
318
348
  }
319
349
  }
320
350
  const read = () => {
351
+ if (error) throw error;
321
352
  if (resourceContext && p) resourceContext.push(p);
322
353
  const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
323
- if (!resolved) {
354
+ if (!resolved && read.loading) {
324
355
  const ctx = useContext(SuspenseContext);
325
356
  if (ctx) {
326
357
  ctx.resources.set(id, read);
@@ -332,7 +363,7 @@ function createResource(fn, fetcher, options = {}) {
332
363
  read.loading = false;
333
364
  function load() {
334
365
  const ctx = sharedConfig.context;
335
- if (!ctx.async) return read.loading = true;
366
+ if (!ctx.async) return read.loading = !!(typeof fn === "function" ? fn() : fn);
336
367
  if (ctx.resources && id in ctx.resources && ctx.resources[id].data) {
337
368
  value = ctx.resources[id].data;
338
369
  return;
@@ -356,6 +387,11 @@ function createResource(fn, fetcher, options = {}) {
356
387
  p = null;
357
388
  notifySuspense(contexts);
358
389
  return res;
390
+ }).catch(err => {
391
+ read.loading = false;
392
+ error = err;
393
+ p = null;
394
+ notifySuspense(contexts);
359
395
  });
360
396
  return;
361
397
  }
@@ -390,7 +426,7 @@ function lazy(fn) {
390
426
  });
391
427
  return "";
392
428
  };
393
- wrap.preload = () => {};
429
+ wrap.preload = () => p;
394
430
  return wrap;
395
431
  }
396
432
  function suspenseComplete(c) {
@@ -418,13 +454,14 @@ function SuspenseList(props) {
418
454
  return props.children;
419
455
  }
420
456
  function Suspense(props) {
457
+ let done;
421
458
  const ctx = sharedConfig.context;
422
459
  const id = ctx.id + ctx.count;
423
- const done = ctx.async ? ctx.registerFragment(id) : () => {};
424
460
  const o = Owner;
425
461
  const value = ctx.suspense[id] || (ctx.suspense[id] = {
426
462
  resources: new Map(),
427
463
  completed: () => {
464
+ if (ctx.dataOnly) return done();
428
465
  const res = runSuspense();
429
466
  if (suspenseComplete(value)) {
430
467
  done(resolveSSRNode(res));
@@ -445,12 +482,13 @@ function Suspense(props) {
445
482
  });
446
483
  }
447
484
  const res = runSuspense();
448
- if (suspenseComplete(value)) {
449
- done();
450
- return res;
451
- }
452
- if (sharedConfig.context.async) {
453
- if (sharedConfig.context.streaming) {
485
+ if (suspenseComplete(value)) return res;
486
+ onError(err => {
487
+ if (!done || !done(undefined, err)) throw err;
488
+ });
489
+ done = ctx.async ? ctx.registerFragment(id) : undefined;
490
+ if (ctx.streaming) {
491
+ if (!ctx.dataOnly) {
454
492
  setHydrateContext(undefined);
455
493
  const res = {
456
494
  t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
@@ -458,14 +496,16 @@ function Suspense(props) {
458
496
  setHydrateContext(ctx);
459
497
  return res;
460
498
  }
499
+ } else if (ctx.async) {
461
500
  return {
462
501
  t: `<![${id}]>`
463
502
  };
464
503
  }
465
504
  setHydrateContext({ ...ctx,
466
- count: 0
505
+ count: 0,
506
+ id: ctx.id + "0.f"
467
507
  });
468
- return createComponent(() => props.fallback, {});
508
+ return props.fallback;
469
509
  }
470
510
 
471
511
  exports.$PROXY = $PROXY;
@@ -492,6 +532,7 @@ exports.createRoot = createRoot;
492
532
  exports.createSelector = createSelector;
493
533
  exports.createSignal = createSignal;
494
534
  exports.createUniqueId = createUniqueId;
535
+ exports.enableExternalSource = enableExternalSource;
495
536
  exports.enableScheduling = enableScheduling;
496
537
  exports.equalFn = equalFn;
497
538
  exports.from = from;