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/dev.cjs CHANGED
@@ -19,10 +19,10 @@ function useContext(context) {
19
19
  return signals.getContext(context);
20
20
  }
21
21
  function children(fn) {
22
- const c = signals.createMemo(fn, undefined, {
22
+ const c = signals.createMemo(fn, {
23
23
  lazy: true
24
24
  });
25
- const memo = signals.createMemo(() => signals.flatten(c()), undefined, {
25
+ const memo = signals.createMemo(() => signals.flatten(c()), {
26
26
  name: "children",
27
27
  lazy: true
28
28
  } );
@@ -35,30 +35,19 @@ function children(fn) {
35
35
  function devComponent(Comp, props) {
36
36
  return signals.createRoot(() => {
37
37
  const owner = signals.getOwner();
38
- owner._props = props;
39
- owner._name = Comp.name;
40
- owner._component = Comp;
41
- return signals.untrack(() => {
42
- Object.assign(Comp, {
43
- [$DEVCOMP]: true
44
- });
45
- signals.setStrictRead(`<${Comp.name || "Anonymous"}>`);
46
- try {
47
- return Comp(props);
48
- } finally {
49
- signals.setStrictRead(false);
50
- }
38
+ owner._component = {
39
+ fn: Comp,
40
+ props,
41
+ name: Comp.name
42
+ };
43
+ Object.assign(Comp, {
44
+ [$DEVCOMP]: true
51
45
  });
46
+ return signals.untrack(() => Comp(props), `<${Comp.name || "Anonymous"}>`);
52
47
  }, {
53
48
  transparent: true
54
49
  });
55
50
  }
56
- function registerGraph(value) {
57
- const owner = signals.getOwner();
58
- if (!owner) return;
59
- if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
60
- value.graph = owner;
61
- }
62
51
 
63
52
  const NoHydrateContext = {
64
53
  id: Symbol("NoHydrateContext"),
@@ -100,6 +89,7 @@ function drainHydrationCallbacks() {
100
89
  setTimeout(() => {
101
90
  if (sharedConfig.verifyHydration) sharedConfig.verifyHydration();
102
91
  if (globalThis._$HY) globalThis._$HY.done = true;
92
+ sharedConfig.registry?.clear();
103
93
  });
104
94
  }
105
95
  function checkHydrationComplete() {
@@ -117,23 +107,10 @@ let _createOptimisticStore;
117
107
  let _createRenderEffect;
118
108
  let _createEffect;
119
109
  class MockPromise {
120
- static all() {
121
- return new MockPromise();
122
- }
123
- static allSettled() {
124
- return new MockPromise();
125
- }
126
- static any() {
127
- return new MockPromise();
128
- }
129
- static race() {
130
- return new MockPromise();
131
- }
132
- static reject() {
133
- return new MockPromise();
134
- }
135
- static resolve() {
136
- return new MockPromise();
110
+ static {
111
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
112
+ MockPromise[k] = () => new MockPromise();
113
+ }
137
114
  }
138
115
  catch() {
139
116
  return new MockPromise();
@@ -161,11 +138,67 @@ function subFetch(fn, prev) {
161
138
  Promise = ogPromise;
162
139
  }
163
140
  }
164
- function consumeFirstSync(ai) {
165
- const iter = ai[Symbol.asyncIterator]();
166
- const r = iter.next();
167
- const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
168
- return [value, iter];
141
+ function syncThenable(value) {
142
+ return {
143
+ then(fn) {
144
+ fn(value);
145
+ }
146
+ };
147
+ }
148
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
149
+ function readHydratedValue(initP, refresh) {
150
+ if (initP == null) return NO_HYDRATED_VALUE;
151
+ refresh();
152
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
153
+ return initP?.v ?? initP;
154
+ }
155
+ function readSerializedOrCompute(compute, prev) {
156
+ if (!sharedConfig.hydrating) return compute(prev);
157
+ const o = signals.getOwner();
158
+ let initP;
159
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
160
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
161
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
162
+ }
163
+ function forwardIteratorReturn(it, value) {
164
+ const returned = it.return?.(value);
165
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
166
+ done: true,
167
+ value
168
+ });
169
+ }
170
+ function normalizeIterator(it) {
171
+ let first = true;
172
+ let buffered = null;
173
+ return {
174
+ next() {
175
+ if (first) {
176
+ first = false;
177
+ const r = it.next();
178
+ return r && typeof r.then === "function" ? r : syncThenable(r);
179
+ }
180
+ if (buffered) {
181
+ const b = buffered;
182
+ buffered = null;
183
+ return b;
184
+ }
185
+ let latest = it.next();
186
+ if (latest && typeof latest.then === "function") return latest;
187
+ while (!latest.done) {
188
+ const peek = it.next();
189
+ if (peek && typeof peek.then === "function") {
190
+ buffered = peek;
191
+ break;
192
+ }
193
+ latest = peek;
194
+ }
195
+ return Promise.resolve(latest);
196
+ },
197
+ return(value) {
198
+ buffered = null;
199
+ return forwardIteratorReturn(it, value);
200
+ }
201
+ };
169
202
  }
170
203
  function applyPatches(target, patches) {
171
204
  for (const patch of patches) {
@@ -182,118 +215,211 @@ function applyPatches(target, patches) {
182
215
  }
183
216
  }
184
217
  }
185
- function scheduleIteratorConsumption(iter, apply) {
186
- const consume = () => {
187
- while (true) {
188
- const n = iter.next();
189
- if (n instanceof Promise) {
190
- n.then(r => {
191
- if (r.done) return;
192
- apply(r.value);
193
- consume();
194
- });
195
- return;
218
+ function isAsyncIterable(v) {
219
+ return v != null && typeof v[Symbol.asyncIterator] === "function";
220
+ }
221
+ function createShadowDraft(realDraft) {
222
+ const shadow = JSON.parse(JSON.stringify(realDraft));
223
+ let useShadow = true;
224
+ return {
225
+ proxy: new Proxy(shadow, {
226
+ get(_, prop) {
227
+ return useShadow ? shadow[prop] : realDraft[prop];
228
+ },
229
+ set(_, prop, value) {
230
+ if (useShadow) {
231
+ shadow[prop] = value;
232
+ return true;
233
+ }
234
+ return Reflect.set(realDraft, prop, value);
235
+ },
236
+ deleteProperty(_, prop) {
237
+ if (useShadow) {
238
+ delete shadow[prop];
239
+ return true;
240
+ }
241
+ return Reflect.deleteProperty(realDraft, prop);
242
+ },
243
+ has(_, prop) {
244
+ return prop in (useShadow ? shadow : realDraft);
245
+ },
246
+ ownKeys() {
247
+ return Reflect.ownKeys(useShadow ? shadow : realDraft);
248
+ },
249
+ getOwnPropertyDescriptor(_, prop) {
250
+ return Object.getOwnPropertyDescriptor(useShadow ? shadow : realDraft, prop);
196
251
  }
197
- if (n.done) break;
198
- apply(n.value);
252
+ }),
253
+ activate() {
254
+ useShadow = false;
199
255
  }
200
256
  };
201
- consume();
202
257
  }
203
- function isAsyncIterable(v) {
204
- return v != null && typeof v[Symbol.asyncIterator] === "function";
258
+ function wrapFirstYield(iterable, activate) {
259
+ const srcIt = iterable[Symbol.asyncIterator]();
260
+ let first = true;
261
+ return {
262
+ [Symbol.asyncIterator]() {
263
+ return {
264
+ next() {
265
+ const p = srcIt.next();
266
+ if (first) {
267
+ first = false;
268
+ return p.then(r => {
269
+ activate();
270
+ return r.done ? r : {
271
+ done: false,
272
+ value: undefined
273
+ };
274
+ });
275
+ }
276
+ return p;
277
+ },
278
+ return(value) {
279
+ return forwardIteratorReturn(srcIt, value);
280
+ }
281
+ };
282
+ }
283
+ };
205
284
  }
206
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
285
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
207
286
  const parent = signals.getOwner();
208
287
  const expectedId = signals.peekNextChildId(parent);
209
288
  if (!sharedConfig.has(expectedId)) return null;
210
- const initP = sharedConfig.load(expectedId);
211
- if (!isAsyncIterable(initP)) return null;
212
- const [firstValue, iter] = consumeFirstSync(initP);
213
- const [get, set] = signals.createSignal(firstValue);
214
- const result = coreFn(() => get(), firstValue, options);
215
- scheduleIteratorConsumption(iter, v => {
216
- set(() => v);
217
- signals.flush();
218
- });
219
- return result;
289
+ const loaded = sharedConfig.load(expectedId);
290
+ if (!isAsyncIterable(loaded)) return null;
291
+ const it = normalizeIterator(loaded[Symbol.asyncIterator]());
292
+ const iterable = {
293
+ [Symbol.asyncIterator]() {
294
+ return it;
295
+ }
296
+ };
297
+ return coreFn(prev => {
298
+ subFetch(compute, prev);
299
+ return iterable;
300
+ }, options);
220
301
  }
221
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
302
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
222
303
  const parent = signals.getOwner();
223
304
  const expectedId = signals.peekNextChildId(parent);
224
305
  if (!sharedConfig.has(expectedId)) return null;
225
- const initP = sharedConfig.load(expectedId);
226
- if (!isAsyncIterable(initP)) return null;
227
- const [firstState, iter] = consumeFirstSync(initP);
228
- const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
229
- scheduleIteratorConsumption(iter, patches => {
230
- setStore(d => {
231
- applyPatches(d, patches);
232
- });
233
- });
234
- return [store, setStore];
306
+ const loaded = sharedConfig.load(expectedId);
307
+ if (!isAsyncIterable(loaded)) return null;
308
+ const srcIt = loaded[Symbol.asyncIterator]();
309
+ let isFirst = true;
310
+ let buffered = null;
311
+ return coreFn(draft => {
312
+ const {
313
+ proxy
314
+ } = createShadowDraft(draft);
315
+ subFetch(fn, proxy);
316
+ const process = res => {
317
+ if (res.done) return {
318
+ done: true,
319
+ value: undefined
320
+ };
321
+ if (isFirst) {
322
+ isFirst = false;
323
+ signals.setSnapshotCapture(false);
324
+ try {
325
+ if (Array.isArray(res.value)) {
326
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
327
+ draft.length = res.value.length;
328
+ } else {
329
+ Object.assign(draft, res.value);
330
+ }
331
+ } finally {
332
+ signals.setSnapshotCapture(true);
333
+ }
334
+ } else {
335
+ applyPatches(draft, res.value);
336
+ }
337
+ return {
338
+ done: false,
339
+ value: undefined
340
+ };
341
+ };
342
+ return {
343
+ [Symbol.asyncIterator]() {
344
+ return {
345
+ next() {
346
+ if (isFirst) {
347
+ const r = srcIt.next();
348
+ return r && typeof r.then === "function" ? {
349
+ then(fn, rej) {
350
+ r.then(v => fn(process(v)), rej);
351
+ }
352
+ } : syncThenable(process(r));
353
+ }
354
+ if (buffered) {
355
+ const b = buffered;
356
+ buffered = null;
357
+ return b.then(process);
358
+ }
359
+ let r = srcIt.next();
360
+ if (r && typeof r.then === "function") {
361
+ return r.then(process);
362
+ }
363
+ let result = process(r);
364
+ while (!r.done) {
365
+ const peek = srcIt.next();
366
+ if (peek && typeof peek.then === "function") {
367
+ buffered = peek;
368
+ break;
369
+ }
370
+ r = peek;
371
+ if (!r.done) result = process(r);
372
+ }
373
+ return Promise.resolve(result);
374
+ },
375
+ return(value) {
376
+ buffered = null;
377
+ return forwardIteratorReturn(srcIt, value);
378
+ }
379
+ };
380
+ }
381
+ };
382
+ }, initialValue, options);
235
383
  }
236
- function hydratedCreateMemo(compute, value, options) {
237
- if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
384
+ function hydratedCreateMemo(compute, options) {
385
+ if (!sharedConfig.hydrating || options?.transparent) {
386
+ return signals.createMemo(compute, options);
387
+ }
238
388
  markTopLevelSnapshotScope();
239
389
  const ssrSource = options?.ssrSource;
240
390
  if (ssrSource === "client") {
241
- const [hydrated, setHydrated] = signals.createSignal(false);
391
+ const [hydrated, setHydrated] = signals.createSignal(false, {
392
+ ownedWrite: true
393
+ });
242
394
  const memo = signals.createMemo(prev => {
243
- if (!hydrated()) return prev ?? value;
395
+ if (!hydrated()) return prev;
244
396
  return compute(prev);
245
- }, value, options);
397
+ }, options);
246
398
  setHydrated(true);
247
399
  return memo;
248
400
  }
249
- if (ssrSource === "initial") {
250
- return signals.createMemo(prev => {
251
- if (!sharedConfig.hydrating) return compute(prev);
252
- subFetch(compute, prev);
253
- return prev ?? value;
254
- }, value, options);
255
- }
256
- const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
401
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, options);
257
402
  if (aiResult !== null) return aiResult;
258
- return signals.createMemo(prev => {
259
- const o = signals.getOwner();
260
- if (!sharedConfig.hydrating) return compute(prev);
261
- let initP;
262
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
263
- const init = initP?.v ?? initP;
264
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
265
- }, value, options);
266
- }
267
- function hydratedCreateSignal(fn, second, third) {
268
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
403
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), options);
404
+ }
405
+ function hydratedCreateSignal(fn, second) {
406
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second);
269
407
  markTopLevelSnapshotScope();
270
- const ssrSource = third?.ssrSource;
408
+ const ssrSource = second?.ssrSource;
271
409
  if (ssrSource === "client") {
272
- const [hydrated, setHydrated] = signals.createSignal(false);
410
+ const [hydrated, setHydrated] = signals.createSignal(false, {
411
+ ownedWrite: true
412
+ });
273
413
  const sig = signals.createSignal(prev => {
274
- if (!hydrated()) return prev ?? second;
414
+ if (!hydrated()) return prev;
275
415
  return fn(prev);
276
- }, second, third);
416
+ }, second);
277
417
  setHydrated(true);
278
418
  return sig;
279
419
  }
280
- if (ssrSource === "initial") {
281
- return signals.createSignal(prev => {
282
- if (!sharedConfig.hydrating) return fn(prev);
283
- subFetch(fn, prev);
284
- return prev ?? second;
285
- }, second, third);
286
- }
287
- const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
420
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second);
288
421
  if (aiResult !== null) return aiResult;
289
- return signals.createSignal(prev => {
290
- if (!sharedConfig.hydrating) return fn(prev);
291
- const o = signals.getOwner();
292
- let initP;
293
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
294
- const init = initP?.v ?? initP;
295
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
296
- }, second, third);
422
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second);
297
423
  }
298
424
  function hydratedCreateErrorBoundary(fn, fallback) {
299
425
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -315,127 +441,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
315
441
  }
316
442
  return signals.createErrorBoundary(fn, fallback);
317
443
  }
318
- function hydratedCreateOptimistic(fn, second, third) {
319
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
444
+ function hydratedCreateOptimistic(fn, second) {
445
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second);
320
446
  markTopLevelSnapshotScope();
321
- const ssrSource = third?.ssrSource;
447
+ const ssrSource = second?.ssrSource;
322
448
  if (ssrSource === "client") {
323
- const [hydrated, setHydrated] = signals.createSignal(false);
449
+ const [hydrated, setHydrated] = signals.createSignal(false, {
450
+ ownedWrite: true
451
+ });
324
452
  const sig = signals.createOptimistic(prev => {
325
- if (!hydrated()) return prev ?? second;
453
+ if (!hydrated()) return prev;
326
454
  return fn(prev);
327
- }, second, third);
455
+ }, second);
328
456
  setHydrated(true);
329
457
  return sig;
330
458
  }
331
- if (ssrSource === "initial") {
332
- return signals.createOptimistic(prev => {
333
- if (!sharedConfig.hydrating) return fn(prev);
334
- subFetch(fn, prev);
335
- return prev ?? second;
336
- }, second, third);
337
- }
338
- const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
459
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second);
339
460
  if (aiResult !== null) return aiResult;
340
- return signals.createOptimistic(prev => {
341
- const o = signals.getOwner();
342
- if (!sharedConfig.hydrating) return fn(prev);
343
- let initP;
344
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
345
- const init = initP?.v ?? initP;
346
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
347
- }, second, third);
348
- }
349
- function wrapStoreFn(fn, ssrSource) {
350
- if (ssrSource === "initial") {
351
- return draft => {
352
- if (!sharedConfig.hydrating) return fn(draft);
353
- subFetch(fn, draft);
354
- return undefined;
355
- };
461
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second);
462
+ }
463
+ function wrapStoreFn(fn) {
464
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
465
+ }
466
+ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
467
+ if (ssrSource === "client") {
468
+ const [hydrated, setHydrated] = signals.createSignal(false, {
469
+ ownedWrite: true
470
+ });
471
+ const result = coreFn(draft => {
472
+ if (!hydrated()) return;
473
+ return fn(draft);
474
+ }, initialValue, options);
475
+ setHydrated(true);
476
+ return result;
356
477
  }
