solid-js 2.0.0-beta.1 → 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 +431 -283
  4. package/dist/dev.js +411 -286
  5. package/dist/server.cjs +701 -281
  6. package/dist/server.js +684 -284
  7. package/dist/solid.cjs +423 -255
  8. package/dist/solid.js +403 -258
  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 +514 -36
  14. package/types/index.d.ts +9 -12
  15. package/types/server/component.d.ts +11 -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 +34 -9
  19. package/types/server/index.d.ts +5 -7
  20. package/types/server/shared.d.ts +5 -1
  21. package/types/server/signals.d.ts +44 -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 +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, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, untrack, mapArray, repeat } from '@solidjs/signals';
2
- export { $PROXY, $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 = () => {
@@ -70,6 +71,7 @@ function drainHydrationCallbacks() {
70
71
  if (cbs) for (const cb of cbs) cb();
71
72
  setTimeout(() => {
72
73
  if (globalThis._$HY) globalThis._$HY.done = true;
74
+ sharedConfig.registry?.clear();
73
75
  });
74
76
  }
75
77
  function checkHydrationComplete() {
@@ -87,23 +89,10 @@ let _createOptimisticStore;
87
89
  let _createRenderEffect;
88
90
  let _createEffect;
89
91
  class MockPromise {
90
- static all() {
91
- return new MockPromise();
92
- }
93
- static allSettled() {
94
- return new MockPromise();
95
- }
96
- static any() {
97
- return new MockPromise();
98
- }
99
- static race() {
100
- return new MockPromise();
101
- }
102
- static reject() {
103
- return new MockPromise();
104
- }
105
- static resolve() {
106
- return new MockPromise();
92
+ static {
93
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
94
+ MockPromise[k] = () => new MockPromise();
95
+ }
107
96
  }
108
97
  catch() {
109
98
  return new MockPromise();
@@ -131,11 +120,67 @@ function subFetch(fn, prev) {
131
120
  Promise = ogPromise;
132
121
  }
133
122
  }
134
- function consumeFirstSync(ai) {
135
- const iter = ai[Symbol.asyncIterator]();
136
- const r = iter.next();
137
- const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
138
- 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
+ };
139
184
  }
140
185
  function applyPatches(target, patches) {
141
186
  for (const patch of patches) {
@@ -152,118 +197,211 @@ function applyPatches(target, patches) {
152
197
  }
153
198
  }
154
199
  }
155
- function scheduleIteratorConsumption(iter, apply) {
156
- const consume = () => {
157
- while (true) {
158
- const n = iter.next();
159
- if (n instanceof Promise) {
160
- n.then(r => {
161
- if (r.done) return;
162
- apply(r.value);
163
- consume();
164
- });
165
- 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);
166
233
  }
167
- if (n.done) break;
168
- apply(n.value);
234
+ }),
235
+ activate() {
236
+ useShadow = false;
169
237
  }
170
238
  };
171
- consume();
172
239
  }
173
- function isAsyncIterable(v) {
174
- 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
+ };
175
266
  }
176
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
267
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
177
268
  const parent = getOwner();
178
269
  const expectedId = peekNextChildId(parent);
179
270
  if (!sharedConfig.has(expectedId)) return null;
180
- const initP = sharedConfig.load(expectedId);
181
- if (!isAsyncIterable(initP)) return null;
182
- const [firstValue, iter] = consumeFirstSync(initP);
183
- const [get, set] = createSignal$1(firstValue);
184
- const result = coreFn(() => get(), firstValue, options);
185
- scheduleIteratorConsumption(iter, v => {
186
- set(() => v);
187
- flush();
188
- });
189
- 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);
190
283
  }
191
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
284
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
192
285
  const parent = getOwner();
193
286
  const expectedId = peekNextChildId(parent);
194
287
  if (!sharedConfig.has(expectedId)) return null;
