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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHEATSHEET.md +640 -0
  2. package/README.md +42 -188
  3. package/dist/dev.cjs +446 -291
  4. package/dist/dev.js +426 -293
  5. package/dist/server.cjs +941 -345
  6. package/dist/server.js +897 -299
  7. package/dist/solid.cjs +438 -261
  8. package/dist/solid.js +418 -263
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +64 -19
  11. package/types/client/core.d.ts +110 -34
  12. package/types/client/flow.d.ts +176 -42
  13. package/types/client/hydration.d.ts +513 -37
  14. package/types/index.d.ts +8 -13
  15. package/types/server/component.d.ts +11 -11
  16. package/types/server/core.d.ts +19 -21
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +34 -9
  19. package/types/server/index.d.ts +6 -8
  20. package/types/server/shared.d.ts +10 -2
  21. package/types/server/signals.d.ts +80 -19
  22. package/types/types.d.ts +15 -0
  23. package/types-cjs/client/component.d.cts +120 -0
  24. package/types-cjs/client/core.d.cts +141 -0
  25. package/types-cjs/client/flow.d.cts +234 -0
  26. package/types-cjs/client/hydration.d.cts +568 -0
  27. package/types-cjs/index.d.cts +15 -0
  28. package/types-cjs/package.json +3 -0
  29. package/types-cjs/server/component.d.cts +67 -0
  30. package/types-cjs/server/core.d.cts +42 -0
  31. package/types-cjs/server/flow.d.cts +115 -0
  32. package/types-cjs/server/hydration.d.cts +63 -0
  33. package/types-cjs/server/index.d.cts +10 -0
  34. package/types-cjs/server/shared.d.cts +54 -0
  35. package/types-cjs/server/signals.d.cts +123 -0
  36. package/types-cjs/types.d.cts +15 -0
  37. package/jsx-runtime.d.ts +0 -1
  38. package/types/jsx.d.ts +0 -4129
package/dist/solid.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,11 +19,12 @@ 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
- lazy: true
25
+ const memo = createMemo$1(() => flatten(c()), {
26
+ lazy: true,
27
+ sync: true
26
28
  });
27
29
  memo.toArray = () => {
28
30
  const v = memo();
@@ -70,6 +72,7 @@ function drainHydrationCallbacks() {
70
72
  if (cbs) for (const cb of cbs) cb();
71
73
  setTimeout(() => {
72
74
  if (globalThis._$HY) globalThis._$HY.done = true;
75
+ sharedConfig.registry?.clear();
73
76
  });
74
77
  }
75
78
  function checkHydrationComplete() {
@@ -87,23 +90,10 @@ let _createOptimisticStore;
87
90
  let _createRenderEffect;
88
91
  let _createEffect;
89
92
  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();
93
+ static {
94
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
95
+ MockPromise[k] = () => new MockPromise();
96
+ }
107
97
  }
108
98
  catch() {
109
99
  return new MockPromise();
@@ -131,11 +121,67 @@ function subFetch(fn, prev) {
131
121
  Promise = ogPromise;
132
122
  }
133
123
  }
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];
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 = 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
+ };
139
185
  }
140
186
  function applyPatches(target, patches) {
141
187
  for (const patch of patches) {
@@ -152,118 +198,211 @@ function applyPatches(target, patches) {
152
198
  }
153
199
  }
154
200
  }
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;
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);
166
234
  }
167
- if (n.done) break;
168
- apply(n.value);
235
+ }),
236
+ activate() {
237
+ useShadow = false;
169
238
  }
170
239
  };
171
- consume();
172
240
  }
173
- function isAsyncIterable(v) {
174
- 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
+ };
175
267
  }
176
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
268
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
177
269
  const parent = getOwner();
178
270
  const expectedId = peekNextChildId(parent);
179
271
  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;
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);
190
284
  }
191
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
285
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
192
286
  const parent = getOwner();
193
287
  const expectedId = peekNextChildId(parent);
194
288
  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];
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
+ 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
+ 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);
205
366
  }
