solid-js 2.0.0-beta.1 → 2.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHEATSHEET.md +640 -0
  2. package/README.md +42 -188
  3. package/dist/dev.cjs +446 -291
  4. package/dist/dev.js +426 -293
  5. package/dist/server.cjs +941 -345
  6. package/dist/server.js +897 -299
  7. package/dist/solid.cjs +438 -261
  8. package/dist/solid.js +418 -263
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +64 -19
  11. package/types/client/core.d.ts +110 -34
  12. package/types/client/flow.d.ts +176 -42
  13. package/types/client/hydration.d.ts +513 -37
  14. package/types/index.d.ts +8 -13
  15. package/types/server/component.d.ts +11 -11
  16. package/types/server/core.d.ts +19 -21
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +34 -9
  19. package/types/server/index.d.ts +6 -8
  20. package/types/server/shared.d.ts +10 -2
  21. package/types/server/signals.d.ts +80 -19
  22. package/types/types.d.ts +15 -0
  23. package/types-cjs/client/component.d.cts +120 -0
  24. package/types-cjs/client/core.d.cts +141 -0
  25. package/types-cjs/client/flow.d.cts +234 -0
  26. package/types-cjs/client/hydration.d.cts +568 -0
  27. package/types-cjs/index.d.cts +15 -0
  28. package/types-cjs/package.json +3 -0
  29. package/types-cjs/server/component.d.cts +67 -0
  30. package/types-cjs/server/core.d.cts +42 -0
  31. package/types-cjs/server/flow.d.cts +115 -0
  32. package/types-cjs/server/hydration.d.cts +63 -0
  33. package/types-cjs/server/index.d.cts +10 -0
  34. package/types-cjs/server/shared.d.cts +54 -0
  35. package/types-cjs/server/signals.d.cts +123 -0
  36. package/types-cjs/types.d.cts +15 -0
  37. package/jsx-runtime.d.ts +0 -1
  38. package/types/jsx.d.ts +0 -4129
package/dist/solid.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var signals = require('@solidjs/signals');
4
4
 
5
+ const IS_DEV = false;
5
6
  const $DEVCOMP = Symbol(0);