195
- const initP = sharedConfig.load(expectedId);
196
- if (!isAsyncIterable(initP)) return null;
197
- const [firstState, iter] = consumeFirstSync(initP);
198
- const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
199
- scheduleIteratorConsumption(iter, patches => {
200
- setStore(d => {
201
- applyPatches(d, patches);
202
- });
203
- });
204
- 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);
205
365
  }
206
- function hydratedCreateMemo(compute, value, options) {
207
- 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
+ }
208
370
  markTopLevelSnapshotScope();
209
371
  const ssrSource = options?.ssrSource;
210
372
  if (ssrSource === "client") {
211
- const [hydrated, setHydrated] = createSignal$1(false);
373
+ const [hydrated, setHydrated] = createSignal$1(false, {
374
+ ownedWrite: true
375
+ });
212
376
  const memo = createMemo$1(prev => {
213
- if (!hydrated()) return prev ?? value;
377
+ if (!hydrated()) return prev;
214
378
  return compute(prev);
215
- }, value, options);
379
+ }, options);
216
380
  setHydrated(true);
217
381
  return memo;
218
382
  }
219
- if (ssrSource === "initial") {
220
- return createMemo$1(prev => {
221
- if (!sharedConfig.hydrating) return compute(prev);
222
- subFetch(compute, prev);
223
- return prev ?? value;
224
- }, value, options);
225
- }
226
- const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, value, options);
383
+ const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, options);
227
384
  if (aiResult !== null) return aiResult;
228
- return createMemo$1(prev => {
229
- const o = getOwner();
230
- if (!sharedConfig.hydrating) return compute(prev);
231
- let initP;
232
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
233
- const init = initP?.v ?? initP;
234
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
235
- }, value, options);
236
- }
237
- function hydratedCreateSignal(fn, second, third) {
238
- 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);
239
389
  markTopLevelSnapshotScope();
240
- const ssrSource = third?.ssrSource;
390
+ const ssrSource = second?.ssrSource;
241
391
  if (ssrSource === "client") {
242
- const [hydrated, setHydrated] = createSignal$1(false);
392
+ const [hydrated, setHydrated] = createSignal$1(false, {
393
+ ownedWrite: true
394
+ });
243
395
  const sig = createSignal$1(prev => {
244
- if (!hydrated()) return prev ?? second;
396
+ if (!hydrated()) return prev;
245
397
  return fn(prev);
246
- }, second, third);
398
+ }, second);
247
399
  setHydrated(true);
248
400
  return sig;
249
401
  }
250
- if (ssrSource === "initial") {
251
- return createSignal$1(prev => {
252
- if (!sharedConfig.hydrating) return fn(prev);
253
- subFetch(fn, prev);
254
- return prev ?? second;
255
- }, second, third);
256
- }
257
- const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second, third);
402
+ const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second);
258
403
  if (aiResult !== null) return aiResult;
259
- return createSignal$1(prev => {
260
- if (!sharedConfig.hydrating) return fn(prev);
261
- const o = getOwner();
262
- let initP;
263
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
264
- const init = initP?.v ?? initP;
265
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
266
- }, second, third);
404
+ return createSignal$1(prev => readSerializedOrCompute(fn, prev), second);
267
405
  }
268
406
  function hydratedCreateErrorBoundary(fn, fallback) {
269
407
  if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
@@ -285,127 +423,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
285
423
  }
286
424
  return createErrorBoundary$1(fn, fallback);
287
425
  }
288
- function hydratedCreateOptimistic(fn, second, third) {
289
- 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);
290
428
  markTopLevelSnapshotScope();
291
- const ssrSource = third?.ssrSource;
429
+ const ssrSource = second?.ssrSource;
292
430
  if (ssrSource === "client") {
293
- const [hydrated, setHydrated] = createSignal$1(false);
431
+ const [hydrated, setHydrated] = createSignal$1(false, {
432
+ ownedWrite: true
433
+ });
294
434
  const sig = createOptimistic$1(prev => {
295
- if (!hydrated()) return prev ?? second;
435
+ if (!hydrated()) return prev;
296
436
  return fn(prev);
297
- }, second, third);
437
+ }, second);
298
438
  setHydrated(true);
