solid-js 2.0.0-beta.0 → 2.0.0-beta.10

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 +451 -283
  4. package/dist/dev.js +428 -286
  5. package/dist/server.cjs +735 -279
  6. package/dist/server.js +715 -282
  7. package/dist/solid.cjs +443 -255
  8. package/dist/solid.js +420 -258
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +65 -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 +525 -31
  14. package/types/index.d.ts +9 -12
  15. package/types/server/component.d.ts +12 -11
  16. package/types/server/core.d.ts +19 -14
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +49 -7
  19. package/types/server/index.d.ts +5 -7
  20. package/types/server/shared.d.ts +9 -4
  21. package/types/server/signals.d.ts +45 -18
  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 +570 -0
  27. package/types-cjs/index.d.cts +17 -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 +49 -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 +50 -0
  35. package/types-cjs/server/signals.d.cts +87 -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,10 +20,10 @@ 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
+ const memo = signals.createMemo(() => signals.flatten(c()), {
26
27
  lazy: true
27
28
  });
28
29
  memo.toArray = () => {
@@ -32,6 +33,10 @@ function children(fn) {
32
33
  return memo;
33
34
  }
34
35
 
36
+ const NoHydrateContext = {
37
+ id: Symbol("NoHydrateContext"),
38
+ defaultValue: false
39
+ };
35
40
  const sharedConfig = {
36
41
  hydrating: false,
37
42
  registry: undefined,
@@ -39,6 +44,7 @@ const sharedConfig = {
39
44
  getNextContextId() {
40
45
  const o = signals.getOwner();
41
46
  if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
47
+ if (signals.getContext(NoHydrateContext)) return undefined;
42
48
  return signals.getNextChildId(o);
43
49
  }
44
50
  };
@@ -66,6 +72,7 @@ function drainHydrationCallbacks() {
66
72
  if (cbs) for (const cb of cbs) cb();
67
73
  setTimeout(() => {
68
74
  if (globalThis._$HY) globalThis._$HY.done = true;
75
+ sharedConfig.registry?.clear();
69
76
  });
70
77
  }
71
78
  function checkHydrationComplete() {
@@ -83,23 +90,10 @@ let _createOptimisticStore;
83
90
  let _createRenderEffect;
84
91
  let _createEffect;
85
92
  class MockPromise {
86
- static all() {
87
- return new MockPromise();
88
- }
89
- static allSettled() {
90
- return new MockPromise();
91
- }
92
- static any() {
93
- return new MockPromise();
94
- }
95
- static race() {
96
- return new MockPromise();
97
- }
98
- static reject() {
99
- return new MockPromise();
100
- }
101
- static resolve() {
102
- return new MockPromise();
93
+ static {
94
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
95
+ MockPromise[k] = () => new MockPromise();
96
+ }
103
97
  }
104
98
  catch() {
105
99
  return new MockPromise();
@@ -127,11 +121,67 @@ function subFetch(fn, prev) {
127
121
  Promise = ogPromise;
128
122
  }
129
123
  }
130
- function consumeFirstSync(ai) {
131
- const iter = ai[Symbol.asyncIterator]();
132
- const r = iter.next();
133
- const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
134
- return [value, iter];
124
+ function syncThenable(value) {
125
+ return {
126
+ then(fn) {
127
+ fn(value);
128
+ }
129
+ };
130
+ }
131
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
132
+ function readHydratedValue(initP, refresh) {
133
+ if (initP == null) return NO_HYDRATED_VALUE;
134
+ refresh();
135
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
136
+ return initP?.v ?? initP;
137
+ }
138
+ function readSerializedOrCompute(compute, prev) {
139
+ if (!sharedConfig.hydrating) return compute(prev);
140
+ const o = signals.getOwner();
141
+ let initP;
142
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
143
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
144
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
145
+ }
146
+ function forwardIteratorReturn(it, value) {
147
+ const returned = it.return?.(value);
148
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
149
+ done: true,
150
+ value
151
+ });
152
+ }
153
+ function normalizeIterator(it) {
154
+ let first = true;
155
+ let buffered = null;
156
+ return {
157
+ next() {
158
+ if (first) {
159
+ first = false;
160
+ const r = it.next();
161
+ return r && typeof r.then === "function" ? r : syncThenable(r);
162
+ }
163
+ if (buffered) {
164
+ const b = buffered;
165
+ buffered = null;
166
+ return b;
167
+ }
168
+ let latest = it.next();
169
+ if (latest && typeof latest.then === "function") return latest;
170
+ while (!latest.done) {
171
+ const peek = it.next();
172
+ if (peek && typeof peek.then === "function") {
173
+ buffered = peek;
174
+ break;
175
+ }
176
+ latest = peek;
177
+ }
178
+ return Promise.resolve(latest);
179
+ },
180
+ return(value) {
181
+ buffered = null;
182
+ return forwardIteratorReturn(it, value);
183
+ }
184
+ };
135
185
  }
136
186
  function applyPatches(target, patches) {
137
187
  for (const patch of patches) {
@@ -148,118 +198,211 @@ function applyPatches(target, patches) {
148
198
  }
149
199
  }
150
200
  }
151
- function scheduleIteratorConsumption(iter, apply) {
152
- const consume = () => {
153
- while (true) {
154
- const n = iter.next();
155
- if (n instanceof Promise) {
156
- n.then(r => {
157
- if (r.done) return;
158
- apply(r.value);
159
- consume();
160
- });
161
- return;
201
+ function isAsyncIterable(v) {
202
+ return v != null && typeof v[Symbol.asyncIterator] === "function";
203
+ }
204
+ function createShadowDraft(realDraft) {
205
+ const shadow = JSON.parse(JSON.stringify(realDraft));
206
+ let useShadow = true;
207
+ return {
208
+ proxy: new Proxy(shadow, {
209
+ get(_, prop) {
210
+ return useShadow ? shadow[prop] : realDraft[prop];
211
+ },
212
+ set(_, prop, value) {
213
+ if (useShadow) {
214
+ shadow[prop] = value;
215
+ return true;
216
+ }
217
+ return Reflect.set(realDraft, prop, value);
218
+ },
219
+ deleteProperty(_, prop) {
220
+ if (useShadow) {
221
+ delete shadow[prop];
222
+ return true;
223
+ }
224
+ return Reflect.deleteProperty(realDraft, prop);
225
+ },
226
+ has(_, prop) {
227
+ return prop in (useShadow ? shadow : realDraft);
228
+ },
229
+ ownKeys() {
230
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
231
+ },
232
+ getOwnPropertyDescriptor(_, prop) {
233
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
162
234
  }
163
- if (n.done) break;
164
- apply(n.value);
235
+ }),
236
+ activate() {
237
+ useShadow = false;
165
238
  }
166
239
  };
167
- consume();
168
240
  }
169
- function isAsyncIterable(v) {
170
- return v != null && typeof v[Symbol.asyncIterator] === "function";
241
+ function wrapFirstYield(iterable, activate) {
242
+ const srcIt = iterable[Symbol.asyncIterator]();
243
+ let first = true;
244
+ return {
245
+ [Symbol.asyncIterator]() {
246
+ return {
247
+ next() {
248
+ const p = srcIt.next();
249
+ if (first) {
250
+ first = false;
251
+ return p.then(r => {
252
+ activate();
253
+ return r.done ? r : {
254
+ done: false,
255
+ value: undefined
256
+ };
257
+ });
258
+ }
259
+ return p;
260
+ },
261
+ return(value) {
262
+ return forwardIteratorReturn(srcIt, value);
263
+ }
264
+ };
265
+ }
266
+ };
171
267
  }
172
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
268
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
173
269
  const parent = signals.getOwner();
174
270
  const expectedId = signals.peekNextChildId(parent);
175
271
  if (!sharedConfig.has(expectedId)) return null;
176
- const initP = sharedConfig.load(expectedId);
177
- if (!isAsyncIterable(initP)) return null;
178
- const [firstValue, iter] = consumeFirstSync(initP);
179
- const [get, set] = signals.createSignal(firstValue);
180
- const result = coreFn(() => get(), firstValue, options);
181
- scheduleIteratorConsumption(iter, v => {
182
- set(() => v);
183
- signals.flush();
184
- });
185
- return result;
272
+ const loaded = sharedConfig.load(expectedId);
273
+ if (!isAsyncIterable(loaded)) return null;
274
+ const it = normalizeIterator(loaded[Symbol.asyncIterator]());
275
+ const iterable = {
276
+ [Symbol.asyncIterator]() {
277
+ return it;
278
+ }
279
+ };
280
+ return coreFn(prev => {
281
+ subFetch(compute, prev);
282
+ return iterable;
283
+ }, options);
186
284
  }
187
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
285
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
188
286
  const parent = signals.getOwner();
189
287
  const expectedId = signals.peekNextChildId(parent);
190
288
  if (!sharedConfig.has(expectedId)) return null;
191
- const initP = sharedConfig.load(expectedId);
192
- if (!isAsyncIterable(initP)) return null;
193
- const [firstState, iter] = consumeFirstSync(initP);
194
- const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
195
- scheduleIteratorConsumption(iter, patches => {
196
- setStore(d => {
197
- applyPatches(d, patches);
198
- });
199
- });
200
- return [store, setStore];
289
+ const loaded = sharedConfig.load(expectedId);
290
+ if (!isAsyncIterable(loaded)) return null;
291
+ const srcIt = loaded[Symbol.asyncIterator]();
292
+ let isFirst = true;
293
+ let buffered = null;
294
+ return coreFn(draft => {
295
+ const {
296
+ proxy
297
+ } = createShadowDraft(draft);
298
+ subFetch(fn, proxy);
299
+ const process = res => {
300
+ if (res.done) return {
301
+ done: true,
302
+ value: undefined
303
+ };
304
+ if (isFirst) {
305
+ isFirst = false;
306
+ signals.setSnapshotCapture(false);
307
+ try {
308
+ if (Array.isArray(res.value)) {
309
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
310
+ draft.length = res.value.length;
311
+ } else {
312
+ Object.assign(draft, res.value);
313
+ }
314
+ } finally {
315
+ signals.setSnapshotCapture(true);
316
+ }
317
+ } else {
318
+ applyPatches(draft, res.value);
319
+ }
320
+ return {
321
+ done: false,
322
+ value: undefined
323
+ };
324
+ };
325
+ return {
326
+ [Symbol.asyncIterator]() {
327
+ return {
328
+ next() {
329
+ if (isFirst) {
330
+ const r = srcIt.next();
331
+ return r && typeof r.then === "function" ? {
332
+ then(fn, rej) {
333
+ r.then(v => fn(process(v)), rej);
334
+ }
335
+ } : syncThenable(process(r));
336
+ }
337
+ if (buffered) {
338
+ const b = buffered;
339
+ buffered = null;
340
+ return b.then(process);
341
+ }
342
+ let r = srcIt.next();
343
+ if (r && typeof r.then === "function") {
344
+ return r.then(process);
345
+ }
346
+ let result = process(r);
347
+ while (!r.done) {
348
+ const peek = srcIt.next();
349
+ if (peek && typeof peek.then === "function") {
350
+ buffered = peek;
351
+ break;
352
+ }
353
+ r = peek;
354
+ if (!r.done) result = process(r);
355
+ }
356
+ return Promise.resolve(result);
357
+ },
358
+ return(value) {
359
+ buffered = null;
360
+ return forwardIteratorReturn(srcIt, value);
361
+ }
362
+ };
363
+ }
364
+ };
365
+ }, initialValue, options);
201
366
  }
202
- function hydratedCreateMemo(compute, value, options) {
203
- if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
367
+ function hydratedCreateMemo(compute, options) {
368
+ if (!sharedConfig.hydrating || options?.transparent) {
369
+ return signals.createMemo(compute, options);
370
+ }
204
371
  markTopLevelSnapshotScope();
205
372
  const ssrSource = options?.ssrSource;
206
373
  if (ssrSource === "client") {
207
- const [hydrated, setHydrated] = signals.createSignal(false);
374
+ const [hydrated, setHydrated] = signals.createSignal(false, {
375
+ ownedWrite: true
376
+ });
208
377
  const memo = signals.createMemo(prev => {
209
- if (!hydrated()) return prev ?? value;
378
+ if (!hydrated()) return prev;
210
379
  return compute(prev);
211
- }, value, options);
380
+ }, options);
212
381
  setHydrated(true);
213
382
  return memo;
214
383
  }
215
- if (ssrSource === "initial") {
216
- return signals.createMemo(prev => {
217
- if (!sharedConfig.hydrating) return compute(prev);
218
- subFetch(compute, prev);
219
- return prev ?? value;
220
- }, value, options);
221
- }
222
- const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
384
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, options);
223
385
  if (aiResult !== null) return aiResult;
224
- return signals.createMemo(prev => {
225
- const o = signals.getOwner();
226
- if (!sharedConfig.hydrating) return compute(prev);
227
- let initP;
228
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
229
- const init = initP?.v ?? initP;
230
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
231
- }, value, options);
232
- }
233
- function hydratedCreateSignal(fn, second, third) {
234
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
386
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), options);
387
+ }
388
+ function hydratedCreateSignal(fn, second) {
389
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second);
235
390
  markTopLevelSnapshotScope();
236
- const ssrSource = third?.ssrSource;
391
+ const ssrSource = second?.ssrSource;
237
392
  if (ssrSource === "client") {
238
- const [hydrated, setHydrated] = signals.createSignal(false);
393
+ const [hydrated, setHydrated] = signals.createSignal(false, {
394
+ ownedWrite: true
395
+ });
239
396
  const sig = signals.createSignal(prev => {
240
- if (!hydrated()) return prev ?? second;
397
+ if (!hydrated()) return prev;
241
398
  return fn(prev);
242
- }, second, third);
399
+ }, second);
243
400
  setHydrated(true);
244
401
  return sig;
245
402
  }
