solid-js 2.0.0-beta.2 → 2.0.0-beta.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
@@ -208,6 +208,67 @@ function applyPatches(target, patches) {
208
208
  function isAsyncIterable(v) {
209
209
  return v != null && typeof v[Symbol.asyncIterator] === "function";
210
210
  }
211
+ function createShadowDraft(realDraft) {
212
+ const shadow = JSON.parse(JSON.stringify(realDraft));
213
+ let useShadow = true;
214
+ return {
215
+ proxy: new Proxy(shadow, {
216
+ get(_, prop) {
217
+ return useShadow ? shadow[prop] : realDraft[prop];
218
+ },
219
+ set(_, prop, value) {
220
+ if (useShadow) {
221
+ shadow[prop] = value;
222
+ return true;
223
+ }
224
+ return Reflect.set(realDraft, prop, value);
225
+ },
226
+ deleteProperty(_, prop) {
227
+ if (useShadow) {
228
+ delete shadow[prop];
229
+ return true;
230
+ }
231
+ return Reflect.deleteProperty(realDraft, prop);
232
+ },
233
+ has(_, prop) {
234
+ return prop in (useShadow ? shadow : realDraft);
235
+ },
236
+ ownKeys() {
237
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
238
+ },
239
+ getOwnPropertyDescriptor(_, prop) {
240
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
241
+ }
242
+ }),
243
+ activate() {
244
+ useShadow = false;
245
+ }
246
+ };
247
+ }
248
+ function wrapFirstYield(iterable, activate) {
249
+ const srcIt = iterable[Symbol.asyncIterator]();
250
+ let first = true;
251
+ return {
252
+ [Symbol.asyncIterator]() {
253
+ return {
254
+ next() {
255
+ const p = srcIt.next();
256
+ if (first) {
257
+ first = false;
258
+ return p.then(r => {
259
+ activate();
260
+ return r.done ? r : {
261
+ done: false,
262
+ value: undefined
263
+ };
264
+ });
265
+ }
266
+ return p;
267
+ }
268
+ };
269
+ }
270
+ };
271
+ }
211
272
  function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
212
273
  const parent = signals.getOwner();
213
274
  const expectedId = signals.peekNextChildId(parent);
@@ -259,7 +320,11 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
259
320
  next() {
260
321
  if (isFirst) {
261
322
  const r = srcIt.next();
262
- return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
323
+ return r && typeof r.then === "function" ? {
324
+ then(fn, rej) {
325
+ r.then(v => fn(process(v)), rej);
326
+ }
327
+ } : syncThenable(process(r));
263
328
  }
264
329
  if (buffered) {
265
330
  const b = buffered;
@@ -288,13 +353,15 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
288
353
  }, initialValue, options);
289
354
  }