299
439
  return sig;
300
440
  }
301
- if (ssrSource === "initial") {
302
- return createOptimistic$1(prev => {
303
- if (!sharedConfig.hydrating) return fn(prev);
304
- subFetch(fn, prev);
305
- return prev ?? second;
306
- }, second, third);
307
- }
308
- const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second, third);
441
+ const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second);
309
442
  if (aiResult !== null) return aiResult;
310
- return createOptimistic$1(prev => {
311
- const o = getOwner();
312
- if (!sharedConfig.hydrating) return fn(prev);
313
- let initP;
314
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
315
- const init = initP?.v ?? initP;
316
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
317
- }, second, third);
318
- }
319
- function wrapStoreFn(fn, ssrSource) {
320
- if (ssrSource === "initial") {
321
- return draft => {
322
- if (!sharedConfig.hydrating) return fn(draft);
323
- subFetch(fn, draft);
324
- return undefined;
325
- };
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;
326
459
  }
327
- return draft => {
328
- const o = getOwner();
329
- if (!sharedConfig.hydrating) return fn(draft);
330
- let initP;
331
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
332
- const init = initP?.v ?? initP;
333
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
334
- };
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);
335
487
  }
336
488
  function hydratedCreateStore(first, second, third) {
337
489
  if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
338
490
  markTopLevelSnapshotScope();
339
491
  const ssrSource = third?.ssrSource;
340
- if (ssrSource === "client" || ssrSource === "initial") {
341
- return createStore$1(second ?? {}, undefined, third);
342
- }
343
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
344
- if (aiResult !== null) return aiResult;
345
- return createStore$1(wrapStoreFn(first, ssrSource), second, third);
492
+ return hydrateStoreLikeFn(createStore$1, first, second ?? {}, third, ssrSource);
346
493
  }
347
494
  function hydratedCreateOptimisticStore(first, second, third) {
348
495
  if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
349
496
  markTopLevelSnapshotScope();
350
497
  const ssrSource = third?.ssrSource;
351
- if (ssrSource === "client" || ssrSource === "initial") {
352
- return createOptimisticStore$1(second ?? {}, undefined, third);
353
- }
354
- const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
355
- if (aiResult !== null) return aiResult;
356
- return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
498
+ return hydrateStoreLikeFn(createOptimisticStore$1, first, second ?? {}, third, ssrSource);
357
499
  }
358
500
  function hydratedCreateProjection(fn, initialValue, options) {
359
501
  if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
360
502
  markTopLevelSnapshotScope();
361
503
  const ssrSource = options?.ssrSource;
362
- if (ssrSource === "client" || ssrSource === "initial") {
363
- return createProjection$1(draft => draft, initialValue, options);
364
- }
365
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, initialValue, options);
366
- if (aiResult !== null) return aiResult[0];
367
- return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
504
+ return hydrateStoreLikeFn(createProjection$1, fn, initialValue, options, ssrSource);
368
505
  }
369
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
370
- 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);
371
508
  const ssrSource = options?.ssrSource;
372
509
  if (ssrSource === "client") {
373
- const [hydrated, setHydrated] = createSignal$1(false);
510
+ const [hydrated, setHydrated] = createSignal$1(false, {
511
+ ownedWrite: true
512
+ });
374
513
  let active = false;
375
514
  coreFn(prev => {
376
- if (!hydrated()) return value;
515
+ if (!hydrated()) return prev;
377
516
  active = true;
378
517
  return compute(prev);
379
518
  }, (next, prev) => {
380
519
  if (!active) return;
381
520
  return effectFn(next, prev);
382
- }, value, options);
521
+ }, options);
383
522
  setHydrated(true);