206
- function hydratedCreateMemo(compute, value, options) {
207
- if (!sharedConfig.hydrating) return createMemo$1(compute, value, options);
367
+ function hydratedCreateMemo(compute, options) {
368
+ if (!sharedConfig.hydrating || options?.transparent) {
369
+ return createMemo$1(compute, options);
370
+ }
208
371
  markTopLevelSnapshotScope();
209
372
  const ssrSource = options?.ssrSource;
210
373
  if (ssrSource === "client") {
211
- const [hydrated, setHydrated] = createSignal$1(false);
374
+ const [hydrated, setHydrated] = createSignal$1(false, {
375
+ ownedWrite: true
376
+ });
212
377
  const memo = createMemo$1(prev => {
213
- if (!hydrated()) return prev ?? value;
378
+ if (!hydrated()) return prev;
214
379
  return compute(prev);
215
- }, value, options);
380
+ }, options);
216
381
  setHydrated(true);
217
382
  return memo;
218
383
  }
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);
384
+ const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, options);
227
385
  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);
386
+ return createMemo$1(prev => readSerializedOrCompute(compute, prev), options);
387
+ }
388
+ function hydratedCreateSignal(fn, second) {
389
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second);
239
390
  markTopLevelSnapshotScope();
240
- const ssrSource = third?.ssrSource;
391
+ const ssrSource = second?.ssrSource;
241
392
  if (ssrSource === "client") {
242
- const [hydrated, setHydrated] = createSignal$1(false);
393
+ const [hydrated, setHydrated] = createSignal$1(false, {
394
+ ownedWrite: true
395
+ });
243
396
  const sig = createSignal$1(prev => {
244
- if (!hydrated()) return prev ?? second;
397
+ if (!hydrated()) return prev;
245
398
  return fn(prev);
246
- }, second, third);
399
+ }, second);
247
400
  setHydrated(true);
248
401
  return sig;
249
402
  }
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);
403
+ const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second);
258
404
  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);
405
+ return createSignal$1(prev => readSerializedOrCompute(fn, prev), second);
267
406
  }
268
407
  function hydratedCreateErrorBoundary(fn, fallback) {
269
408
  if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
@@ -285,127 +424,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
285
424
  }
286
425
  return createErrorBoundary$1(fn, fallback);
287
426
  }
288
- function hydratedCreateOptimistic(fn, second, third) {
289
- if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second, third);
427
+ function hydratedCreateOptimistic(fn, second) {
428
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second);
290
429
  markTopLevelSnapshotScope();
291
- const ssrSource = third?.ssrSource;
430
+ const ssrSource = second?.ssrSource;
292
431
  if (ssrSource === "client") {
293
- const [hydrated, setHydrated] = createSignal$1(false);
432
+ const [hydrated, setHydrated] = createSignal$1(false, {
433
+ ownedWrite: true
434
+ });
294
435
  const sig = createOptimistic$1(prev => {
295
- if (!hydrated()) return prev ?? second;
436
+ if (!hydrated()) return prev;
296
437
  return fn(prev);
297
- }, second, third);
438
+ }, second);
298
439
  setHydrated(true);
299
440
  return sig;
300
441
  }
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);
442
+ const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second);
309
443
  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
- };
444
+ return createOptimistic$1(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] = createSignal$1(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;
326
460
  }
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
- };
461
+ if (ssrSource === "hybrid") {
462
+ const [hydrated, setHydrated] = createSignal$1(false, {
463
+ ownedWrite: true
464
+ });
465
+ const result = coreFn(draft => {
466
+ const o = 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);
335
488
  }
336
489
  function hydratedCreateStore(first, second, third) {
337
490
  if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
338
491
  markTopLevelSnapshotScope();
339
492
  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);
493
+ return hydrateStoreLikeFn(createStore$1, first, second ?? {}, third, ssrSource);
346
494
  }
347
495
  function hydratedCreateOptimisticStore(first, second, third) {
348
496
  if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
349
497
  markTopLevelSnapshotScope();
350
498
  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);
499
+ return hydrateStoreLikeFn(createOptimisticStore$1, first, second ?? {}, third, ssrSource);
357
500
  }