6
7
  function createContext(defaultValue, options) {
7
8
  const id = Symbol(options && options.name || "");
@@ -19,11 +20,12 @@ function useContext(context) {
19
20
  return signals.getContext(context);
20
21
  }
21
22
  function children(fn) {
22
- const c = signals.createMemo(fn, undefined, {
23
+ const c = signals.createMemo(fn, {
23
24
  lazy: true
24
25
  });
25
- const memo = signals.createMemo(() => signals.flatten(c()), undefined, {
26
- lazy: true
26
+ const memo = signals.createMemo(() => signals.flatten(c()), {
27
+ lazy: true,
28
+ sync: true
27
29
  });
28
30
  memo.toArray = () => {
29
31
  const v = memo();
@@ -71,6 +73,7 @@ function drainHydrationCallbacks() {
71
73
  if (cbs) for (const cb of cbs) cb();
72
74
  setTimeout(() => {
73
75
  if (globalThis._$HY) globalThis._$HY.done = true;
76
+ sharedConfig.registry?.clear();
74
77
  });
75
78
  }
76
79
  function checkHydrationComplete() {
@@ -88,23 +91,10 @@ let _createOptimisticStore;
88
91
  let _createRenderEffect;
89
92
  let _createEffect;
90
93
  class MockPromise {
91
- static all() {
92
- return new MockPromise();
93
- }
94
- static allSettled() {
95
- return new MockPromise();
96
- }
97
- static any() {
98
- return new MockPromise();
99
- }
100
- static race() {
101
- return new MockPromise();
102
- }
103
- static reject() {
104
- return new MockPromise();
105
- }
106
- static resolve() {
107
- return new MockPromise();
94
+ static {
95
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
96
+ MockPromise[k] = () => new MockPromise();
97
+ }
108
98
  }
109
99
  catch() {
110
100
  return new MockPromise();
@@ -132,11 +122,67 @@ function subFetch(fn, prev) {
132
122
  Promise = ogPromise;
133
123
  }
134
124
  }
135
- function consumeFirstSync(ai) {
136
- const iter = ai[Symbol.asyncIterator]();
137
- const r = iter.next();
138
- const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
139
- return [value, iter];
125
+ function syncThenable(value) {
126
+ return {
127
+ then(fn) {
128
+ fn(value);
129
+ }
130
+ };
131
+ }
132
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
133
+ function readHydratedValue(initP, refresh) {
134
+ if (initP == null) return NO_HYDRATED_VALUE;
135
+ refresh();
136
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
137
+ return initP?.v ?? initP;
138
+ }
139
+ function readSerializedOrCompute(compute, prev) {
140
+ if (!sharedConfig.hydrating) return compute(prev);
141
+ const o = signals.getOwner();
142
+ let initP;
143
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
144
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
145
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
146
+ }
147
+ function forwardIteratorReturn(it, value) {
148
+ const returned = it.return?.(value);
149
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
150
+ done: true,
151
+ value
152
+ });
153
+ }
154
+ function normalizeIterator(it) {
155
+ let first = true;
156
+ let buffered = null;
157
+ return {
158
+ next() {
159
+ if (first) {
160
+ first = false;
161
+ const r = it.next();
162
+ return r && typeof r.then === "function" ? r : syncThenable(r);
163
+ }
164
+ if (buffered) {
165
+ const b = buffered;
166
+ buffered = null;
167
+ return b;
168
+ }
169
+ let latest = it.next();
170
+ if (latest && typeof latest.then === "function") return latest;
171
+ while (!latest.done) {
172
+ const peek = it.next();
173
+ if (peek && typeof peek.then === "function") {
174
+ buffered = peek;
175
+ break;
176
+ }
177
+ latest = peek;
178
+ }
179
+ return Promise.resolve(latest);
180
+ },
181
+ return(value) {
182
+ buffered = null;
183
+ return forwardIteratorReturn(it, value);
184
+ }
185
+ };
140
186
  }
141
187
  function applyPatches(target, patches) {
142
188
  for (const patch of patches) {
@@ -153,118 +199,211 @@ function applyPatches(target, patches) {
153
199
  }
154
200
  }
155
201
  }
156
- function scheduleIteratorConsumption(iter, apply) {
157
- const consume = () => {
158
- while (true) {
159
- const n = iter.next();
160
- if (n instanceof Promise) {
161
- n.then(r => {
162
- if (r.done) return;
163
- apply(r.value);
164
- consume();
165
- });
166
- return;
202
+ function isAsyncIterable(v) {
203
+ return v != null && typeof v[Symbol.asyncIterator] === "function";
204
+ }
205
+ function createShadowDraft(realDraft) {
206
+ const shadow = JSON.parse(JSON.stringify(realDraft));
207
+ let useShadow = true;
208
+ return {
209
+ proxy: new Proxy(shadow, {
210
+ get(_, prop) {
211
+ return useShadow ? shadow[prop] : realDraft[prop];
212
+ },
213
+ set(_, prop, value) {
214
+ if (useShadow) {
215
+ shadow[prop] = value;
216
+ return true;
217
+ }
218
+ return Reflect.set(realDraft, prop, value);
219
+ },
220
+ deleteProperty(_, prop) {
221
+ if (useShadow) {
222
+ delete shadow[prop];
223
+ return true;
224
+ }
225
+ return Reflect.deleteProperty(realDraft, prop);
226
+ },
227
+ has(_, prop) {
228
+ return prop in (useShadow ? shadow : realDraft);
229
+ },
230
+ ownKeys() {
231
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
232
+ },
233
+ getOwnPropertyDescriptor(_, prop) {
234
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
167
235
  }
168
- if (n.done) break;
169
- apply(n.value);
236
+ }),
237
+ activate() {
238
+ useShadow = false;
170
239
  }
171
240
  };
172
- consume();
173
241
  }
174
- function isAsyncIterable(v) {
175
- return v != null && typeof v[Symbol.asyncIterator] === "function";
242
+ function wrapFirstYield(iterable, activate) {
243
+ const srcIt = iterable[Symbol.asyncIterator]();
244
+ let first = true;
245
+ return {
246
+ [Symbol.asyncIterator]() {
247
+ return {
248
+ next() {
249
+ const p = srcIt.next();
250
+ if (first) {
251
+ first = false;
252
+ return p.then(r => {
253
+ activate();
254
+ return r.done ? r : {
255
+ done: false,
256
+ value: undefined
257
+ };
258
+ });
259
+ }
260
+ return p;
261
+ },
262
+ return(value) {
263
+ return forwardIteratorReturn(srcIt, value);
264
+ }
265
+ };
266
+ }
267
+ };
176
268
  }
177
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
269
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
178
270
  const parent = signals.getOwner();
179
271
  const expectedId = signals.peekNextChildId(parent);
180
272
  if (!sharedConfig.has(expectedId)) return null;
181
- const initP = sharedConfig.load(expectedId);
182
- if (!isAsyncIterable(initP)) return null;
183
- const [firstValue, iter] = consumeFirstSync(initP);
184
- const [get, set] = signals.createSignal(firstValue);
185
- const result = coreFn(() => get(), firstValue, options);
186
- scheduleIteratorConsumption(iter, v => {
187
- set(() => v);
188
- signals.flush();
189
- });
190
- return result;
273
+ const loaded = sharedConfig.load(expectedId);
274
+ if (!isAsyncIterable(loaded)) return null;
275
+ const it = normalizeIterator(loaded[Symbol.asyncIterator]());
276
+ const iterable = {
277
+ [Symbol.asyncIterator]() {
278
+ return it;
279
+ }
280
+ };
281
+ return coreFn(prev => {
282
+ subFetch(compute, prev);
283
+ return iterable;
284
+ }, options);
191
285
  }
192
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
286
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
193
287
  const parent = signals.getOwner();
194
288
  const expectedId = signals.peekNextChildId(parent);
195
289
  if (!sharedConfig.has(expectedId)) return null;
196
- const initP = sharedConfig.load(expectedId);
197
- if (!isAsyncIterable(initP)) return null;
198
- const [firstState, iter] = consumeFirstSync(initP);
199
- const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
200
- scheduleIteratorConsumption(iter, patches => {
201
- setStore(d => {
202
- applyPatches(d, patches);
203
- });
204
- });
205
- return [store, setStore];
290
+ const loaded = sharedConfig.load(expectedId);
291
+ if (!isAsyncIterable(loaded)) return null;
292
+ const srcIt = loaded[Symbol.asyncIterator]();
293
+ let isFirst = true;
294
+ let buffered = null;
295
+ return coreFn(draft => {
296
+ const {
297
+ proxy
298
+ } = createShadowDraft(draft);
299
+ subFetch(fn, proxy);
300
+ const process = res => {
301
+ if (res.done) return {
302
+ done: true,
303
+ value: undefined
304
+ };
305
+ if (isFirst) {
306
+ isFirst = false;
307
+ signals.setSnapshotCapture(false);
308
+ try {
309
+ if (Array.isArray(res.value)) {
310
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
311
+ draft.length = res.value.length;
312
+ } else {
313
+ Object.assign(draft, res.value);
314
+ }
315
+ } finally {
316
+ signals.setSnapshotCapture(true);
317
+ }
318
+ } else {
319
+ applyPatches(draft, res.value);
320
+ }
321
+ return {
322
+ done: false,
323
+ value: undefined
324
+ };
325
+ };
326
+ return {
327
+ [Symbol.asyncIterator]() {
328
+ return {
329
+ next() {
330
+ if (isFirst) {
331
+ const r = srcIt.next();
332
+ return r && typeof r.then === "function" ? {
333
+ then(fn, rej) {
334
+ r.then(v => fn(process(v)), rej);
335
+ }
336
+ } : syncThenable(process(r));
337
+ }
338
+ if (buffered) {
339
+ const b = buffered;
340
+ buffered = null;
341
+ return b.then(process);
342
+ }
343
+ let r = srcIt.next();
344
+ if (r && typeof r.then === "function") {
345
+ return r.then(process);
346
+ }
347
+ let result = process(r);
348
+ while (!r.done) {
349
+ const peek = srcIt.next();
350
+ if (peek && typeof peek.then === "function") {
351
+ buffered = peek;
352
+ break;
353
+ }
354
+ r = peek;
355
+ if (!r.done) result = process(r);
356
+ }
357
+ return Promise.resolve(result);
358
+ },
359
+ return(value) {
360
+ buffered = null;
361
+ return forwardIteratorReturn(srcIt, value);
362
+ }
363
+ };
364
+ }
365
+ };
366
+ }, initialValue, options);
206
367
  }
207
- function hydratedCreateMemo(compute, value, options) {
208
- if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
368
+ function hydratedCreateMemo(compute, options) {
369
+ if (!sharedConfig.hydrating || options?.transparent) {
370
+ return signals.createMemo(compute, options);
371
+ }
209
372
  markTopLevelSnapshotScope();
210
373
  const ssrSource = options?.ssrSource;
211
374
  if (ssrSource === "client") {
212
- const [hydrated, setHydrated] = signals.createSignal(false);
375
+ const [hydrated, setHydrated] = signals.createSignal(false, {
376
+ ownedWrite: true
377
+ });
213
378
  const memo = signals.createMemo(prev => {
214
- if (!hydrated()) return prev ?? value;
379
+ if (!hydrated()) return prev;
215
380
  return compute(prev);
216
- }, value, options);
381
+ }, options);
217
382
  setHydrated(true);
218
383
  return memo;
219
384
  }
220
- if (ssrSource === "initial") {
221
- return signals.createMemo(prev => {
222
- if (!sharedConfig.hydrating) return compute(prev);
223
- subFetch(compute, prev);
224
- return prev ?? value;
225
- }, value, options);
226
- }
227
- const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
385
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, options);
228
386
  if (aiResult !== null) return aiResult;
229
- return signals.createMemo(prev => {
230
- const o = signals.getOwner();
231
- if (!sharedConfig.hydrating) return compute(prev);
232
- let initP;
233
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
234
- const init = initP?.v ?? initP;
235
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
236
- }, value, options);
237
- }
238
- function hydratedCreateSignal(fn, second, third) {
239
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
387
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), options);
388
+ }
389
+ function hydratedCreateSignal(fn, second) {
390
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second);
240
391
  markTopLevelSnapshotScope();
241
- const ssrSource = third?.ssrSource;
392
+ const ssrSource = second?.ssrSource;
242
393
  if (ssrSource === "client") {
243
- const [hydrated, setHydrated] = signals.createSignal(false);
394
+ const [hydrated, setHydrated] = signals.createSignal(false, {
395
+ ownedWrite: true
396
+ });
244
397
  const sig = signals.createSignal(prev => {
245
- if (!hydrated()) return prev ?? second;
398
+ if (!hydrated()) return prev;
246
399
  return fn(prev);
247
- }, second, third);
400
+ }, second);
248
401
  setHydrated(true);
249
402
  return sig;
250
403
  }
251
- if (ssrSource === "initial") {
252
- return signals.createSignal(prev => {
253
- if (!sharedConfig.hydrating) return fn(prev);
254
- subFetch(fn, prev);
255
- return prev ?? second;
256
- }, second, third);
257
- }
258
- const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
404
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second);
259
405
  if (aiResult !== null) return aiResult;
260
- return signals.createSignal(prev => {
261
- if (!sharedConfig.hydrating) return fn(prev);
262
- const o = signals.getOwner();
263
- let initP;
264
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
265
- const init = initP?.v ?? initP;
266
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
267
- }, second, third);
406
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second);
268
407
  }
269
408
  function hydratedCreateErrorBoundary(fn, fallback) {
270
409
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -286,127 +425,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
286
425
  }
287
426
  return signals.createErrorBoundary(fn, fallback);
288
427
  }
289
- function hydratedCreateOptimistic(fn, second, third) {
290
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
428
+ function hydratedCreateOptimistic(fn, second) {
429
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second);
291
430
  markTopLevelSnapshotScope();
292
- const ssrSource = third?.ssrSource;
431
+ const ssrSource = second?.ssrSource;
293
432
  if (ssrSource === "client") {
294
- const [hydrated, setHydrated] = signals.createSignal(false);
433
+ const [hydrated, setHydrated] = signals.createSignal(false, {
434
+ ownedWrite: true
435
+ });
295
436
  const sig = signals.createOptimistic(prev => {
296
- if (!hydrated()) return prev ?? second;
437
+ if (!hydrated()) return prev;
297
438
  return fn(prev);
298
- }, second, third);
439
+ }, second);
299
440
  setHydrated(true);
300
441
  return sig;
301
442
  }