384
523
  return;
385
524
  }
386
- if (ssrSource === "initial") {
387
- coreFn(prev => {
388
- if (!sharedConfig.hydrating) return compute(prev);
389
- subFetch(compute, prev);
390
- return prev ?? value;
391
- }, effectFn, value, options);
392
- return;
393
- }
394
525
  markTopLevelSnapshotScope();
395
- coreFn(prev => {
396
- const o = getOwner();
397
- if (!sharedConfig.hydrating) return compute(prev);
398
- let initP;
399
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
400
- const init = initP?.v ?? initP;
401
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
402
- }, effectFn, value, options);
526
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
403
527
  }
404
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
405
- return hydratedEffect(createRenderEffect$1, compute, effectFn, value, options);
528
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
529
+ return hydratedEffect(createRenderEffect$1, compute, effectFn, options);
406
530
  }
407
- function hydratedCreateEffect(compute, effectFn, value, options) {
408
- return hydratedEffect(createEffect$1, compute, effectFn, value, options);
531
+ function hydratedCreateEffect(compute, effectFn, options) {
532
+ return hydratedEffect(createEffect$1, compute, effectFn, options);
409
533
  }
410
534
  function enableHydration() {
411
535
  _createMemo = hydratedCreateMemo;
@@ -464,24 +588,6 @@ const createStore = (...args) => (_createStore || createStore$1)(...args);
464
588
  const createOptimisticStore = (...args) => (_createOptimisticStore || createOptimisticStore$1)(...args);
465
589
  const createRenderEffect = (...args) => (_createRenderEffect || createRenderEffect$1)(...args);
466
590
  const createEffect = (...args) => (_createEffect || createEffect$1)(...args);
467
- function loadModuleAssets(mapping) {
468
- const hy = globalThis._$HY;
469
- if (!hy) return;
470
- if (!hy.modules) hy.modules = {};
471
- if (!hy.loading) hy.loading = {};
472
- const pending = [];
473
- for (const moduleUrl in mapping) {
474
- if (hy.modules[moduleUrl]) continue;
475
- const entryUrl = mapping[moduleUrl];
476
- if (!hy.loading[moduleUrl]) {
477
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
478
- hy.modules[moduleUrl] = mod;
479
- });
480
- }
481
- pending.push(hy.loading[moduleUrl]);
482
- }
483
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
484
- }
485
591
  function createBoundaryTrigger() {
486
592
  setSnapshotCapture(false);
487
593
  const [s, set] = createSignal$1(undefined, {
@@ -497,7 +603,7 @@ function resumeBoundaryHydration(o, id, set) {
497
603
  checkHydrationComplete();
498
604
  return;
499
605
  }
500
- sharedConfig.gather(id);
606
+ sharedConfig.gather?.(id);
501
607
  _hydratingValue = true;
502
608
  markSnapshotScope(o);
503
609
  _snapshotRootOwner = o;
@@ -509,38 +615,65 @@ function resumeBoundaryHydration(o, id, set) {
509
615
  flush();
510
616
  checkHydrationComplete();
511
617
  }
512
- function Loading(props) {
513
- 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;
514
653
  return createMemo$1(() => {
515
654
  const o = getOwner();
516
655
  const id = o.id;
517
656
  let assetPromise;
518
657
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
519
658
  const mapping = sharedConfig.load(id + "_assets");
520
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
659
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
521
660
  }
522
661
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
523
- let ref = sharedConfig.load(id);
662
+ const ref = sharedConfig.load(id);
524
663
  let p;
525
664
  if (ref) {
526
- 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();
527
672
  }
528
673
  if (p) {
529
- _pendingBoundaries++;
530
- onCleanup(() => {
531
- if (!isDisposed(o)) return;
532
- sharedConfig.cleanupFragment?.(id);
533
- });
534
- const set = createBoundaryTrigger();
674
+ const [set, resume] = initBoundaryResume(o, id);
535
675
  if (p !== "$$f") {
536
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
537
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
538
- _pendingBoundaries--;
539
- checkHydrationComplete();
540
- runWithOwner(o, () => {
541
- throw err;
542
- });
543
- });
676
+ waitAndResume(p, resume, assetPromise);
544
677
  } else {
545
678
  const afterAssets = () => {
546
679
  _pendingBoundaries--;
@@ -549,16 +682,26 @@ function Loading(props) {
549
682
  };
550
683
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
551
684
  }
552
- return props.fallback;
685
+ return fallback();
553
686
  }
554
687
  }
555
- if (assetPromise) {
556
- _pendingBoundaries++;
557
- const set = createBoundaryTrigger();
558
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
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();
695
+ }
696
+ waitAndResume(fr, resume, assetPromise);
697
+ return fallback();
698
+ }
699
+ if (assetPromise && !sharedConfig.has(id)) {
700
+ const [, resume] = initBoundaryResume(o, id);
701
+ assetPromise.then(resume);
559
702
  return undefined;
560
703
  }
561
- return createLoadBoundary(() => props.children, () => props.fallback);
704
+ return createLoadingBoundary$1(fn, fallback, options);
562
705
  });