358
501
  function hydratedCreateProjection(fn, initialValue, options) {
359
502
  if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
360
503
  markTopLevelSnapshotScope();
361
504
  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);
505
+ return hydrateStoreLikeFn(createProjection$1, fn, initialValue, options, ssrSource);
368
506
  }
369
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
370
- 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);
371
509
  const ssrSource = options?.ssrSource;
372
510
  if (ssrSource === "client") {
373
- const [hydrated, setHydrated] = createSignal$1(false);
511
+ const [hydrated, setHydrated] = createSignal$1(false, {
512
+ ownedWrite: true
513
+ });
374
514
  let active = false;
375
515
  coreFn(prev => {
376
- if (!hydrated()) return value;
516
+ if (!hydrated()) return prev;
377
517
  active = true;
378
518
  return compute(prev);
379
519
  }, (next, prev) => {
380
520
  if (!active) return;
381
521
  return effectFn(next, prev);
382
- }, value, options);
522
+ }, options);
383
523
  setHydrated(true);
384
524
  return;
385
525
  }
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
526
  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);
527
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
403
528
  }
404
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
405
- return hydratedEffect(createRenderEffect$1, compute, effectFn, value, options);
529
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
530
+ return hydratedEffect(createRenderEffect$1, compute, effectFn, options);
406
531
  }
407
- function hydratedCreateEffect(compute, effectFn, value, options) {
408
- return hydratedEffect(createEffect$1, compute, effectFn, value, options);
532
+ function hydratedCreateEffect(compute, effectFn, options) {
533
+ return hydratedEffect(createEffect$1, compute, effectFn, options);
409
534
  }
410
535
  function enableHydration() {
411
536
  _createMemo = hydratedCreateMemo;
@@ -464,24 +589,6 @@ const createStore = (...args) => (_createStore || createStore$1)(...args);
464
589
  const createOptimisticStore = (...args) => (_createOptimisticStore || createOptimisticStore$1)(...args);
465
590
  const createRenderEffect = (...args) => (_createRenderEffect || createRenderEffect$1)(...args);
466
591
  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
592
  function createBoundaryTrigger() {
486
593
  setSnapshotCapture(false);
487
594
  const [s, set] = createSignal$1(undefined, {
@@ -497,7 +604,7 @@ function resumeBoundaryHydration(o, id, set) {
497
604
  checkHydrationComplete();
498
605
  return;
499
606
  }
500
- sharedConfig.gather(id);
607
+ sharedConfig.gather?.(id);
501
608
  _hydratingValue = true;
502
609
  markSnapshotScope(o);
503
610
  _snapshotRootOwner = o;
@@ -509,38 +616,65 @@ function resumeBoundaryHydration(o, id, set) {
509
616
  flush();
510
617
  checkHydrationComplete();
511
618
  }
512
- function Loading(props) {
513
- if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
619
+ function initBoundaryResume(o, id) {
620
+ _pendingBoundaries++;
621
+ onCleanup(() => {
622
+ if (!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 createLoadingBoundary$1(fn, fallback, options);
653
+ let settledSerializationResumeQueued = false;
514
654
  return createMemo$1(() => {
515
655
  const o = getOwner();
516
656
  const id = o.id;
517
657
  let assetPromise;
518
658
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
519
659
  const mapping = sharedConfig.load(id + "_assets");
520
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
660
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
521
661
  }
522
662
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
523
- let ref = sharedConfig.load(id);
663
+ const ref = sharedConfig.load(id);
524
664
  let p;
525
665
  if (ref) {
526
- 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();
527
673
  }
528
674
  if (p) {
529
- _pendingBoundaries++;
530
- onCleanup(() => {
531
- if (!isDisposed(o)) return;
532
- sharedConfig.cleanupFragment?.(id);
533
- });
534
- const set = createBoundaryTrigger();
675
+ const [set, resume] = initBoundaryResume(o, id);
535
676
  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
- });
677
+ waitAndResume(p, resume, assetPromise);
544
678
  } else {
545
679
  const afterAssets = () => {
546
680
  _pendingBoundaries--;
@@ -549,16 +683,26 @@ function Loading(props) {
549
683
  };
550
684
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
551
685
  }
552
- 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();
553
696
  }
697
+ waitAndResume(fr, resume, assetPromise);
698
+ return fallback();
554
699
  }
555
- if (assetPromise) {
556
- _pendingBoundaries++;
557
- const set = createBoundaryTrigger();
558
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
700
+ if (assetPromise && !sharedConfig.has(id)) {
701
+ const [, resume] = initBoundaryResume(o, id);
702
+ assetPromise.then(resume);
559
703
  return undefined;
560
704
  }
561
- return createLoadBoundary(() => props.children, () => props.fallback);
705
+ return createLoadingBoundary$1(fn, fallback, options);
562
706
  });
563
707
  }
564
708
  function NoHydration(props) {
@@ -597,7 +741,9 @@ function lazy(fn, moduleUrl) {
597
741
  let Comp;
598
742
  return createMemo$1(() => (Comp = comp()) ? untrack(() => {
599
743
  return Comp(props);
600
- }) : "");
744
+ }) : "", {
745
+ sync: true
746
+ });
601
747
  };
602
748
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
603
749
  wrap.moduleUrl = moduleUrl;
@@ -627,27 +773,25 @@ function Repeat(props) {
627
773
  }
628
774
  function Show(props) {
629
775
  const keyed = props.keyed;
630
- const conditionValue = createMemo$1(() => props.when, undefined, undefined);
631
- const condition = keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
632
- equals: (a, b) => !a === !b
776
+ const conditionValue = createMemo$1(() => props.when, undefined);
777
+ const condition = keyed ? conditionValue : createMemo$1(conditionValue, {
778
+ equals: (a, b) => !a === !b,
779
+ sync: true
633
780
  });
634
781
  return createMemo$1(() => {
635
782
  const c = condition();
636
783
  if (c) {
637
784
  const child = props.children;
638
785
  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;
786
+ return fn ? untrack(() => child(() => {
787
+ if (!untrack(condition)) throw narrowedError("Show");
788
+ return conditionValue();
789
+ }), IS_DEV) : child;
648
790
  }
649
791
  return props.fallback;
650
- }, undefined, undefined);
792
+ }, {
793
+ sync: true
794
+ });
651
795
  }
652
796
  function Switch(props) {
653
797
  const chs = children(() => props.children);
@@ -658,13 +802,16 @@ function Switch(props) {
658
802
  const index = i;
659
803
  const mp = mps[i];
660
804
  const prevFunc = func;
661
- const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined, undefined);
662
- const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
663
- equals: (a, b) => !a === !b
805
+ const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined);
806
+ const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, {
807
+ equals: (a, b) => !a === !b,
808
+ sync: true
664
809
  });
665
810
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
666
811
  }