246
- if (ssrSource === "initial") {
247
- return signals.createSignal(prev => {
248
- if (!sharedConfig.hydrating) return fn(prev);
249
- subFetch(fn, prev);
250
- return prev ?? second;
251
- }, second, third);
252
- }
253
- const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
403
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second);
254
404
  if (aiResult !== null) return aiResult;
255
- return signals.createSignal(prev => {
256
- if (!sharedConfig.hydrating) return fn(prev);
257
- const o = signals.getOwner();
258
- let initP;
259
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
260
- const init = initP?.v ?? initP;
261
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
262
- }, second, third);
405
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second);
263
406
  }
264
407
  function hydratedCreateErrorBoundary(fn, fallback) {
265
408
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -281,127 +424,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
281
424
  }
282
425
  return signals.createErrorBoundary(fn, fallback);
283
426
  }
284
- function hydratedCreateOptimistic(fn, second, third) {
285
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
427
+ function hydratedCreateOptimistic(fn, second) {
428
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second);
286
429
  markTopLevelSnapshotScope();
287
- const ssrSource = third?.ssrSource;
430
+ const ssrSource = second?.ssrSource;
288
431
  if (ssrSource === "client") {
289
- const [hydrated, setHydrated] = signals.createSignal(false);
432
+ const [hydrated, setHydrated] = signals.createSignal(false, {
433
+ ownedWrite: true
434
+ });
290
435
  const sig = signals.createOptimistic(prev => {
291
- if (!hydrated()) return prev ?? second;
436
+ if (!hydrated()) return prev;
292
437
  return fn(prev);
293
- }, second, third);
438
+ }, second);
294
439
  setHydrated(true);