357
- return draft => {
358
- const o = signals.getOwner();
359
- if (!sharedConfig.hydrating) return fn(draft);
360
- let initP;
361
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
362
- const init = initP?.v ?? initP;
363
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
364
- };
478
+ if (ssrSource === "hybrid") {
479
+ const [hydrated, setHydrated] = signals.createSignal(false, {
480
+ ownedWrite: true
481
+ });
482
+ const result = coreFn(draft => {
483
+ const o = signals.getOwner();
484
+ if (!hydrated()) {
485
+ if (sharedConfig.has(o.id)) {
486
+ const initP = sharedConfig.load(o.id);
487
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
488
+ if (init !== NO_HYDRATED_VALUE) return init;
489
+ }
490
+ return fn(draft);
491
+ }
492
+ const {
493
+ proxy,
494
+ activate
495
+ } = createShadowDraft(draft);
496
+ const r = fn(proxy);
497
+ return isAsyncIterable(r) ? wrapFirstYield(r, activate) : r;
498
+ }, initialValue, options);
499
+ setHydrated(true);
500
+ return result;
501
+ }
502
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options);
503
+ if (aiResult !== null) return aiResult;
504
+ return coreFn(wrapStoreFn(fn), initialValue, options);
365
505
  }
366
506
  function hydratedCreateStore(first, second, third) {
367
507
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
368
508
  markTopLevelSnapshotScope();
369
509
  const ssrSource = third?.ssrSource;
370
- if (ssrSource === "client" || ssrSource === "initial") {
371
- return signals.createStore(second ?? {}, undefined, third);
372
- }
373
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
374
- if (aiResult !== null) return aiResult;
375
- return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
510
+ return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
376
511
  }
