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