295
440
  return sig;
296
441
  }
297
- if (ssrSource === "initial") {
298
- return signals.createOptimistic(prev => {
299
- if (!sharedConfig.hydrating) return fn(prev);
300
- subFetch(fn, prev);
301
- return prev ?? second;
302
- }, second, third);
303
- }
304
- const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
442
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second);
305
443
  if (aiResult !== null) return aiResult;
306
- return signals.createOptimistic(prev => {
307
- const o = signals.getOwner();
308
- if (!sharedConfig.hydrating) return fn(prev);
309
- let initP;
310
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
311
- const init = initP?.v ?? initP;
312
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
313
- }, second, third);
314
- }
315
- function wrapStoreFn(fn, ssrSource) {
316
- if (ssrSource === "initial") {
317
- return draft => {
318
- if (!sharedConfig.hydrating) return fn(draft);
319
- subFetch(fn, draft);
320
- return undefined;
321
- };
444
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second);
445
+ }
446
+ function wrapStoreFn(fn) {
447
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
448
+ }
449
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
450
+ if (ssrSource === "client") {
451
+ const [hydrated, setHydrated] = signals.createSignal(false, {
452
+ ownedWrite: true
453
+ });
454
+ const result = coreFn(draft => {
455
+ if (!hydrated()) return;
456
+ return fn(draft);
457
+ }, initialValue, options);
458
+ setHydrated(true);
459
+ return result;
322
460
  }