377
512
  function hydratedCreateOptimisticStore(first, second, third) {
378
513
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
379
514
  markTopLevelSnapshotScope();
380
515
  const ssrSource = third?.ssrSource;
381
- if (ssrSource === "client" || ssrSource === "initial") {
382
- return signals.createOptimisticStore(second ?? {}, undefined, third);
383
- }
384
- const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
385
- if (aiResult !== null) return aiResult;
386
- return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
516
+ return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
387
517
  }
388
518
  function hydratedCreateProjection(fn, initialValue, options) {
389
519
  if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
390
520
  markTopLevelSnapshotScope();
391
521
  const ssrSource = options?.ssrSource;
392
- if (ssrSource === "client" || ssrSource === "initial") {
393
- return signals.createProjection(draft => draft, initialValue, options);
394
- }
395
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
396
- if (aiResult !== null) return aiResult[0];
397
- return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
522
+ return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
398
523
  }
399
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
400
- if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
524
+ function hydratedEffect(coreFn, compute, effectFn, options) {
525
+ if (!sharedConfig.hydrating || options?.transparent) return coreFn(compute, effectFn, options);
401
526
  const ssrSource = options?.ssrSource;
402
527
  if (ssrSource === "client") {
403
- const [hydrated, setHydrated] = signals.createSignal(false);
528
+ const [hydrated, setHydrated] = signals.createSignal(false, {
529
+ ownedWrite: true
530
+ });
404
531
  let active = false;
405
532
  coreFn(prev => {
406
- if (!hydrated()) return value;
533
+ if (!hydrated()) return prev;
407
534
  active = true;
408
535
  return compute(prev);
409
536
  }, (next, prev) => {
410
537
  if (!active) return;
411
538
  return effectFn(next, prev);
412
- }, value, options);
539
+ }, options);
413
540
  setHydrated(true);