290
355
  function hydratedCreateMemo(compute, value, options) {
291
- if (!sharedConfig.hydrating) {
356
+ if (!sharedConfig.hydrating || options?.transparent) {
292
357
  return signals.createMemo(compute, value, options);
293
358
  }
294
359
  markTopLevelSnapshotScope();
295
360
  const ssrSource = options?.ssrSource;
296
361
  if (ssrSource === "client") {
297
- const [hydrated, setHydrated] = signals.createSignal(false);
362
+ const [hydrated, setHydrated] = signals.createSignal(false, {
363
+ pureWrite: true
364
+ });
298
365
  const memo = signals.createMemo(prev => {
299
366
  if (!hydrated()) return prev ?? value;
300
367
  return compute(prev);
@@ -325,7 +392,9 @@ function hydratedCreateSignal(fn, second, third) {
325
392
  markTopLevelSnapshotScope();
326
393
  const ssrSource = third?.ssrSource;
327
394
  if (ssrSource === "client") {
328
- const [hydrated, setHydrated] = signals.createSignal(false);
395
+ const [hydrated, setHydrated] = signals.createSignal(false, {
396
+ pureWrite: true
397
+ });
329
398
  const sig = signals.createSignal(prev => {
330
399
  if (!hydrated()) return prev ?? second;
331
400
  return fn(prev);
@@ -376,7 +445,9 @@ function hydratedCreateOptimistic(fn, second, third) {
376
445
  markTopLevelSnapshotScope();
377
446
  const ssrSource = third?.ssrSource;
378
447
  if (ssrSource === "client") {
379
- const [hydrated, setHydrated] = signals.createSignal(false);
448
+ const [hydrated, setHydrated] = signals.createSignal(false, {
449
+ pureWrite: true
450
+ });
380
451
  const sig = signals.createOptimistic(prev => {
381
452
  if (!hydrated()) return prev ?? second;
382
453
  return fn(prev);
@@ -402,14 +473,7 @@ function hydratedCreateOptimistic(fn, second, third) {
402
473
  return init != null ? (subFetch(fn, prev), init) : fn(prev);
403
474
  }, second, third);
404
475
  }
405
- function wrapStoreFn(fn, ssrSource) {
406
- if (ssrSource === "initial") {
407
- return draft => {
408
- if (!sharedConfig.hydrating) return fn(draft);
409
- subFetch(fn, draft);
410
- return undefined;
411
- };
412
- }
476
+ function wrapStoreFn(fn) {
413
477
  return draft => {
414
478
  const o = signals.getOwner();
415
479
  if (!sharedConfig.hydrating) return fn(draft);
@@ -419,46 +483,77 @@ function wrapStoreFn(fn, ssrSource) {
419
483
  return init != null ? (subFetch(fn, draft), init) : fn(draft);
420
484
  };
421
485
  }
486
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
487
+ if (ssrSource === "client") {
488
+ const [hydrated, setHydrated] = signals.createSignal(false, {
489
+ pureWrite: true
490
+ });
491
+ const result = coreFn(draft => {
492
+ if (!hydrated()) return;
493
+ return fn(draft);
494
+ }, initialValue, options);
495
+ setHydrated(true);
496
+ return result;
497
+ }
498
+ if (ssrSource === "hybrid") {
499
+ const [hydrated, setHydrated] = signals.createSignal(false, {
500
+ pureWrite: true
501
+ });
502
+ const result = coreFn(draft => {
503
+ const o = signals.getOwner();
504
+ if (!hydrated()) {
505
+ if (sharedConfig.has(o.id)) {
506
+ const initP = sharedConfig.load(o.id);
507
+ const init = initP?.v ?? initP;
508
+ if (init != null) {
509
+ subFetch(fn, draft);
510
+ return init;
511
+ }
512
+ }
513
+ return fn(draft);
514
+ }
515
+ const {
516
+ proxy,
517
+ activate
518
+ } = createShadowDraft(draft);
519
+ const r = fn(proxy);
520
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
521
+ }, initialValue, options);
522
+ setHydrated(true);
523
+ return result;
524
+ }
525
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, initialValue, options);
526
+ if (aiResult !== null) return aiResult;
527
+ return coreFn(wrapStoreFn(fn), initialValue, options);
528
+ }
422
529
  function hydratedCreateStore(first, second, third) {
423
530
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
424
531
  markTopLevelSnapshotScope();
425
532
  const ssrSource = third?.ssrSource;
426
- if (ssrSource === "client" || ssrSource === "initial") {
427
- return signals.createStore(second ?? {}, undefined, third);
428
- }
429
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
430
- if (aiResult !== null) return aiResult;
431
- return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
533
+ if (ssrSource === "initial") return signals.createStore(second ?? {}, undefined, third);
534
+ return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
432
535
  }
433
536
  function hydratedCreateOptimisticStore(first, second, third) {
434
537
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
435
538
  markTopLevelSnapshotScope();
436
539
  const ssrSource = third?.ssrSource;
437
- if (ssrSource === "client" || ssrSource === "initial") {
438
- return signals.createOptimisticStore(second ?? {}, undefined, third);
439
- }
440
- const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
441
- if (aiResult !== null) return aiResult;
442
- return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
540
+ if (ssrSource === "initial") return signals.createOptimisticStore(second ?? {}, undefined, third);
541
+ return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
443
542
  }
444
543
  function hydratedCreateProjection(fn, initialValue, options) {
445
- if (!sharedConfig.hydrating) {
446
- return signals.createProjection(fn, initialValue, options);
447
- }
544
+ if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
448
545
  markTopLevelSnapshotScope();
449
546
  const ssrSource = options?.ssrSource;
450
- if (ssrSource === "client" || ssrSource === "initial") {
451
- return signals.createProjection(draft => draft, initialValue, options);
452
- }
453
- const aiResult = hydrateStoreFromAsyncIterable(signals.createProjection, initialValue, options);
454
- if (aiResult !== null) return aiResult;
455
- return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
547
+ if (ssrSource === "initial") return signals.createProjection(draft => draft, initialValue, options);
548
+ return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
456
549
  }
457
550
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
458
551
  if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
459
552
  const ssrSource = options?.ssrSource;
460
553
  if (ssrSource === "client") {
461
- const [hydrated, setHydrated] = signals.createSignal(false);
554
+ const [hydrated, setHydrated] = signals.createSignal(false, {
555
+ pureWrite: true
556
+ });
462
557
  let active = false;
463
558
  coreFn(prev => {
464
559
  if (!hydrated()) return value;
@@ -592,13 +687,16 @@ function resumeBoundaryHydration(o, id, set) {
592
687
  set();
593
688
  signals.flush();
594
689
  _snapshotRootOwner = null;
595
- _hydratingValue = false;
596
690
  signals.releaseSnapshotScope(o);
597
691
  signals.flush();
692
+ _hydratingValue = false;
598
693
  checkHydrationComplete();
599
694
  }
600
695
  function Loading(props) {
601
- if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
696
+ const onOpt = props.on ? {
697
+ on: () => props.on()
698
+ } : undefined;
699
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
602
700
  return signals.createMemo(() => {
603
701
  const o = signals.getOwner();
604
702
  const id = o.id;
@@ -646,7 +744,8 @@ function Loading(props) {
646
744
  assetPromise.then(() => resumeBoundaryHydration(o, id, set));
647
745
  return undefined;
648
746
  }
649
- return signals.createLoadBoundary(() => props.children, () => props.fallback);
747
+ const boundary = signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
748
+ return boundary;
650
749
  });
651
750
  }
652
751
  function NoHydration(props) {
@@ -818,6 +917,14 @@ Object.defineProperty(exports, "action", {
818
917
  enumerable: true,
819
918
  get: function () { return signals.action; }
820
919
  });
920
+ Object.defineProperty(exports, "createErrorBoundary", {
921
+ enumerable: true,
922
+ get: function () { return signals.createErrorBoundary; }
923
+ });
924
+ Object.defineProperty(exports, "createLoadingBoundary", {
925
+ enumerable: true,
926
+ get: function () { return signals.createLoadingBoundary; }
927
+ });
821
928
  Object.defineProperty(exports, "createOwner", {
822
929
  enumerable: true,
823
930
  get: function () { return signals.createOwner; }
@@ -838,6 +945,14 @@ Object.defineProperty(exports, "deep", {
838
945
  enumerable: true,
839
946
  get: function () { return signals.deep; }
840
947
  });
948
+ Object.defineProperty(exports, "enableExternalSource", {
949
+ enumerable: true,
950
+ get: function () { return signals.enableExternalSource; }
951
+ });
952
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
953
+ enumerable: true,
954
+ get: function () { return signals.enforceLoadingBoundary; }
955
+ });
841
956
  Object.defineProperty(exports, "flatten", {
842
957
  enumerable: true,
843
958
  get: function () { return signals.flatten; }
@@ -918,10 +1033,6 @@ Object.defineProperty(exports, "runWithOwner", {
918
1033
  enumerable: true,
919
1034
  get: function () { return signals.runWithOwner; }
920
1035
  });
921
- Object.defineProperty(exports, "setOnUnhandledAsync", {
922
- enumerable: true,
923
- get: function () { return signals.setOnUnhandledAsync; }
924
- });
925
1036
  Object.defineProperty(exports, "snapshot", {
926
1037
  enumerable: true,
927
1038
  get: function () { return signals.snapshot; }
package/dist/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getContext, createMemo as createMemo$1, flatten, getOwner, createRoot, setContext, untrack, createLoadBoundary, onCleanup, isDisposed, runWithOwner, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, mapArray, repeat } from '@solidjs/signals';
2
- export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createOwner, createReaction, createRoot, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, setOnUnhandledAsync, snapshot, storePath, untrack } from '@solidjs/signals';
1
+ import { getContext, createMemo as createMemo$1, flatten, getOwner, createRoot, setContext, untrack, createLoadingBoundary, onCleanup, isDisposed, runWithOwner, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, mapArray, repeat } from '@solidjs/signals';
2
+ export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createErrorBoundary, createLoadingBoundary, createOwner, createReaction, createRoot, createTrackedEffect, deep, enableExternalSource, enforceLoadingBoundary, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, snapshot, storePath, untrack } from '@solidjs/signals';
3
3
 
4
4
  const $DEVCOMP = Symbol("COMPONENT_DEV" );
5
5
  function createContext(defaultValue, options) {
@@ -207,6 +207,67 @@ function applyPatches(target, patches) {
207
207
  function isAsyncIterable(v) {
208
208
  return v != null && typeof v[Symbol.asyncIterator] === "function";
209
209
  }
210
+ function createShadowDraft(realDraft) {
211
+ const shadow = JSON.parse(JSON.stringify(realDraft));
212
+ let useShadow = true;
213
+ return {
214
+ proxy: new Proxy(shadow, {
215
+ get(_, prop) {
216
+ return useShadow ? shadow[prop] : realDraft[prop];
217
+ },
218
+ set(_, prop, value) {
219
+ if (useShadow) {
220
+ shadow[prop] = value;
221
+ return true;
222
+ }
223
+ return Reflect.set(realDraft, prop, value);
224
+ },
225
+ deleteProperty(_, prop) {
226
+ if (useShadow) {
227
+ delete shadow[prop];
228
+ return true;
229
+ }
230
+ return Reflect.deleteProperty(realDraft, prop);
231
+ },
232
+ has(_, prop) {
233
+ return prop in (useShadow ? shadow : realDraft);
234
+ },
235
+ ownKeys() {
236
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
237
+ },
238
+ getOwnPropertyDescriptor(_, prop) {
239
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
240
+ }
241
+ }),
242
+ activate() {
243
+ useShadow = false;
244
+ }
245
+ };
246
+ }
247
+ function wrapFirstYield(iterable, activate) {
248
+ const srcIt = iterable[Symbol.asyncIterator]();
249
+ let first = true;
250
+ return {
251
+ [Symbol.asyncIterator]() {
252
+ return {
253
+ next() {
254
+ const p = srcIt.next();
255
+ if (first) {
256
+ first = false;
257
+ return p.then(r => {
258
+ activate();
259
+ return r.done ? r : {
260
+ done: false,
261
+ value: undefined
262
+ };
263
+ });
264
+ }
265
+ return p;
266
+ }
267
+ };
268
+ }
269
+ };
270
+ }
210
271
  function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
211
272
  const parent = getOwner();
212
273
  const expectedId = peekNextChildId(parent);
@@ -258,7 +319,11 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
258
319
  next() {
259
320
  if (isFirst) {
260
321
  const r = srcIt.next();
261
- return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
322
+ return r && typeof r.then === "function" ? {
323
+ then(fn, rej) {
324
+ r.then(v => fn(process(v)), rej);
325
+ }
326
+ } : syncThenable(process(r));
262
327
  }
263
328
  if (buffered) {
264
329
  const b = buffered;
@@ -287,13 +352,15 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
287
352
  }, initialValue, options);
288
353
  }
289
354
  function hydratedCreateMemo(compute, value, options) {
290
- if (!sharedConfig.hydrating) {
355
+ if (!sharedConfig.hydrating || options?.transparent) {
291
356
  return createMemo$1(compute, value, options);
292
357
  }
293
358
  markTopLevelSnapshotScope();
294
359
  const ssrSource = options?.ssrSource;
295
360
  if (ssrSource === "client") {
296
- const [hydrated, setHydrated] = createSignal$1(false);
361
+ const [hydrated, setHydrated] = createSignal$1(false, {
362
+ pureWrite: true
363
+ });
297
364
  const memo = createMemo$1(prev => {
298
365
  if (!hydrated()) return prev ?? value;
299
366
  return compute(prev);
@@ -324,7 +391,9 @@ function hydratedCreateSignal(fn, second, third) {
324
391
  markTopLevelSnapshotScope();
325
392
  const ssrSource = third?.ssrSource;
326
393
  if (ssrSource === "client") {
327
- const [hydrated, setHydrated] = createSignal$1(false);
394
+ const [hydrated, setHydrated] = createSignal$1(false, {
395
+ pureWrite: true
396
+ });
328
397
  const sig = createSignal$1(prev => {
329
398
  if (!hydrated()) return prev ?? second;
330
399
  return fn(prev);
@@ -375,7 +444,9 @@ function hydratedCreateOptimistic(fn, second, third) {
375
444
  markTopLevelSnapshotScope();
376
445
  const ssrSource = third?.ssrSource;
377
446
  if (ssrSource === "client") {
378
- const [hydrated, setHydrated] = createSignal$1(false);
447
+ const [hydrated, setHydrated] = createSignal$1(false, {
448
+ pureWrite: true
449
+ });
379
450
  const sig = createOptimistic$1(prev => {
380
451
  if (!hydrated()) return prev ?? second;
381
452
  return fn(prev);
@@ -401,14 +472,7 @@ function hydratedCreateOptimistic(fn, second, third) {
401
472
  return init != null ? (subFetch(fn, prev), init) : fn(prev);
402
473
  }, second, third);
403
474
  }
404
- function wrapStoreFn(fn, ssrSource) {
405
- if (ssrSource === "initial") {
406
- return draft => {
407
- if (!sharedConfig.hydrating) return fn(draft);
408
- subFetch(fn, draft);
409
- return undefined;
410
- };
411
- }
475
+ function wrapStoreFn(fn) {
412
476
  return draft => {
413
477
  const o = getOwner();
414
478
  if (!sharedConfig.hydrating) return fn(draft);
@@ -418,46 +482,77 @@ function wrapStoreFn(fn, ssrSource) {
418
482
  return init != null ? (subFetch(fn, draft), init) : fn(draft);
419
483
  };
420
484
  }
485
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
486
+ if (ssrSource === "client") {
487
+ const [hydrated, setHydrated] = createSignal$1(false, {
488
+ pureWrite: true
489
+ });
490
+ const result = coreFn(draft => {
491
+ if (!hydrated()) return;
492
+ return fn(draft);
493
+ }, initialValue, options);
494
+ setHydrated(true);
495
+ return result;
496
+ }
497
+ if (ssrSource === "hybrid") {
498
+ const [hydrated, setHydrated] = createSignal$1(false, {
499
+ pureWrite: true
500
+ });
501
+ const result = coreFn(draft => {
502
+ const o = getOwner();
503
+ if (!hydrated()) {
504
+ if (sharedConfig.has(o.id)) {
505
+ const initP = sharedConfig.load(o.id);
506
+ const init = initP?.v ?? initP;
507
+ if (init != null) {
508
+ subFetch(fn, draft);
509
+ return init;
510
+ }
511
+ }
512
+ return fn(draft);
513
+ }
514
+ const {
515
+ proxy,
516
+ activate
517
+ } = createShadowDraft(draft);
518
+ const r = fn(proxy);
519
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
520
+ }, initialValue, options);
521
+ setHydrated(true);
522
+ return result;
523
+ }
524
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, initialValue, options);
525
+ if (aiResult !== null) return aiResult;
526
+ return coreFn(wrapStoreFn(fn), initialValue, options);
527
+ }
421
528
  function hydratedCreateStore(first, second, third) {
422
529
  if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
423
530
  markTopLevelSnapshotScope();
424
531
  const ssrSource = third?.ssrSource;
425
- if (ssrSource === "client" || ssrSource === "initial") {
426
- return createStore$1(second ?? {}, undefined, third);
427
- }
428
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
429
- if (aiResult !== null) return aiResult;
430
- return createStore$1(wrapStoreFn(first, ssrSource), second, third);
532
+ if (ssrSource === "initial") return createStore$1(second ?? {}, undefined, third);
533
+ return hydrateStoreLikeFn(createStore$1, first, second ?? {}, third, ssrSource);
431
534
  }
432
535
  function hydratedCreateOptimisticStore(first, second, third) {
433
536
  if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
434
537
  markTopLevelSnapshotScope();
435
538
  const ssrSource = third?.ssrSource;
436
- if (ssrSource === "client" || ssrSource === "initial") {
437
- return createOptimisticStore$1(second ?? {}, undefined, third);
438
- }
439
- const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
440
- if (aiResult !== null) return aiResult;
441
- return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
539
+ if (ssrSource === "initial") return createOptimisticStore$1(second ?? {}, undefined, third);
540
+ return hydrateStoreLikeFn(createOptimisticStore$1, first, second ?? {}, third, ssrSource);
442
541
  }
443
542
  function hydratedCreateProjection(fn, initialValue, options) {
444
- if (!sharedConfig.hydrating) {
445
- return createProjection$1(fn, initialValue, options);
446
- }
543
+ if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
447
544
  markTopLevelSnapshotScope();
448
545
  const ssrSource = options?.ssrSource;
449
- if (ssrSource === "client" || ssrSource === "initial") {
450
- return createProjection$1(draft => draft, initialValue, options);
451
- }
452
- const aiResult = hydrateStoreFromAsyncIterable(createProjection$1, initialValue, options);
453
- if (aiResult !== null) return aiResult;
454
- return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
546
+ if (ssrSource === "initial") return createProjection$1(draft => draft, initialValue, options);
547
+ return hydrateStoreLikeFn(createProjection$1, fn, initialValue, options, ssrSource);
455
548
  }
456
549
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
457
550
  if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
458
551
  const ssrSource = options?.ssrSource;
459
552
  if (ssrSource === "client") {
460
- const [hydrated, setHydrated] = createSignal$1(false);
553
+ const [hydrated, setHydrated] = createSignal$1(false, {
554
+ pureWrite: true
555
+ });
461
556
  let active = false;
462
557
  coreFn(prev => {
463
558
  if (!hydrated()) return value;
@@ -591,13 +686,16 @@ function resumeBoundaryHydration(o, id, set) {
591
686
  set();
592
687
  flush();
593
688
  _snapshotRootOwner = null;
594
- _hydratingValue = false;
595
689
  releaseSnapshotScope(o);
596
690
  flush();
691
+ _hydratingValue = false;
597
692
  checkHydrationComplete();
598
693
  }
599
694
  function Loading(props) {
600
- if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
695
+ const onOpt = props.on ? {
696
+ on: () => props.on()
697
+ } : undefined;
698
+ if (!sharedConfig.hydrating) return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
601
699
  return createMemo$1(() => {
602
700
  const o = getOwner();
603
701
  const id = o.id;
@@ -645,7 +743,8 @@ function Loading(props) {
645
743
  assetPromise.then(() => resumeBoundaryHydration(o, id, set));
646
744
  return undefined;
647
745
  }
648
- return createLoadBoundary(() => props.children, () => props.fallback);
746
+ const boundary = createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
747
+ return boundary;
649
748
  });
650
749
  }
651
750
  function NoHydration(props) {
package/dist/server.cjs CHANGED
@@ -493,7 +493,7 @@ function createErrorBoundary(fn, fallback) {
493
493
  return () => result;
494
494
  });
495
495
  }
496
- function createLoadBoundary(fn, fallback) {
496
+ function createLoadingBoundary(fn, fallback, options) {
497
497
  try {
498
498
  const result = fn();
499
499
  return () => result;
@@ -701,7 +701,7 @@ function ssrHandleError(err) {
701
701
  function Loading(props) {
702
702
  const ctx = sharedConfig.context;
703
703
  if (!ctx) {
704
- return createLoadBoundary(() => props.children, () => props.fallback);
704
+ return createLoadingBoundary(() => props.children, () => props.fallback);
705
705
  }
706
706
  const o = signals.createOwner();
707
707
  const id = o.id;
@@ -814,6 +814,14 @@ Object.defineProperty(exports, "createRoot", {
814
814
  enumerable: true,
815
815
  get: function () { return signals.createRoot; }
816
816
  });
817
+ Object.defineProperty(exports, "enableExternalSource", {
818
+ enumerable: true,
819
+ get: function () { return signals.enableExternalSource; }
820
+ });
821
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
822
+ enumerable: true,
823
+ get: function () { return signals.enforceLoadingBoundary; }
824
+ });
817
825
  Object.defineProperty(exports, "flatten", {
818
826
  enumerable: true,
819
827
  get: function () { return signals.flatten; }
@@ -850,10 +858,6 @@ Object.defineProperty(exports, "runWithOwner", {
850
858
  enumerable: true,
851
859
  get: function () { return signals.runWithOwner; }
852
860
  });
853
- Object.defineProperty(exports, "setOnUnhandledAsync", {
854
- enumerable: true,
855
- get: function () { return signals.setOnUnhandledAsync; }
856
- });
857
861
  Object.defineProperty(exports, "snapshot", {
858
862
  enumerable: true,
859
863
  get: function () { return signals.snapshot; }
@@ -880,6 +884,8 @@ exports.createComponent = createComponent;
880
884
  exports.createContext = createContext;
881
885
  exports.createDeepProxy = createDeepProxy;
882
886
  exports.createEffect = createEffect;
887
+ exports.createErrorBoundary = createErrorBoundary;
888
+ exports.createLoadingBoundary = createLoadingBoundary;
883
889
  exports.createMemo = createMemo;
884
890
  exports.createOptimistic = createOptimistic;
885
891
  exports.createOptimisticStore = createOptimisticStore;
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getOwner, getContext, getNextChildId, createOwner, runWithOwner, onCleanup, NotReadyError, isWrappable, setContext, flatten, createRoot } from '@solidjs/signals';
2
- export { $PROXY, $REFRESH, $TRACK, NotReadyError, createOwner, createRoot, flatten, getNextChildId, getOwner, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, setOnUnhandledAsync, snapshot, storePath } from '@solidjs/signals';
1
+ import { getOwner, getContext, getNextChildId, createOwner, runWithOwner, setContext, NotReadyError, onCleanup, isWrappable, flatten, createRoot } from '@solidjs/signals';
2
+ export { $PROXY, $REFRESH, $TRACK, NotReadyError, createOwner, createRoot, enableExternalSource, enforceLoadingBoundary, flatten, getNextChildId, getOwner, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot, storePath } from '@solidjs/signals';
3
3
 
4
4
  const NoHydrateContext = {
5
5
  id: Symbol("NoHydrateContext"),
@@ -492,7 +492,7 @@ function createErrorBoundary(fn, fallback) {
492
492
  return () => result;
493
493
  });
494
494
  }
495
- function createLoadBoundary(fn, fallback) {
495
+ function createLoadingBoundary(fn, fallback, options) {
496
496
  try {
497
497
  const result = fn();
498
498
  return () => result;
@@ -700,7 +700,7 @@ function ssrHandleError(err) {
700
700
  function Loading(props) {
701
701
  const ctx = sharedConfig.context;
702
702
  if (!ctx) {
703
- return createLoadBoundary(() => props.children, () => props.fallback);
703
+ return createLoadingBoundary(() => props.children, () => props.fallback);
704
704
  }
705
705
  const o = createOwner();
706
706
  const id = o.id;
@@ -789,4 +789,4 @@ function Hydration(props) {
789
789
 
790
790
  const DEV = undefined;
791
791
 
792
- export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, latest, lazy, mapArray, onSettled, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
792
+ export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createErrorBoundary, createLoadingBoundary, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, latest, lazy, mapArray, onSettled, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
package/dist/solid.cjs CHANGED
@@ -187,6 +187,67 @@ function applyPatches(target, patches) {
187
187
  function isAsyncIterable(v) {
188
188
  return v != null && typeof v[Symbol.asyncIterator] === "function";
189
189
  }
190
+ function createShadowDraft(realDraft) {
191
+ const shadow = JSON.parse(JSON.stringify(realDraft));
192
+ let useShadow = true;
193
+ return {
194
+ proxy: new Proxy(shadow, {
195
+ get(_, prop) {
196
+ return useShadow ? shadow[prop] : realDraft[prop];
197
+ },
198
+ set(_, prop, value) {
199
+ if (useShadow) {
200
+ shadow[prop] = value;
201
+ return true;
202
+ }
203
+ return Reflect.set(realDraft, prop, value);
204
+ },
205
+ deleteProperty(_, prop) {
206
+ if (useShadow) {
207
+ delete shadow[prop];
208
+ return true;
209
+ }
210
+ return Reflect.deleteProperty(realDraft, prop);
211
+ },
212
+ has(_, prop) {
213
+ return prop in (useShadow ? shadow : realDraft);
214
+ },
215
+ ownKeys() {
216
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
217
+ },
218
+ getOwnPropertyDescriptor(_, prop) {
219
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
220
+ }
221
+ }),
222
+ activate() {
223
+ useShadow = false;
224
+ }
225
+ };
226
+ }
227
+ function wrapFirstYield(iterable, activate) {
228
+ const srcIt = iterable[Symbol.asyncIterator]();
229
+ let first = true;
230
+ return {
231
+ [Symbol.asyncIterator]() {
232
+ return {
233
+ next() {
234
+ const p = srcIt.next();
235
+ if (first) {
236
+ first = false;
237
+ return p.then(r => {
238
+ activate();
239
+ return r.done ? r : {
240
+ done: false,
241
+ value: undefined
242
+ };
243
+ });
244
+ }
245
+ return p;
246
+ }
247
+ };
248
+ }
249
+ };
250
+ }
190
251
  function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
191
252
  const parent = signals.getOwner();
192
253
  const expectedId = signals.peekNextChildId(parent);
@@ -238,7 +299,11 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
238
299
  next() {
239
300
  if (isFirst) {
240
301
  const r = srcIt.next();
241
- return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
302
+ return r && typeof r.then === "function" ? {
303
+ then(fn, rej) {
304
+ r.then(v => fn(process(v)), rej);
305
+ }
306
+ } : syncThenable(process(r));
242
307
  }
243
308
  if (buffered) {
244
309
  const b = buffered;
@@ -267,13 +332,15 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
267
332
  }, initialValue, options);
268
333
  }
269
334
  function hydratedCreateMemo(compute, value, options) {
270
- if (!sharedConfig.hydrating) {
335
+ if (!sharedConfig.hydrating || options?.transparent) {
271
336
  return signals.createMemo(compute, value, options);
272
337
  }
273
338
  markTopLevelSnapshotScope();
274
339
  const ssrSource = options?.ssrSource;
275
340
  if (ssrSource === "client") {
276
- const [hydrated, setHydrated] = signals.createSignal(false);
341
+ const [hydrated, setHydrated] = signals.createSignal(false, {
342
+ pureWrite: true
343
+ });
277
344
  const memo = signals.createMemo(prev => {
278
345
  if (!hydrated()) return prev ?? value;
279
346
  return compute(prev);
@@ -304,7 +371,9 @@ function hydratedCreateSignal(fn, second, third) {
304
371
  markTopLevelSnapshotScope();
305
372
  const ssrSource = third?.ssrSource;
306
373
  if (ssrSource === "client") {
307
- const [hydrated, setHydrated] = signals.createSignal(false);
374
+ const [hydrated, setHydrated] = signals.createSignal(false, {
375
+ pureWrite: true
376
+ });
308
377
  const sig = signals.createSignal(prev => {
309
378
  if (!hydrated()) return prev ?? second;
310
379
  return fn(prev);
@@ -355,7 +424,9 @@ function hydratedCreateOptimistic(fn, second, third) {
355
424
  markTopLevelSnapshotScope();
356
425
  const ssrSource = third?.ssrSource;
357
426
  if (ssrSource === "client") {
358
- const [hydrated, setHydrated] = signals.createSignal(false);
427
+ const [hydrated, setHydrated] = signals.createSignal(false, {
428
+ pureWrite: true
429
+ });
359
430
  const sig = signals.createOptimistic(prev => {
360
431
  if (!hydrated()) return prev ?? second;
361
432
  return fn(prev);
@@ -381,14 +452,7 @@ function hydratedCreateOptimistic(fn, second, third) {
381
452
  return init != null ? (subFetch(fn, prev), init) : fn(prev);
382
453
  }, second, third);
383
454
  }
384
- function wrapStoreFn(fn, ssrSource) {
385
- if (ssrSource === "initial") {
386
- return draft => {
387
- if (!sharedConfig.hydrating) return fn(draft);
388
- subFetch(fn, draft);
389
- return undefined;
390
- };
391
- }
455
+ function wrapStoreFn(fn) {
392
456
  return draft => {
393
457
  const o = signals.getOwner();
394
458
  if (!sharedConfig.hydrating) return fn(draft);
@@ -398,46 +462,77 @@ function wrapStoreFn(fn, ssrSource) {
398
462
  return init != null ? (subFetch(fn, draft), init) : fn(draft);
399
463
  };
400
464
  }
465
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
466
+ if (ssrSource === "client") {
467
+ const [hydrated, setHydrated] = signals.createSignal(false, {
468
+ pureWrite: true
469
+ });
470
+ const result = coreFn(draft => {
471
+ if (!hydrated()) return;
472
+ return fn(draft);
473
+ }, initialValue, options);
474
+ setHydrated(true);
475
+ return result;
476
+ }
477
+ if (ssrSource === "hybrid") {
478
+ const [hydrated, setHydrated] = signals.createSignal(false, {
479
+ pureWrite: true
480
+ });
481
+ const result = coreFn(draft => {
482
+ const o = signals.getOwner();
483
+ if (!hydrated()) {
484
+ if (sharedConfig.has(o.id)) {
485
+ const initP = sharedConfig.load(o.id);
486
+ const init = initP?.v ?? initP;
487
+ if (init != null) {
488
+ subFetch(fn, draft);
489
+ return init;
490
+ }
491
+ }
492
+ return fn(draft);
493
+ }
494
+ const {
495
+ proxy,
496
+ activate
497
+ } = createShadowDraft(draft);
498
+ const r = fn(proxy);
499
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
500
+ }, initialValue, options);
501
+ setHydrated(true);
502
+ return result;
503
+ }
504
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, initialValue, options);
505
+ if (aiResult !== null) return aiResult;
506
+ return coreFn(wrapStoreFn(fn), initialValue, options);
507
+ }
401
508
  function hydratedCreateStore(first, second, third) {
402
509
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
403
510
  markTopLevelSnapshotScope();
404
511
  const ssrSource = third?.ssrSource;
405
- if (ssrSource === "client" || ssrSource === "initial") {
406
- return signals.createStore(second ?? {}, undefined, third);
407
- }
408
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
409
- if (aiResult !== null) return aiResult;
410
- return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
512
+ if (ssrSource === "initial") return signals.createStore(second ?? {}, undefined, third);
513
+ return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
411
514
  }
412
515
  function hydratedCreateOptimisticStore(first, second, third) {
413
516
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
414
517
  markTopLevelSnapshotScope();
415
518
  const ssrSource = third?.ssrSource;
416
- if (ssrSource === "client" || ssrSource === "initial") {
417
- return signals.createOptimisticStore(second ?? {}, undefined, third);
418
- }
419
- const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
420
- if (aiResult !== null) return aiResult;
421
- return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
519
+ if (ssrSource === "initial") return signals.createOptimisticStore(second ?? {}, undefined, third);
520
+ return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
422
521
  }
423
522
  function hydratedCreateProjection(fn, initialValue, options) {
424
- if (!sharedConfig.hydrating) {
425
- return signals.createProjection(fn, initialValue, options);
426
- }
523
+ if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
427
524
  markTopLevelSnapshotScope();
428
525
  const ssrSource = options?.ssrSource;
429
- if (ssrSource === "client" || ssrSource === "initial") {
430
- return signals.createProjection(draft => draft, initialValue, options);
431
- }
432
- const aiResult = hydrateStoreFromAsyncIterable(signals.createProjection, initialValue, options);
433
- if (aiResult !== null) return aiResult;
434
- return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
526
+ if (ssrSource === "initial") return signals.createProjection(draft => draft, initialValue, options);
527
+ return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
435
528
  }
436
529
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
437
530
  if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
438
531
  const ssrSource = options?.ssrSource;
439
532
  if (ssrSource === "client") {
440
- const [hydrated, setHydrated] = signals.createSignal(false);
533
+ const [hydrated, setHydrated] = signals.createSignal(false, {
534
+ pureWrite: true
535
+ });
441
536
  let active = false;
442
537
  coreFn(prev => {
443
538
  if (!hydrated()) return value;
@@ -571,13 +666,16 @@ function resumeBoundaryHydration(o, id, set) {
571
666
  set();
572
667
  signals.flush();
573
668
  _snapshotRootOwner = null;
574
- _hydratingValue = false;
575
669
  signals.releaseSnapshotScope(o);
576
670
  signals.flush();
671
+ _hydratingValue = false;
577
672
  checkHydrationComplete();
578
673
  }
579
674
  function Loading(props) {
580
- if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
675
+ const onOpt = props.on ? {
676
+ on: () => props.on()
677
+ } : undefined;
678
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
581
679
  return signals.createMemo(() => {
582
680
  const o = signals.getOwner();
583
681
  const id = o.id;
@@ -625,7 +723,8 @@ function Loading(props) {
625
723
  assetPromise.then(() => resumeBoundaryHydration(o, id, set));
626
724
  return undefined;
627
725
  }
628
- return signals.createLoadBoundary(() => props.children, () => props.fallback);
726
+ const boundary = signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
727
+ return boundary;
629
728
  });
630
729
  }
631
730
  function NoHydration(props) {
@@ -774,6 +873,14 @@ Object.defineProperty(exports, "action", {
774
873
  enumerable: true,
775
874
  get: function () { return signals.action; }
776
875
  });
876
+ Object.defineProperty(exports, "createErrorBoundary", {
877
+ enumerable: true,
878
+ get: function () { return signals.createErrorBoundary; }
879
+ });
880
+ Object.defineProperty(exports, "createLoadingBoundary", {
881
+ enumerable: true,
882
+ get: function () { return signals.createLoadingBoundary; }
883
+ });
777
884
  Object.defineProperty(exports, "createOwner", {
778
885
  enumerable: true,
779
886
  get: function () { return signals.createOwner; }
@@ -794,6 +901,14 @@ Object.defineProperty(exports, "deep", {
794
901
  enumerable: true,
795
902
  get: function () { return signals.deep; }
796
903
  });
904
+ Object.defineProperty(exports, "enableExternalSource", {
905
+ enumerable: true,
906
+ get: function () { return signals.enableExternalSource; }
907
+ });
908
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
909
+ enumerable: true,
910
+ get: function () { return signals.enforceLoadingBoundary; }
911
+ });
797
912
  Object.defineProperty(exports, "flatten", {
798
913
  enumerable: true,
799
914
  get: function () { return signals.flatten; }
@@ -874,10 +989,6 @@ Object.defineProperty(exports, "runWithOwner", {
874
989
  enumerable: true,
875
990
  get: function () { return signals.runWithOwner; }
876
991
  });
877
- Object.defineProperty(exports, "setOnUnhandledAsync", {
878
- enumerable: true,
879
- get: function () { return signals.setOnUnhandledAsync; }
880
- });
881
992
  Object.defineProperty(exports, "snapshot", {
882
993
  enumerable: true,
883
994
  get: function () { return signals.snapshot; }
package/dist/solid.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getContext, createMemo as createMemo$1, flatten, createRoot, setContext, createLoadBoundary, getOwner, onCleanup, isDisposed, runWithOwner, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, untrack, mapArray, repeat } from '@solidjs/signals';
2
- export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createOwner, createReaction, createRoot, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, setOnUnhandledAsync, snapshot, storePath, untrack } from '@solidjs/signals';
1
+ import { getContext, createMemo as createMemo$1, flatten, createRoot, setContext, createLoadingBoundary, getOwner, onCleanup, isDisposed, runWithOwner, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, untrack, mapArray, repeat } from '@solidjs/signals';
2
+ export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createErrorBoundary, createLoadingBoundary, createOwner, createReaction, createRoot, createTrackedEffect, deep, enableExternalSource, enforceLoadingBoundary, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, snapshot, storePath, untrack } from '@solidjs/signals';
3
3
 
4
4
  const IS_DEV = false;
5
5
  const $DEVCOMP = Symbol(0);
@@ -186,6 +186,67 @@ function applyPatches(target, patches) {
186
186
  function isAsyncIterable(v) {
187
187
  return v != null && typeof v[Symbol.asyncIterator] === "function";
188
188
  }
189
+ function createShadowDraft(realDraft) {
190
+ const shadow = JSON.parse(JSON.stringify(realDraft));
191
+ let useShadow = true;
192
+ return {
193
+ proxy: new Proxy(shadow, {
194
+ get(_, prop) {
195
+ return useShadow ? shadow[prop] : realDraft[prop];
196
+ },
197
+ set(_, prop, value) {
198
+ if (useShadow) {
199
+ shadow[prop] = value;
200
+ return true;
201
+ }
202
+ return Reflect.set(realDraft, prop, value);
203
+ },
204
+ deleteProperty(_, prop) {
205
+ if (useShadow) {
206
+ delete shadow[prop];
207
+ return true;
208
+ }
209
+ return Reflect.deleteProperty(realDraft, prop);
210
+ },
211
+ has(_, prop) {
212
+ return prop in (useShadow ? shadow : realDraft);
213
+ },
214
+ ownKeys() {
215
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
216
+ },
217
+ getOwnPropertyDescriptor(_, prop) {
218
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
219
+ }
220
+ }),
221
+ activate() {
222
+ useShadow = false;
223
+ }
224
+ };
225
+ }
226
+ function wrapFirstYield(iterable, activate) {
227
+ const srcIt = iterable[Symbol.asyncIterator]();
228
+ let first = true;
229
+ return {
230
+ [Symbol.asyncIterator]() {
231
+ return {
232
+ next() {
233
+ const p = srcIt.next();
234
+ if (first) {
235
+ first = false;
236
+ return p.then(r => {
237
+ activate();
238
+ return r.done ? r : {
239
+ done: false,
240
+ value: undefined
241
+ };
242
+ });
243
+ }
244
+ return p;
245
+ }
246
+ };
247
+ }
248
+ };
249
+ }
189
250
  function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
190
251
  const parent = getOwner();
191
252
  const expectedId = peekNextChildId(parent);
@@ -237,7 +298,11 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
237
298
  next() {
238
299
  if (isFirst) {
239
300
  const r = srcIt.next();
240
- return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
301
+ return r && typeof r.then === "function" ? {
302
+ then(fn, rej) {
303
+ r.then(v => fn(process(v)), rej);
304
+ }
305
+ } : syncThenable(process(r));
241
306
  }
242
307
  if (buffered) {
243
308
  const b = buffered;
@@ -266,13 +331,15 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
266
331
  }, initialValue, options);
267
332
  }
268
333
  function hydratedCreateMemo(compute, value, options) {
269
- if (!sharedConfig.hydrating) {
334
+ if (!sharedConfig.hydrating || options?.transparent) {
270
335
  return createMemo$1(compute, value, options);
271
336
  }
272
337
  markTopLevelSnapshotScope();
273
338
  const ssrSource = options?.ssrSource;
274
339
  if (ssrSource === "client") {
275
- const [hydrated, setHydrated] = createSignal$1(false);
340
+ const [hydrated, setHydrated] = createSignal$1(false, {
341
+ pureWrite: true
342
+ });
276
343
  const memo = createMemo$1(prev => {
277
344
  if (!hydrated()) return prev ?? value;
278
345
  return compute(prev);
@@ -303,7 +370,9 @@ function hydratedCreateSignal(fn, second, third) {
303
370
  markTopLevelSnapshotScope();
304
371
  const ssrSource = third?.ssrSource;
305
372
  if (ssrSource === "client") {
306
- const [hydrated, setHydrated] = createSignal$1(false);
373
+ const [hydrated, setHydrated] = createSignal$1(false, {
374
+ pureWrite: true
375
+ });
307
376
  const sig = createSignal$1(prev => {
308
377
  if (!hydrated()) return prev ?? second;
309
378
  return fn(prev);
@@ -354,7 +423,9 @@ function hydratedCreateOptimistic(fn, second, third) {
354
423
  markTopLevelSnapshotScope();
355
424
  const ssrSource = third?.ssrSource;
356
425
  if (ssrSource === "client") {
357
- const [hydrated, setHydrated] = createSignal$1(false);
426
+ const [hydrated, setHydrated] = createSignal$1(false, {
427
+ pureWrite: true
428
+ });
358
429
  const sig = createOptimistic$1(prev => {
359
430
  if (!hydrated()) return prev ?? second;
360
431
  return fn(prev);
@@ -380,14 +451,7 @@ function hydratedCreateOptimistic(fn, second, third) {
380
451
  return init != null ? (subFetch(fn, prev), init) : fn(prev);
381
452
  }, second, third);
382
453
  }
383
- function wrapStoreFn(fn, ssrSource) {
384
- if (ssrSource === "initial") {
385
- return draft => {
386
- if (!sharedConfig.hydrating) return fn(draft);
387
- subFetch(fn, draft);
388
- return undefined;
389
- };
390
- }
454
+ function wrapStoreFn(fn) {
391
455
  return draft => {
392
456
  const o = getOwner();
393
457
  if (!sharedConfig.hydrating) return fn(draft);
@@ -397,46 +461,77 @@ function wrapStoreFn(fn, ssrSource) {
397
461
  return init != null ? (subFetch(fn, draft), init) : fn(draft);
398
462
  };
399
463
  }
464
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
465
+ if (ssrSource === "client") {
466
+ const [hydrated, setHydrated] = createSignal$1(false, {
467
+ pureWrite: true
468
+ });
469
+ const result = coreFn(draft => {
470
+ if (!hydrated()) return;
471
+ return fn(draft);
472
+ }, initialValue, options);
473
+ setHydrated(true);
474
+ return result;
475
+ }
476
+ if (ssrSource === "hybrid") {
477
+ const [hydrated, setHydrated] = createSignal$1(false, {
478
+ pureWrite: true
479
+ });
480
+ const result = coreFn(draft => {
481
+ const o = getOwner();
482
+ if (!hydrated()) {
483
+ if (sharedConfig.has(o.id)) {
484
+ const initP = sharedConfig.load(o.id);
485
+ const init = initP?.v ?? initP;
486
+ if (init != null) {
487
+ subFetch(fn, draft);
488
+ return init;
489
+ }
490
+ }
491
+ return fn(draft);
492
+ }
493
+ const {
494
+ proxy,
495
+ activate
496
+ } = createShadowDraft(draft);
497
+ const r = fn(proxy);
498
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
499
+ }, initialValue, options);
500
+ setHydrated(true);
501
+ return result;
502
+ }
503
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, initialValue, options);
504
+ if (aiResult !== null) return aiResult;
505
+ return coreFn(wrapStoreFn(fn), initialValue, options);
506
+ }
400
507
  function hydratedCreateStore(first, second, third) {
401
508
  if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
402
509
  markTopLevelSnapshotScope();
403
510
  const ssrSource = third?.ssrSource;
404
- if (ssrSource === "client" || ssrSource === "initial") {
405
- return createStore$1(second ?? {}, undefined, third);
406
- }
407
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
408
- if (aiResult !== null) return aiResult;
409
- return createStore$1(wrapStoreFn(first, ssrSource), second, third);
511
+ if (ssrSource === "initial") return createStore$1(second ?? {}, undefined, third);
512
+ return hydrateStoreLikeFn(createStore$1, first, second ?? {}, third, ssrSource);
410
513
  }
411
514
  function hydratedCreateOptimisticStore(first, second, third) {
412
515
  if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
413
516
  markTopLevelSnapshotScope();
414
517
  const ssrSource = third?.ssrSource;
415
- if (ssrSource === "client" || ssrSource === "initial") {
416
- return createOptimisticStore$1(second ?? {}, undefined, third);
417
- }
418
- const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
419
- if (aiResult !== null) return aiResult;
420
- return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
518
+ if (ssrSource === "initial") return createOptimisticStore$1(second ?? {}, undefined, third);
519
+ return hydrateStoreLikeFn(createOptimisticStore$1, first, second ?? {}, third, ssrSource);
421
520
  }
422
521
  function hydratedCreateProjection(fn, initialValue, options) {
423
- if (!sharedConfig.hydrating) {
424
- return createProjection$1(fn, initialValue, options);
425
- }
522
+ if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
426
523
  markTopLevelSnapshotScope();
427
524
  const ssrSource = options?.ssrSource;
428
- if (ssrSource === "client" || ssrSource === "initial") {
429
- return createProjection$1(draft => draft, initialValue, options);
430
- }
431
- const aiResult = hydrateStoreFromAsyncIterable(createProjection$1, initialValue, options);
432
- if (aiResult !== null) return aiResult;
433
- return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
525
+ if (ssrSource === "initial") return createProjection$1(draft => draft, initialValue, options);
526
+ return hydrateStoreLikeFn(createProjection$1, fn, initialValue, options, ssrSource);
434
527
  }
435
528
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
436
529
  if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
437
530
  const ssrSource = options?.ssrSource;
438
531
  if (ssrSource === "client") {
439
- const [hydrated, setHydrated] = createSignal$1(false);
532
+ const [hydrated, setHydrated] = createSignal$1(false, {
533
+ pureWrite: true
534
+ });
440
535
  let active = false;
441
536
  coreFn(prev => {
442
537
  if (!hydrated()) return value;
@@ -570,13 +665,16 @@ function resumeBoundaryHydration(o, id, set) {
570
665
  set();
571
666
  flush();
572
667
  _snapshotRootOwner = null;
573
- _hydratingValue = false;
574
668
  releaseSnapshotScope(o);
575
669
  flush();
670
+ _hydratingValue = false;
576
671
  checkHydrationComplete();
577
672
  }
578
673
  function Loading(props) {
579
- if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
674
+ const onOpt = props.on ? {
675
+ on: () => props.on()
676
+ } : undefined;
677
+ if (!sharedConfig.hydrating) return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
580
678
  return createMemo$1(() => {
581
679
  const o = getOwner();
582
680
  const id = o.id;
@@ -624,7 +722,8 @@ function Loading(props) {
624
722
  assetPromise.then(() => resumeBoundaryHydration(o, id, set));
625
723
  return undefined;
626
724
  }
627
- return createLoadBoundary(() => props.children, () => props.fallback);
725
+ const boundary = createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
726
+ return boundary;
628
727
  });
629
728
  }
630
729
  function NoHydration(props) {
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": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.3",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -79,7 +79,7 @@
79
79
  "performance"
80
80
  ],
81
81
  "dependencies": {
82
- "@solidjs/signals": "^0.12.0",
82
+ "@solidjs/signals": "^0.13.3",
83
83
  "csstype": "^3.1.0",
84
84
  "seroval": "~1.5.0",
85
85
  "seroval-plugins": "~1.5.0"
@@ -78,6 +78,7 @@ export declare const createEffect: typeof coreEffect;
78
78
  */
79
79
  export declare function Loading(props: {
80
80
  fallback?: JSX.Element;
81
+ on?: () => any;
81
82
  children: JSX.Element;
82
83
  }): JSX.Element;
83
84
  /**
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { $PROXY, $REFRESH, $TRACK, action, createOwner, createReaction, createRoot, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isRefreshing, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, latest, reconcile, refresh, repeat, resolve, NotReadyError, runWithOwner, setOnUnhandledAsync, snapshot, storePath, untrack } from "@solidjs/signals";
2
- export type { Accessor, ComputeFunction, EffectFunction, EffectOptions, Merge, NoInfer, NotWrappable, Omit, Owner, Signal, SignalOptions, Setter, Store, SolidStore, StoreNode, StoreSetter, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter } from "@solidjs/signals";
1
+ export { $PROXY, $REFRESH, $TRACK, action, createErrorBoundary, createLoadingBoundary, createOwner, createReaction, createRoot, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isRefreshing, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, latest, reconcile, refresh, repeat, resolve, NotReadyError, runWithOwner, enableExternalSource, enforceLoadingBoundary, snapshot, storePath, untrack } from "@solidjs/signals";
2
+ export type { Accessor, ComputeFunction, EffectFunction, EffectOptions, ExternalSource, ExternalSourceConfig, ExternalSourceFactory, Merge, NoInfer, NotWrappable, Omit, Owner, Signal, SignalOptions, Setter, Store, SolidStore, StoreNode, StoreSetter, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter } from "@solidjs/signals";
3
3
  export { $DEVCOMP, children, createContext, useContext } from "./client/core.js";
4
4
  export type { ChildrenReturn, Context, ContextProviderComponent, ResolvedChildren, ResolvedJSXElement } from "./client/core.js";
5
5
  export * from "./client/component.js";
@@ -17,6 +17,7 @@ export declare function ssrHandleError(err: any): Promise<any> | undefined;
17
17
  */
18
18
  export declare function Loading(props: {
19
19
  fallback?: JSX.Element;
20
+ on?: () => any;
20
21
  children: JSX.Element;
21
22
  }): JSX.Element;
22
23
  /**
@@ -1,5 +1,5 @@
1
- export { $PROXY, $REFRESH, $TRACK, action, createEffect, createMemo, createOptimistic, createOptimisticStore, createOwner, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isRefreshing, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, latest, reconcile, refresh, repeat, resolve, NotReadyError, runWithOwner, snapshot, storePath, createDeepProxy, setOnUnhandledAsync, untrack } from "./signals.js";
2
- export type { Accessor, ComputeFunction, EffectFunction, EffectOptions, Merge, NoInfer, NotWrappable, Omit, Owner, Signal, SignalOptions, Setter, Store, SolidStore, StoreNode, StoreSetter, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter, PatchOp } from "./signals.js";
1
+ export { $PROXY, $REFRESH, $TRACK, action, createEffect, createMemo, createOptimistic, createOptimisticStore, createErrorBoundary, createLoadingBoundary, createOwner, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createTrackedEffect, deep, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isRefreshing, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, latest, reconcile, refresh, repeat, resolve, NotReadyError, runWithOwner, snapshot, storePath, createDeepProxy, enableExternalSource, enforceLoadingBoundary, untrack } from "./signals.js";
2
+ export type { Accessor, ComputeFunction, EffectFunction, EffectOptions, ExternalSource, ExternalSourceConfig, ExternalSourceFactory, Merge, NoInfer, NotWrappable, Omit, Owner, Signal, SignalOptions, Setter, Store, SolidStore, StoreNode, StoreSetter, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter, PatchOp } from "./signals.js";
3
3
  export { $DEVCOMP, children, createContext, useContext, ssrRunInScope } from "./core.js";
4
4
  export type { ChildrenReturn, Context, ContextProviderComponent, ResolvedChildren, ResolvedJSXElement } from "./core.js";
5
5
  export * from "./component.js";
@@ -1,7 +1,7 @@
1
- export { createRoot, createOwner, runWithOwner, getOwner, onCleanup, getNextChildId, createContext, setContext, getContext, NotReadyError, NoOwnerError, ContextNotFoundError, isEqual, isWrappable, SUPPORTS_PROXY, setOnUnhandledAsync } from "@solidjs/signals";
1
+ export { createRoot, createOwner, runWithOwner, getOwner, onCleanup, getNextChildId, createContext, setContext, getContext, NotReadyError, NoOwnerError, ContextNotFoundError, isEqual, isWrappable, SUPPORTS_PROXY, enableExternalSource, enforceLoadingBoundary } from "@solidjs/signals";
2
2
  export { flatten } from "@solidjs/signals";
3
3
  export { snapshot, merge, omit, storePath, $PROXY, $REFRESH, $TRACK } from "@solidjs/signals";
4
- export type { Accessor, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, MemoOptions, NoInfer, SignalOptions, Setter, Signal, Owner, Maybe, Store, StoreSetter, StoreNode, NotWrappable, SolidStore, Merge, Omit, Context, ContextRecord, IQueue, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter } from "@solidjs/signals";
4
+ export type { Accessor, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, ExternalSource, ExternalSourceConfig, ExternalSourceFactory, MemoOptions, NoInfer, SignalOptions, Setter, Signal, Owner, Maybe, Store, StoreSetter, StoreNode, NotWrappable, SolidStore, Merge, Omit, Context, ContextRecord, IQueue, StorePathRange, ArrayFilterFn, CustomPartial, Part, PathSetter } from "@solidjs/signals";
5
5
  import type { Accessor, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, MemoOptions, SignalOptions, Signal, Owner, Store, StoreSetter, Context } from "@solidjs/signals";
6
6
  import { NoHydrateContext } from "./shared.js";
7
7
  interface ServerComputation<T = any> {
@@ -49,7 +49,9 @@ declare const ErrorContext: Context<((err: any) => void) | null>;
49
49
  export { ErrorContext };
50
50
  export { NoHydrateContext };
51
51
  export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => unknown;
52
- export declare function createLoadBoundary(fn: () => any, fallback: () => any): () => unknown;
52
+ export declare function createLoadingBoundary(fn: () => any, fallback: () => any, options?: {
53
+ on?: () => any;
54
+ }): () => unknown;
53
55
  export declare function untrack<T>(fn: () => T): T;
54
56
  export declare function flush(): void;
55
57
  export declare function resolve<T>(fn: () => T): Promise<T>;