323
- return draft => {
324
- const o = signals.getOwner();
325
- if (!sharedConfig.hydrating) return fn(draft);
326
- let initP;
327
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
328
- const init = initP?.v ?? initP;
329
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
330
- };
461
+ if (ssrSource === "hybrid") {
462
+ const [hydrated, setHydrated] = signals.createSignal(false, {
463
+ ownedWrite: true
464
+ });
465
+ const result = coreFn(draft => {
466
+ const o = signals.getOwner();
467
+ if (!hydrated()) {
468
+ if (sharedConfig.has(o.id)) {
469
+ const initP = sharedConfig.load(o.id);
470
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
471
+ if (init !== NO_HYDRATED_VALUE) return init;
472
+ }
473
+ return fn(draft);
474
+ }
475
+ const {
476
+ proxy,
477
+ activate
478
+ } = createShadowDraft(draft);
479
+ const r = fn(proxy);
480
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
481
+ }, initialValue, options);
482
+ setHydrated(true);
483
+ return result;
484
+ }
485
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options);
486
+ if (aiResult !== null) return aiResult;
487
+ return coreFn(wrapStoreFn(fn), initialValue, options);
331
488
  }
332
489
  function hydratedCreateStore(first, second, third) {
333
490
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
334
491
  markTopLevelSnapshotScope();
335
492
  const ssrSource = third?.ssrSource;
336
- if (ssrSource === "client" || ssrSource === "initial") {
337
- return signals.createStore(second ?? {}, undefined, third);
338
- }
339
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
340
- if (aiResult !== null) return aiResult;
341
- return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
493
+ return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
342
494
  }