414
541
  return;
415
542
  }
416
- if (ssrSource === "initial") {
417
- coreFn(prev => {
418
- if (!sharedConfig.hydrating) return compute(prev);
419
- subFetch(compute, prev);
420
- return prev ?? value;
421
- }, effectFn, value, options);
422
- return;
423
- }
424
543
  markTopLevelSnapshotScope();
425
- coreFn(prev => {
426
- const o = signals.getOwner();
427
- if (!sharedConfig.hydrating) return compute(prev);
428
- let initP;
429
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
430
- const init = initP?.v ?? initP;
431
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
432
- }, effectFn, value, options);
544
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
433
545
  }
434
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
435
- return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
546
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
547
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, options);
436
548
  }
437
- function hydratedCreateEffect(compute, effectFn, value, options) {
438
- return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
549
+ function hydratedCreateEffect(compute, effectFn, options) {
550
+ return hydratedEffect(signals.createEffect, compute, effectFn, options);
439
551
  }
440
552
  function enableHydration() {
441
553
  _createMemo = hydratedCreateMemo;
@@ -494,24 +606,6 @@ const createStore = (...args) => (_createStore || signals.createStore)(...args);
494
606
  const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
495
607
  const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
496
608
  const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
497
- function loadModuleAssets(mapping) {
498
- const hy = globalThis._$HY;
499
- if (!hy) return;
500
- if (!hy.modules) hy.modules = {};
501
- if (!hy.loading) hy.loading = {};
502
- const pending = [];
503
- for (const moduleUrl in mapping) {
504
- if (hy.modules[moduleUrl]) continue;
505
- const entryUrl = mapping[moduleUrl];
506
- if (!hy.loading[moduleUrl]) {
507
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
508
- hy.modules[moduleUrl] = mod;
509
- });
510
- }
511
- pending.push(hy.loading[moduleUrl]);
512
- }
513
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
514
- }
515
609
  function createBoundaryTrigger() {
516
610
  signals.setSnapshotCapture(false);
517
611
  const [s, set] = signals.createSignal(undefined, {
@@ -527,7 +621,7 @@ function resumeBoundaryHydration(o, id, set) {
527
621
  checkHydrationComplete();
528
622
  return;
529
623
  }
530
- sharedConfig.gather(id);
624
+ sharedConfig.gather?.(id);
531
625
  _hydratingValue = true;
532
626
  signals.markSnapshotScope(o);
533
627
  _snapshotRootOwner = o;
@@ -539,38 +633,65 @@ function resumeBoundaryHydration(o, id, set) {
539
633
  signals.flush();
540
634
  checkHydrationComplete();
541
635
  }
542
- function Loading(props) {
543
- if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
636
+ function initBoundaryResume(o, id) {
637
+ _pendingBoundaries++;
638
+ signals.onCleanup(() => {
639
+ if (!signals.isDisposed(o)) return;
640
+ sharedConfig.cleanupFragment?.(id);
641
+ });
642
+ const set = createBoundaryTrigger();
643
+ return [set, () => resumeBoundaryHydration(o, id, set)];
644
+ }
645
+ function waitAndResume(p, resume, assetPromise) {
646
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
647
+ waitFor.then(() => {
648
+ if (p && typeof p === "object") p.s = 1;
649
+ resume();
650
+ }, err => {
651
+ if (p && typeof p === "object") {
652
+ p.s = 2;
653
+ p.v = err;
654
+ }
655
+ resume();
656
+ });
657
+ }
658
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
659
+ sharedConfig.gather?.(id);
660
+ const doResume = () => queueMicrotask(resume);
661
+ if (assetPromise) {
662
+ assetPromise.then(doResume);
663
+ return true;
664
+ }
665
+ doResume();
666
+ return false;
667
+ }
668
+ function createLoadingBoundary(fn, fallback, options) {
669
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
670
+ let settledSerializationResumeQueued = false;
544
671
  return signals.createMemo(() => {
545
672
  const o = signals.getOwner();
546
673
  const id = o.id;
547
674
  let assetPromise;
548
675
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
549
676
  const mapping = sharedConfig.load(id + "_assets");
550
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
677
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
551
678
  }
552
679
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
553
- let ref = sharedConfig.load(id);
680
+ const ref = sharedConfig.load(id);
554
681
  let p;
555
682
  if (ref) {
556
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
683
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
684
+ }
685
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
686
+ settledSerializationResumeQueued = true;
687
+ const [, resume] = initBoundaryResume(o, id);
688
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
689
+ return fallback();
557
690
  }
558
691
  if (p) {
559
- _pendingBoundaries++;
560
- signals.onCleanup(() => {
561
- if (!signals.isDisposed(o)) return;
562
- sharedConfig.cleanupFragment?.(id);
563
- });
564
- const set = createBoundaryTrigger();
692
+ const [set, resume] = initBoundaryResume(o, id);
565
693
  if (p !== "$$f") {
566
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
567
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
568
- _pendingBoundaries--;
569
- checkHydrationComplete();
570
- signals.runWithOwner(o, () => {
571
- throw err;
572
- });
573
- });
694
+ waitAndResume(p, resume, assetPromise);
574
695
  } else {
575
696
  const afterAssets = () => {
576
697
  _pendingBoundaries--;
@@ -579,16 +700,26 @@ function Loading(props) {
579
700
  };
580
701
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
581
702
  }
582
- return props.fallback;
703
+ return fallback();
704
+ }
705
+ }
706
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
707
+ settledSerializationResumeQueued = true;
708
+ const fr = sharedConfig.load(id + "_fr");
709
+ const [, resume] = initBoundaryResume(o, id);
710
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
711
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
712
+ return fallback();
583
713
  }
714
+ waitAndResume(fr, resume, assetPromise);
715
+ return fallback();
584
716
  }