667
812
  return func;
813
+ }, {
814
+ sync: true
668
815
  });
669
816
  return createMemo$1(() => {
670
817
  const sel = switchFunc()();
@@ -672,16 +819,13 @@ function Switch(props) {
672
819
  const [index, conditionValue, mp] = sel;
673
820
  const child = mp.children;
674
821
  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);
822
+ return fn ? untrack(() => child(() => {
823
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
824
+ return conditionValue();
825
+ }), IS_DEV) : child;
826
+ }, {
827
+ sync: true
828
+ });
685
829
  }
686
830
  function Match(props) {
687
831
  return props;
@@ -692,9 +836,20 @@ function Errored(props) {
692
836
  return typeof f === "function" && f.length ? f(err, reset) : f;
693
837
  });
694
838
  }
839
+ function Loading(props) {
840
+ const onOpt = "on" in props ? {
841
+ on: () => props.on
842
+ } : undefined;
843
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
844
+ }
845
+ function Reveal(props) {
846
+ return createRevealOrder(() => props.children, {
847
+ order: () => props.order ?? "sequential",
848
+ collapsed: () => !!props.collapsed
849
+ });
850
+ }
695
851
 
696
852
  function ssrHandleError() {}
697
- function ssrRunInScope() {}
698
853
  const DEV = undefined;
699
854
 
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 };
855
+ 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, useContext };