343
495
  function hydratedCreateOptimisticStore(first, second, third) {
344
496
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
345
497
  markTopLevelSnapshotScope();
346
498
  const ssrSource = third?.ssrSource;
347
- if (ssrSource === "client" || ssrSource === "initial") {
348
- return signals.createOptimisticStore(second ?? {}, undefined, third);
349
- }
350
- const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
351
- if (aiResult !== null) return aiResult;
352
- return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
499
+ return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
353
500
  }
354
501
  function hydratedCreateProjection(fn, initialValue, options) {
355
502
  if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
356
503
  markTopLevelSnapshotScope();
357
504
  const ssrSource = options?.ssrSource;
358
- if (ssrSource === "client" || ssrSource === "initial") {
359
- return signals.createProjection(draft => draft, initialValue, options);
360
- }
361
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
362
- if (aiResult !== null) return aiResult[0];
363
- return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
505
+ return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
364
506
  }
365
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
366
- if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
507
+ function hydratedEffect(coreFn, compute, effectFn, options) {
508
+ if (!sharedConfig.hydrating || options?.transparent) return coreFn(compute, effectFn, options);
367
509
  const ssrSource = options?.ssrSource;
368
510
  if (ssrSource === "client") {
369
- const [hydrated, setHydrated] = signals.createSignal(false);
511
+ const [hydrated, setHydrated] = signals.createSignal(false, {
512
+ ownedWrite: true
513
+ });
370
514
  let active = false;
371
515
  coreFn(prev => {
372
- if (!hydrated()) return value;
516
+ if (!hydrated()) return prev;
373
517
  active = true;
374
518
  return compute(prev);
375
519
  }, (next, prev) => {
376
520
  if (!active) return;
377
521
  return effectFn(next, prev);
378
- }, value, options);
522
+ }, options);
379
523
  setHydrated(true);
380
524
  return;
381
525
  }
382
- if (ssrSource === "initial") {
383
- coreFn(prev => {
384
- if (!sharedConfig.hydrating) return compute(prev);
385
- subFetch(compute, prev);
386
- return prev ?? value;
387
- }, effectFn, value, options);
388
- return;
389
- }
390
526
  markTopLevelSnapshotScope();
391
- coreFn(prev => {
392
- const o = signals.getOwner();
393
- if (!sharedConfig.hydrating) return compute(prev);
394
- let initP;
395
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
396
- const init = initP?.v ?? initP;
397
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
398
- }, effectFn, value, options);
527
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
399
528
  }