585
- if (assetPromise) {
586
- _pendingBoundaries++;
587
- const set = createBoundaryTrigger();
588
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
717
+ if (assetPromise && !sharedConfig.has(id)) {
718
+ const [, resume] = initBoundaryResume(o, id);
719
+ assetPromise.then(resume);
589
720
  return undefined;
590
721
  }
591
- return signals.createLoadBoundary(() => props.children, () => props.fallback);
722
+ return signals.createLoadingBoundary(fn, fallback, options);
592
723
  });
593
724
  }
594
725
  function NoHydration(props) {
@@ -662,10 +793,10 @@ function Repeat(props) {
662
793
  }
663
794
  function Show(props) {
664
795
  const keyed = props.keyed;
665
- const conditionValue = signals.createMemo(() => props.when, undefined, {
796
+ const conditionValue = signals.createMemo(() => props.when, {
666
797
  name: "condition value"
667
798
  } );
668
- const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
799
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, {
669
800
  equals: (a, b) => !a === !b,
670
801
  name: "condition"
671
802
  } );
@@ -674,20 +805,13 @@ function Show(props) {
674
805
  if (c) {
675
806
  const child = props.children;
676
807
  const fn = typeof child === "function" && child.length > 0;
677
- return fn ? signals.untrack(() => {
678
- signals.setStrictRead("<Show>");
679
- try {
680
- return child(() => {
681
- if (!signals.untrack(condition)) throw narrowedError("Show");
682
- return conditionValue();
683
- });
684
- } finally {
685
- signals.setStrictRead(false);
686
- }
687
- }) : child;
808
+ return fn ? signals.untrack(() => child(() => {
809
+ if (!signals.untrack(condition)) throw narrowedError("Show");
810
+ return conditionValue();
811
+ }), "<Show>") : child;
688
812
  }
689
813
  return props.fallback;
690
- }, undefined, {
814
+ }, {
691
815
  name: "value"
692
816
  } );
693
817
  }
@@ -700,10 +824,10 @@ function Switch(props) {
700
824
  const index = i;
701
825
  const mp = mps[i];
702
826
  const prevFunc = func;
703
- const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
827
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, {
704
828
  name: "condition value"
705
829
  } );
706
- const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
830
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, {
707
831
  equals: (a, b) => !a === !b,
708
832
  name: "condition"
709
833
  } );