302
- if (ssrSource === "initial") {
303
- return signals.createOptimistic(prev => {
304
- if (!sharedConfig.hydrating) return fn(prev);
305
- subFetch(fn, prev);
306
- return prev ?? second;
307
- }, second, third);
308
- }
309
- const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
443
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second);
310
444
  if (aiResult !== null) return aiResult;
311
- return signals.createOptimistic(prev => {
312
- const o = signals.getOwner();
313
- if (!sharedConfig.hydrating) return fn(prev);
314
- let initP;
315
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
316
- const init = initP?.v ?? initP;
317
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
318
- }, second, third);
319
- }
320
- function wrapStoreFn(fn, ssrSource) {
321
- if (ssrSource === "initial") {
322
- return draft => {
323
- if (!sharedConfig.hydrating) return fn(draft);
324
- subFetch(fn, draft);
325
- return undefined;
326
- };
445
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second);
446
+ }
447
+ function wrapStoreFn(fn) {
448
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
449
+ }
450
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
451
+ if (ssrSource === "client") {
452
+ const [hydrated, setHydrated] = signals.createSignal(false, {
453
+ ownedWrite: true
454
+ });
455
+ const result = coreFn(draft => {
456
+ if (!hydrated()) return;
457
+ return fn(draft);
458
+ }, initialValue, options);
459
+ setHydrated(true);
460
+ return result;
327
461
  }