400
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
401
- return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
529
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
530
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, options);
402
531
  }
403
- function hydratedCreateEffect(compute, effectFn, value, options) {
404
- return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
532
+ function hydratedCreateEffect(compute, effectFn, options) {
533
+ return hydratedEffect(signals.createEffect, compute, effectFn, options);
405
534
  }
406
535
  function enableHydration() {
407
536
  _createMemo = hydratedCreateMemo;
@@ -460,24 +589,6 @@ const createStore = (...args) => (_createStore || signals.createStore)(...args);
460
589
  const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
461
590
  const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
462
591
  const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
463
- function loadModuleAssets(mapping) {
464
- const hy = globalThis._$HY;
465
- if (!hy) return;
466
- if (!hy.modules) hy.modules = {};
467
- if (!hy.loading) hy.loading = {};
468
- const pending = [];
469
- for (const moduleUrl in mapping) {
470
- if (hy.modules[moduleUrl]) continue;
471
- const entryUrl = mapping[moduleUrl];
472
- if (!hy.loading[moduleUrl]) {
473
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
474
- hy.modules[moduleUrl] = mod;
475
- });
476
- }
477
- pending.push(hy.loading[moduleUrl]);
478
- }
479
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
480
- }
481
592
  function createBoundaryTrigger() {
482
593
  signals.setSnapshotCapture(false);
483
594
  const [s, set] = signals.createSignal(undefined, {
@@ -493,7 +604,7 @@ function resumeBoundaryHydration(o, id, set) {
493
604
  checkHydrationComplete();
494
605
  return;
495
606
  }
496
- sharedConfig.gather(id);
607
+ sharedConfig.gather?.(id);
497
608
  _hydratingValue = true;
498
609
  signals.markSnapshotScope(o);
499
610
  _snapshotRootOwner = o;
@@ -505,38 +616,65 @@ function resumeBoundaryHydration(o, id, set) {
505
616
  signals.flush();
506
617
  checkHydrationComplete();
507
618
  }
508
- function Loading(props) {
509
- if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
619
+ function initBoundaryResume(o, id) {
620
+ _pendingBoundaries++;
621
+ signals.onCleanup(() => {
622
+ if (!signals.isDisposed(o)) return;
623
+ sharedConfig.cleanupFragment?.(id);
624
+ });
625
+ const set = createBoundaryTrigger();
626
+ return [set, () => resumeBoundaryHydration(o, id, set)];
627
+ }
628
+ function waitAndResume(p, resume, assetPromise) {
629
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
630
+ waitFor.then(() => {
631
+ if (p && typeof p === "object") p.s = 1;
632
+ resume();
633
+ }, err => {
634
+ if (p && typeof p === "object") {
635
+ p.s = 2;
636
+ p.v = err;
637
+ }
638
+ resume();
639
+ });
640
+ }
641
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
642
+ sharedConfig.gather?.(id);
643
+ const doResume = () => queueMicrotask(resume);
644
+ if (assetPromise) {
645
+ assetPromise.then(doResume);
646
+ return true;
647
+ }
648
+ doResume();
649
+ return false;
650
+ }
651
+ function createLoadingBoundary(fn, fallback, options) {
652
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
653
+ let settledSerializationResumeQueued = false;
510
654
  return signals.createMemo(() => {
511
655
  const o = signals.getOwner();
512
656
  const id = o.id;
513
657
  let assetPromise;
514
658
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
515
659
  const mapping = sharedConfig.load(id + "_assets");
516
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
660
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
517
661
  }
518
662
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
519
- let ref = sharedConfig.load(id);
663
+ const ref = sharedConfig.load(id);
520
664
  let p;
521
665
  if (ref) {
522
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
666
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
667
+ }
668
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
669
+ settledSerializationResumeQueued = true;
670
+ const [, resume] = initBoundaryResume(o, id);
671
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
672
+ return fallback();
523
673
  }
524
674
  if (p) {
525
- _pendingBoundaries++;
526
- signals.onCleanup(() => {
527
- if (!signals.isDisposed(o)) return;
528
- sharedConfig.cleanupFragment?.(id);
529
- });
530
- const set = createBoundaryTrigger();
675
+ const [set, resume] = initBoundaryResume(o, id);
531
676
  if (p !== "$$f") {
532
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
533
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
534
- _pendingBoundaries--;
535
- checkHydrationComplete();
536
- signals.runWithOwner(o, () => {
537
- throw err;
538
- });
539
- });
677
+ waitAndResume(p, resume, assetPromise);
540
678
  } else {
541
679
  const afterAssets = () => {
542
680
  _pendingBoundaries--;
@@ -545,18 +683,39 @@ function Loading(props) {
545
683
  };
546
684
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
547
685
  }
548
- return props.fallback;
686
+ return fallback();
687
+ }
688
+ }
689
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
690
+ settledSerializationResumeQueued = true;
691
+ const fr = sharedConfig.load(id + "_fr");
692
+ const [, resume] = initBoundaryResume(o, id);
693
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
694
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
695
+ return fallback();
549
696
  }
697
+ waitAndResume(fr, resume, assetPromise);
698
+ return fallback();
550
699
  }