@@ -717,18 +841,11 @@ function Switch(props) {
717
841
  const [index, conditionValue, mp] = sel;
718
842
  const child = mp.children;
719
843
  const fn = typeof child === "function" && child.length > 0;
720
- return fn ? signals.untrack(() => {
721
- signals.setStrictRead("<Match>");
722
- try {
723
- return child(() => {
724
- if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
725
- return conditionValue();
726
- });
727
- } finally {
728
- signals.setStrictRead(false);
729
- }
730
- }) : child;
731
- }, undefined, {
844
+ return fn ? signals.untrack(() => child(() => {
845
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
846
+ return conditionValue();
847
+ }), "<Match>") : child;
848
+ }, {
732
849
  name: "eval conditions"
733
850
  } );
734
851
  }
@@ -742,14 +859,22 @@ function Errored(props) {
742
859
  return typeof f === "function" && f.length ? f(err, reset) : f;
743
860
  });
744
861
  }
862
+ function Loading(props) {
863
+ const onOpt = "on" in props ? {
864
+ on: () => props.on
865
+ } : undefined;
866
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
867
+ }
868
+ function Reveal(props) {
869
+ return signals.createRevealOrder(() => props.children, {
870
+ order: () => props.order ?? "sequential",
871
+ collapsed: () => !!props.collapsed
872
+ });
873
+ }
745
874
 