563
706
  }
564
707
  function NoHydration(props) {
@@ -627,8 +770,8 @@ function Repeat(props) {
627
770
  }
628
771
  function Show(props) {
629
772
  const keyed = props.keyed;
630
- const conditionValue = createMemo$1(() => props.when, undefined, undefined);
631
- const condition = keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
773
+ const conditionValue = createMemo$1(() => props.when, undefined);
774
+ const condition = keyed ? conditionValue : createMemo$1(conditionValue, {
632
775
  equals: (a, b) => !a === !b
633
776
  });
634
777
  return createMemo$1(() => {
@@ -636,18 +779,13 @@ function Show(props) {
636
779
  if (c) {
637
780
  const child = props.children;
638
781
  const fn = typeof child === "function" && child.length > 0;
639
- return fn ? untrack(() => {
640
- try {
641
- return child(() => {
642
- if (!untrack(condition)) throw narrowedError("Show");
643
- return conditionValue();
644
- });
645
- } finally {
646
- }
647
- }) : child;
782
+ return fn ? untrack(() => child(() => {
783
+ if (!untrack(condition)) throw narrowedError("Show");
784
+ return conditionValue();
785
+ }), IS_DEV) : child;
648
786
  }
649
787
  return props.fallback;
650
- }, undefined, undefined);
788
+ }, undefined);
651
789
  }
652
790
  function Switch(props) {
653
791
  const chs = children(() => props.children);
@@ -658,8 +796,8 @@ function Switch(props) {
658
796
  const index = i;
659
797
  const mp = mps[i];
660
798
  const prevFunc = func;
661
- const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined, undefined);
662
- 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, {
663
801
  equals: (a, b) => !a === !b
664
802
  });
665
803
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
@@ -672,16 +810,11 @@ function Switch(props) {
672
810
  const [index, conditionValue, mp] = sel;
673
811
  const child = mp.children;
674
812
  const fn = typeof child === "function" && child.length > 0;
675
- return fn ? untrack(() => {
676
- try {
677
- return child(() => {
678
- if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
679
- return conditionValue();
680
- });
681
- } finally {
682
- }
683
- }) : child;
684
- }, 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);
685
818
  }
686
819
  function Match(props) {
687
820
  return props;
@@ -692,9 +825,21 @@ function Errored(props) {
692
825
  return typeof f === "function" && f.length ? f(err, reset) : f;
693
826
  });
694
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
+ }
695
840
 
696
841
  function ssrHandleError() {}
697
842
  function ssrRunInScope() {}
698
843
  const DEV = undefined;
699
844
 
700
- export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, 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 };