551
- if (assetPromise) {
552
- _pendingBoundaries++;
553
- const set = createBoundaryTrigger();
554
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
700
+ if (assetPromise && !sharedConfig.has(id)) {
701
+ const [, resume] = initBoundaryResume(o, id);
702
+ assetPromise.then(resume);
555
703
  return undefined;
556
704
  }
557
- return signals.createLoadBoundary(() => props.children, () => props.fallback);
705
+ return signals.createLoadingBoundary(fn, fallback, options);
706
+ });
707
+ }
708
+ function NoHydration(props) {
709
+ const o = signals.createOwner();
710
+ return signals.runWithOwner(o, () => {
711
+ signals.setContext(NoHydrateContext, true);
712
+ if (sharedConfig.hydrating) return undefined;
713
+ return props.children;
558
714
  });
559
715
  }
716
+ function Hydration(props) {
717
+ return props.children;
718
+ }
560
719
 
561
720
  function createComponent(Comp, props) {
562
721
  return signals.untrack(() => Comp(props || {}));
@@ -585,6 +744,7 @@ function lazy(fn, moduleUrl) {
585
744
  }) : "");
586
745
  };
587
746
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
747
+ wrap.moduleUrl = moduleUrl;
588
748
  return wrap;
589
749
  }
590
750
  let counter = 0;
@@ -611,8 +771,8 @@ function Repeat(props) {
611
771
  }
612
772
  function Show(props) {
613
773
  const keyed = props.keyed;
614
- const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
615
- const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
774
+ const conditionValue = signals.createMemo(() => props.when, undefined);
775
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, {
616
776
  equals: (a, b) => !a === !b
617
777
  });
618
778
  return signals.createMemo(() => {
@@ -620,18 +780,13 @@ function Show(props) {
620
780
  if (c) {
621
781
  const child = props.children;
622
782
  const fn = typeof child === "function" && child.length > 0;
623
- return fn ? signals.untrack(() => {
624
- try {
625
- return child(() => {
626
- if (!signals.untrack(condition)) throw narrowedError("Show");
627
- return conditionValue();
628
- });
629
- } finally {
630
- }
631
- }) : child;
783
+ return fn ? signals.untrack(() => child(() => {
784
+ if (!signals.untrack(condition)) throw narrowedError("Show");
785
+ return conditionValue();
786
+ }), IS_DEV) : child;
632
787
  }
633
788
  return props.fallback;
634
- }, undefined, undefined);
789
+ }, undefined);
635
790
  }
636
791
  function Switch(props) {
637
792
  const chs = children(() => props.children);
@@ -642,8 +797,8 @@ function Switch(props) {
642
797
  const index = i;
643
798
  const mp = mps[i];
644
799
  const prevFunc = func;
645
- const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
646
- const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
800
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined);
801
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, {
647
802
  equals: (a, b) => !a === !b
648
803
  });
649
804
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
@@ -656,16 +811,11 @@ function Switch(props) {
656
811
  const [index, conditionValue, mp] = sel;
657
812
  const child = mp.children;
658
813
  const fn = typeof child === "function" && child.length > 0;
659
- return fn ? signals.untrack(() => {
660
- try {
661
- return child(() => {
662
- if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
663
- return conditionValue();
664
- });
665
- } finally {
666
- }
667
- }) : child;
668
- }, undefined, undefined);
814
+ return fn ? signals.untrack(() => child(() => {
815
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
816
+ return conditionValue();
817
+ }), IS_DEV) : child;
818
+ }, undefined);
669
819
  }