328
- return draft => {
329
- const o = signals.getOwner();
330
- if (!sharedConfig.hydrating) return fn(draft);
331
- let initP;
332
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
333
- const init = initP?.v ?? initP;
334
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
335
- };
462
+ if (ssrSource === "hybrid") {
463
+ const [hydrated, setHydrated] = signals.createSignal(false, {
464
+ ownedWrite: true
465
+ });
466
+ const result = coreFn(draft => {
467
+ const o = signals.getOwner();
468
+ if (!hydrated()) {
469
+ if (sharedConfig.has(o.id)) {
470
+ const initP = sharedConfig.load(o.id);
471
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
472
+ if (init !== NO_HYDRATED_VALUE) return init;
473
+ }
474
+ return fn(draft);
475
+ }
476
+ const {
477
+ proxy,
478
+ activate
479
+ } = createShadowDraft(draft);
480
+ const r = fn(proxy);
481
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
482
+ }, initialValue, options);
483
+ setHydrated(true);
484
+ return result;
485
+ }
486
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options);
487
+ if (aiResult !== null) return aiResult;
488
+ return coreFn(wrapStoreFn(fn), initialValue, options);
336
489
  }
337
490
  function hydratedCreateStore(first, second, third) {
338
491
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
339
492
  markTopLevelSnapshotScope();
340
493
  const ssrSource = third?.ssrSource;
341
- if (ssrSource === "client" || ssrSource === "initial") {
342
- return signals.createStore(second ?? {}, undefined, third);
343
- }
344
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
345
- if (aiResult !== null) return aiResult;
346
- return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
494
+ return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
347
495
  }
