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