670
820
  function Match(props) {
671
821
  return props;
@@ -676,6 +826,18 @@ function Errored(props) {
676
826
  return typeof f === "function" && f.length ? f(err, reset) : f;
677
827
  });
678
828
  }
829
+ function Loading(props) {
830
+ const onOpt = "on" in props ? {
831
+ on: () => props.on
832
+ } : undefined;
833
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
834
+ }
835
+ function Reveal(props) {
836
+ return signals.createRevealOrder(() => props.children, {
837
+ order: () => props.order ?? "sequential",
838
+ collapsed: () => !!props.collapsed
839
+ });
840
+ }
679
841
 
680
842
  function ssrHandleError() {}
681
843
  function ssrRunInScope() {}
@@ -685,6 +847,10 @@ Object.defineProperty(exports, "$PROXY", {
685
847
  enumerable: true,
686
848
  get: function () { return signals.$PROXY; }
687
849
  });
850
+ Object.defineProperty(exports, "$REFRESH", {
851
+ enumerable: true,
852
+ get: function () { return signals.$REFRESH; }
853
+ });
688
854
  Object.defineProperty(exports, "$TRACK", {
689
855
  enumerable: true,
690
856
  get: function () { return signals.$TRACK; }
@@ -705,6 +871,10 @@ Object.defineProperty(exports, "createReaction", {
705
871
  enumerable: true,
706
872
  get: function () { return signals.createReaction; }
707
873
  });
874
+ Object.defineProperty(exports, "createRevealOrder", {
875
+ enumerable: true,
876
+ get: function () { return signals.createRevealOrder; }
877
+ });
708
878
  Object.defineProperty(exports, "createRoot", {
709
879
  enumerable: true,
710
880
  get: function () { return signals.createRoot; }
@@ -717,6 +887,14 @@ Object.defineProperty(exports, "deep", {
717
887
  enumerable: true,
718
888
  get: function () { return signals.deep; }
719
889
  });
890
+ Object.defineProperty(exports, "enableExternalSource", {
891
+ enumerable: true,
892
+ get: function () { return signals.enableExternalSource; }
893
+ });
894
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
895
+ enumerable: true,
896
+ get: function () { return signals.enforceLoadingBoundary; }
897
+ });
720
898
  Object.defineProperty(exports, "flatten", {
721
899
  enumerable: true,
722
900
  get: function () { return signals.flatten; }
@@ -737,6 +915,10 @@ Object.defineProperty(exports, "getOwner", {
737
915
  enumerable: true,
738
916
  get: function () { return signals.getOwner; }
739
917
  });
918
+ Object.defineProperty(exports, "isDisposed", {
919
+ enumerable: true,
920
+ get: function () { return signals.isDisposed; }
921
+ });
740
922
  Object.defineProperty(exports, "isEqual", {
741
923
  enumerable: true,
742
924
  get: function () { return signals.isEqual; }
@@ -813,15 +995,21 @@ exports.$DEVCOMP = $DEVCOMP;
813
995
  exports.DEV = DEV;
814
996
  exports.Errored = Errored;
815
997
  exports.For = For;
998
+ exports.Hydration = Hydration;
816
999
  exports.Loading = Loading;
817
1000
  exports.Match = Match;
1001
+ exports.NoHydrateContext = NoHydrateContext;
1002
+ exports.NoHydration = NoHydration;
818
1003
  exports.Repeat = Repeat;
1004
+ exports.Reveal = Reveal;
819
1005
  exports.Show = Show;
820
1006
  exports.Switch = Switch;
821
1007
  exports.children = children;
822
1008
  exports.createComponent = createComponent;
823
1009
  exports.createContext = createContext;
824
1010
  exports.createEffect = createEffect;
1011
+ exports.createErrorBoundary = createErrorBoundary;
1012
+ exports.createLoadingBoundary = createLoadingBoundary;
825
1013
  exports.createMemo = createMemo;
826
1014
  exports.createOptimistic = createOptimistic;
827
1015
  exports.createOptimisticStore = createOptimisticStore;