348
496
  function hydratedCreateOptimisticStore(first, second, third) {
349
497
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
350
498
  markTopLevelSnapshotScope();
351
499
  const ssrSource = third?.ssrSource;
352
- if (ssrSource === "client" || ssrSource === "initial") {
353
- return signals.createOptimisticStore(second ?? {}, undefined, third);
354
- }
355
- const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
356
- if (aiResult !== null) return aiResult;
357
- return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
500
+ return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
358
501
  }
359
502
  function hydratedCreateProjection(fn, initialValue, options) {
360
503
  if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
361
504
  markTopLevelSnapshotScope();
362
505
  const ssrSource = options?.ssrSource;
363
- if (ssrSource === "client" || ssrSource === "initial") {
364
- return signals.createProjection(draft => draft, initialValue, options);
365
- }
366
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
367
- if (aiResult !== null) return aiResult[0];
368
- return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
506
+ return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
369
507
  }
370
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
371
- if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
508
+ function hydratedEffect(coreFn, compute, effectFn, options) {
509
+ if (!sharedConfig.hydrating || options?.transparent) return coreFn(compute, effectFn, options);
372
510
  const ssrSource = options?.ssrSource;
373
511
  if (ssrSource === "client") {
374
- const [hydrated, setHydrated] = signals.createSignal(false);
512
+ const [hydrated, setHydrated] = signals.createSignal(false, {
513
+ ownedWrite: true
514
+ });
375
515
  let active = false;
376
516
  coreFn(prev => {
377
- if (!hydrated()) return value;
517
+ if (!hydrated()) return prev;
378
518
  active = true;
379
519
  return compute(prev);
380
520
  }, (next, prev) => {
381
521
  if (!active) return;
382
522
  return effectFn(next, prev);
383
- }, value, options);
523
+ }, options);
384
524
  setHydrated(true);
385
525
  return;
386
526
  }
387
- if (ssrSource === "initial") {
388
- coreFn(prev => {
389
- if (!sharedConfig.hydrating) return compute(prev);
390
- subFetch(compute, prev);
391
- return prev ?? value;
392
- }, effectFn, value, options);
393
- return;
394
- }
395
527
  markTopLevelSnapshotScope();