746
875
  function ssrHandleError() {}
747
876
  function ssrRunInScope() {}
748
- const DevHooks = {};
749
- const DEV = {
750
- hooks: DevHooks,
751
- registerGraph
752
- } ;
877
+ const DEV = signals.DEV ;
753
878
  if (globalThis) {
754
879
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
755
880
  }
@@ -758,6 +883,10 @@ Object.defineProperty(exports, "$PROXY", {
758
883
  enumerable: true,
759
884
  get: function () { return signals.$PROXY; }
760
885
  });
886
+ Object.defineProperty(exports, "$REFRESH", {
887
+ enumerable: true,
888
+ get: function () { return signals.$REFRESH; }
889
+ });
761
890
  Object.defineProperty(exports, "$TRACK", {
762
891
  enumerable: true,
763
892
  get: function () { return signals.$TRACK; }
@@ -778,6 +907,10 @@ Object.defineProperty(exports, "createReaction", {
778
907
  enumerable: true,
779
908
  get: function () { return signals.createReaction; }
780
909
  });
910
+ Object.defineProperty(exports, "createRevealOrder", {
911
+ enumerable: true,
912
+ get: function () { return signals.createRevealOrder; }
913
+ });
781
914
  Object.defineProperty(exports, "createRoot", {
782
915
  enumerable: true,
783
916
  get: function () { return signals.createRoot; }
@@ -790,6 +923,14 @@ Object.defineProperty(exports, "deep", {
790
923
  enumerable: true,
791
924
  get: function () { return signals.deep; }
792
925
  });
926
+ Object.defineProperty(exports, "enableExternalSource", {
927
+ enumerable: true,
928
+ get: function () { return signals.enableExternalSource; }
929
+ });
930
+ Object.defineProperty(exports, "enforceLoadingBoundary", {
931
+ enumerable: true,
932
+ get: function () { return signals.enforceLoadingBoundary; }
933
+ });
793
934
  Object.defineProperty(exports, "flatten", {
794
935
  enumerable: true,
795
936
  get: function () { return signals.flatten; }
@@ -810,6 +951,10 @@ Object.defineProperty(exports, "getOwner", {
810
951
  enumerable: true,
811
952
  get: function () { return signals.getOwner; }
812
953
  });
954
+ Object.defineProperty(exports, "isDisposed", {
955
+ enumerable: true,
956
+ get: function () { return signals.isDisposed; }
957
+ });
813
958
  Object.defineProperty(exports, "isEqual", {
814
959
  enumerable: true,
815
960
  get: function () { return signals.isEqual; }
@@ -892,12 +1037,15 @@ exports.Match = Match;
892
1037
  exports.NoHydrateContext = NoHydrateContext;
893
1038
  exports.NoHydration = NoHydration;
894
1039
  exports.Repeat = Repeat;
1040
+ exports.Reveal = Reveal;
895
1041
  exports.Show = Show;
896
1042
  exports.Switch = Switch;
897
1043
  exports.children = children;
898
1044
  exports.createComponent = createComponent;
899
1045
  exports.createContext = createContext;
900
1046
  exports.createEffect = createEffect;
1047
+ exports.createErrorBoundary = createErrorBoundary;
1048
+ exports.createLoadingBoundary = createLoadingBoundary;
901
1049
  exports.createMemo = createMemo;
902
1050
  exports.createOptimistic = createOptimistic;
903
1051
  exports.createOptimisticStore = createOptimisticStore;