396
- coreFn(prev => {
397
- const o = signals.getOwner();
398
- if (!sharedConfig.hydrating) return compute(prev);
399
- let initP;
400
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
401
- const init = initP?.v ?? initP;
402
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
403
- }, effectFn, value, options);
528
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
404
529
  }
405
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
406
- return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
530
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
531
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, options);
407
532
  }
408
- function hydratedCreateEffect(compute, effectFn, value, options) {
409
- return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
533
+ function hydratedCreateEffect(compute, effectFn, options) {
534
+ return hydratedEffect(signals.createEffect, compute, effectFn, options);
410
535
  }
411
536
  function enableHydration() {
412
537
  _createMemo = hydratedCreateMemo;
@@ -465,24 +590,6 @@ const createStore = (...args) => (_createStore || signals.createStore)(...args);
465
590
  const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
466
591
  const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
467
592
  const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
468
- function loadModuleAssets(mapping) {
469
- const hy = globalThis._$HY;
470
- if (!hy) return;
471
- if (!hy.modules) hy.modules = {};
472
- if (!hy.loading) hy.loading = {};
473
- const pending = [];
474
- for (const moduleUrl in mapping) {
475
- if (hy.modules[moduleUrl]) continue;
476
- const entryUrl = mapping[moduleUrl];
477
- if (!hy.loading[moduleUrl]) {
478
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
479
- hy.modules[moduleUrl] = mod;
480
- });
481
- }
482
- pending.push(hy.loading[moduleUrl]);
483
- }
484
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
485
- }
486
593
  function createBoundaryTrigger() {
487
594
  signals.setSnapshotCapture(false);
488
595
  const [s, set] = signals.createSignal(undefined, {
@@ -498,7 +605,7 @@ function resumeBoundaryHydration(o, id, set) {
498
605
  checkHydrationComplete();
499
606
  return;
500
607
  }
501
- sharedConfig.gather(id);
608
+ sharedConfig.gather?.(id);
502
609
  _hydratingValue = true;
503
610
  signals.markSnapshotScope(o);
504
611
  _snapshotRootOwner = o;
@@ -510,38 +617,65 @@ function resumeBoundaryHydration(o, id, set) {
510
617
  signals.flush();
511
618
  checkHydrationComplete();
512
619
  }
513
- function Loading(props) {
514
- if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
620
+ function initBoundaryResume(o, id) {
621
+ _pendingBoundaries++;
622
+ signals.onCleanup(() => {
623
+ if (!signals.isDisposed(o)) return;
624
+ sharedConfig.cleanupFragment?.(id);
625
+ });
626
+ const set = createBoundaryTrigger();
627
+ return [set, () => resumeBoundaryHydration(o, id, set)];
628
+ }
629
+ function waitAndResume(p, resume, assetPromise) {
630
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
631
+ waitFor.then(() => {
632
+ if (p && typeof p === "object") p.s = 1;
633
+ resume();
634
+ }, err => {
635
+ if (p && typeof p === "object") {
636
+ p.s = 2;
637
+ p.v = err;
638
+ }
639
+ resume();
640
+ });
641
+ }
642
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
643
+ sharedConfig.gather?.(id);
644
+ const doResume = () => queueMicrotask(resume);
645
+ if (assetPromise) {
646
+ assetPromise.then(doResume);
647
+ return true;
648
+ }
649
+ doResume();
650
+ return false;
651
+ }
652
+ function createLoadingBoundary(fn, fallback, options) {
653
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
654
+ let settledSerializationResumeQueued = false;
515
655
  return signals.createMemo(() => {
516
656
  const o = signals.getOwner();
517
657
  const id = o.id;
518
658
  let assetPromise;
519
659
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
520
660
  const mapping = sharedConfig.load(id + "_assets");
521
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
661
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
522
662
  }
523
663
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
524
- let ref = sharedConfig.load(id);
664
+ const ref = sharedConfig.load(id);
525
665
  let p;
526
666
  if (ref) {
527
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
667
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
668
+ }
669
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
670
+ settledSerializationResumeQueued = true;
671
+ const [, resume] = initBoundaryResume(o, id);
672
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
673
+ return fallback();
528
674
  }
529
675
  if (p) {
530
- _pendingBoundaries++;
531
- signals.onCleanup(() => {
532
- if (!signals.isDisposed(o)) return;
533
- sharedConfig.cleanupFragment?.(id);
534
- });
535
- const set = createBoundaryTrigger();
676
+ const [set, resume] = initBoundaryResume(o, id);
536
677
  if (p !== "$$f") {
537
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
538
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
539
- _pendingBoundaries--;
540
- checkHydrationComplete();
541
- signals.runWithOwner(o, () => {
542
- throw err;
543
- });
544
- });
678
+ waitAndResume(p, resume, assetPromise);
545
679
  } else {
546
680
  const afterAssets = () => {
547
681
  _pendingBoundaries--;
@@ -550,16 +684,26 @@ function Loading(props) {
550
684
  };
551
685
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
552
686
  }
553
- return props.fallback;
687
+ return fallback();
688
+ }
689
+ }
690
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
691
+ settledSerializationResumeQueued = true;
692
+ const fr = sharedConfig.load(id + "_fr");
693
+ const [, resume] = initBoundaryResume(o, id);
694
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
695
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
696
+ return fallback();
554
697
  }
698
+ waitAndResume(fr, resume, assetPromise);
699
+ return fallback();
555
700
  }
556
- if (assetPromise) {
557
- _pendingBoundaries++;
558
- const set = createBoundaryTrigger();
559
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
701
+ if (assetPromise && !sharedConfig.has(id)) {
702
+ const [, resume] = initBoundaryResume(o, id);
703
+ assetPromise.then(resume);
560
704
  return undefined;
561
705
  }
562
- return signals.createLoadBoundary(() => props.children, () => props.fallback);
706
+ return signals.createLoadingBoundary(fn, fallback, options);
563
707
  });
564
708
  }
565
709
  function NoHydration(props) {
@@ -598,7 +742,9 @@ function lazy(fn, moduleUrl) {
598
742
  let Comp;
599
743
  return signals.createMemo(() => (Comp = comp()) ? signals.untrack(() => {
600
744
  return Comp(props);
601
- }) : "");
745
+ }) : "", {
746
+ sync: true
747
+ });
602
748
  };
603
749
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
604
750
  wrap.moduleUrl = moduleUrl;
@@ -628,27 +774,25 @@ function Repeat(props) {
628
774
  }
629
775
  function Show(props) {
630
776
  const keyed = props.keyed;
631
- const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
632
- const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
633
- equals: (a, b) => !a === !b
777
+ const conditionValue = signals.createMemo(() => props.when, undefined);
778
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, {
779
+ equals: (a, b) => !a === !b,
780
+ sync: true
634
781
  });
635
782
  return signals.createMemo(() => {
636
783
  const c = condition();
637
784
  if (c) {
638
785
  const child = props.children;
639
786
  const fn = typeof child === "function" && child.length > 0;
640
- return fn ? signals.untrack(() => {
641
- try {
642
- return child(() => {
643
- if (!signals.untrack(condition)) throw narrowedError("Show");
644
- return conditionValue();
645
- });
646
- } finally {
647
- }
648
- }) : child;
787
+ return fn ? signals.untrack(() => child(() => {
788
+ if (!signals.untrack(condition)) throw narrowedError("Show");
789
+ return conditionValue();
790
+ }), IS_DEV) : child;
649
791
  }
650
792
  return props.fallback;
651
- }, undefined, undefined);
793
+ }, {
794
+ sync: true
795
+ });
652
796
  }
653
797
  function Switch(props) {
654
798
  const chs = children(() => props.children);
@@ -659,13 +803,16 @@ function Switch(props) {
659
803
  const index = i;
660
804
  const mp = mps[i];
661
805
  const prevFunc = func;
662
- const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
663
- const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
664
- equals: (a, b) => !a === !b
806
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined);
807
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, {
808
+ equals: (a, b) => !a === !b,
809
+ sync: true
665
810
  });
666
811
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
667
812
  }
668
813
  return func;
814
+ }, {
815
+ sync: true
669
816
  });
670
817
  return signals.createMemo(() => {
671
818
  const sel = switchFunc()();
@@ -673,16 +820,13 @@ function Switch(props) {
673
820
  const [index, conditionValue, mp] = sel;
674
821
  const child = mp.children;
675
822
  const fn = typeof child === "function" && child.length > 0;
676
- return fn ? signals.untrack(() => {
677
- try {
678
- return child(() => {
679
- if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
680
- return conditionValue();
681
- });
682
- } finally {
683
- }
684
- }) : child;
685
- }, undefined, undefined);
823
+ return fn ? signals.untrack(() => child(() => {
824
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
825
+ return conditionValue();
826
+ }), IS_DEV) : child;
827
+ }, {
828
+ sync: true
829
+ });
686
830
  }
687
831
  function Match(props) {
688
832
  return props;
@@ -693,15 +837,30 @@ function Errored(props) {
693
837
  return typeof f === "function" && f.length ? f(err, reset) : f;
694
838
  });
695
839
  }
840
+ function Loading(props) {
841
+ const onOpt = "on" in props ? {
842
+ on: () => props.on
843
+ } : undefined;
844
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
845
+ }
846
+ function Reveal(props) {
847
+ return signals.createRevealOrder(() => props.children, {
848
+ order: () => props.order ?? "sequential",
849
+ collapsed: () => !!props.collapsed
850
+ });
851
+ }
696
852
 
697
853
  function ssrHandleError() {}
698
- function ssrRunInScope() {}
699
854
  const DEV = undefined;
700
855
 
701
856
  Object.defineProperty(exports, "$PROXY", {
702
857
  enumerable: true,
703
858
  get: function () { return signals.$PROXY; }
704
859
  });
860
+ Object.defineProperty(exports, "$REFRESH", {
861
+ enumerable: true,
862
+ get: function () { return signals.$REFRESH; }
863
+ });
705
864
  Object.defineProperty(exports, "$TRACK", {
706
865
  enumerable: true,
707
866
  get: function () { return signals.$TRACK; }
@@ -722,6 +881,10 @@ Object.defineProperty(exports, "createReaction", {
722
881
  enumerable: true,
723
882
  get: function () { return signals.createReaction; }
724
883
  });
884
+ Object.defineProperty(exports, "createRevealOrder", {
885
+ enumerable: true,
886
+ get: function () { return signals.createRevealOrder; }
887
+ });
725
888
  Object.defineProperty(exports, "createRoot", {
726
889
  enumerable: true,
727
890
  get: function () { return signals.createRoot; }
@@ -734,6 +897,14 @@ Object.defineProperty(exports, "deep", {
734
897
  enumerable: true,
735
898
  get: function () { return signals.deep; }
736
899
  });
900
+ Object.defineProperty(exports, "enableExternalSource", {
901
+ enumerable: true,
902
+ get: function () { return signals.enableExternalSource; }
903
+ });
904
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
905
+ enumerable: true,
906
+ get: function () { return signals.enforceLoadingBoundary; }
907
+ });
737
908
  Object.defineProperty(exports, "flatten", {
738
909
  enumerable: true,
739
910
  get: function () { return signals.flatten; }
@@ -754,6 +925,10 @@ Object.defineProperty(exports, "getOwner", {
754
925
  enumerable: true,
755
926
  get: function () { return signals.getOwner; }
756
927
  });
928
+ Object.defineProperty(exports, "isDisposed", {
929
+ enumerable: true,
930
+ get: function () { return signals.isDisposed; }
931
+ });
757
932
  Object.defineProperty(exports, "isEqual", {
758
933
  enumerable: true,
759
934
  get: function () { return signals.isEqual; }
@@ -836,12 +1011,15 @@ exports.Match = Match;
836
1011
  exports.NoHydrateContext = NoHydrateContext;
837
1012
  exports.NoHydration = NoHydration;
838
1013
  exports.Repeat = Repeat;
1014
+ exports.Reveal = Reveal;
839
1015
  exports.Show = Show;
840
1016
  exports.Switch = Switch;
841
1017
  exports.children = children;
842
1018
  exports.createComponent = createComponent;
843
1019
  exports.createContext = createContext;
844
1020
  exports.createEffect = createEffect;
1021
+ exports.createErrorBoundary = createErrorBoundary;
1022
+ exports.createLoadingBoundary = createLoadingBoundary;
845
1023
  exports.createMemo = createMemo;
846
1024
  exports.createOptimistic = createOptimistic;
847
1025
  exports.createOptimisticStore = createOptimisticStore;
@@ -854,5 +1032,4 @@ exports.enableHydration = enableHydration;
854
1032
  exports.lazy = lazy;
855
1033
  exports.sharedConfig = sharedConfig;
856
1034
  exports.ssrHandleError = ssrHandleError;
857
- exports.ssrRunInScope = ssrRunInScope;
858
1035
  exports.useContext = useContext;