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/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getContext, createMemo as createMemo$1, flatten, getOwner, createRoot, setContext, untrack, setStrictRead, createLoadBoundary, 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, 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, getOwner, untrack, createOwner, runWithOwner, createEffect as createEffect$1, createErrorBoundary as createErrorBoundary$1, createLoadingBoundary as createLoadingBoundary$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, onCleanup, isDisposed, peekNextChildId, clearSnapshots, flush, markSnapshotScope, mapArray, repeat, createRevealOrder, DEV as DEV$1 } 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
4
  const $DEVCOMP = Symbol("COMPONENT_DEV" );
5
5
  function createContext(defaultValue, options) {
@@ -18,12 +18,13 @@ function useContext(context) {
18
18
  return getContext(context);
19
19
  }
20
20
  function children(fn) {
21
- const c = createMemo$1(fn, undefined, {
21
+ const c = createMemo$1(fn, {
22
22
  lazy: true
23
23
  });
24
- const memo = createMemo$1(() => flatten(c()), undefined, {
24
+ const memo = createMemo$1(() => flatten(c()), {
25
25
  name: "children",
26
- lazy: true
26
+ lazy: true,
27
+ sync: true
27
28
  } );
28
29
  memo.toArray = () => {
29
30
  const v = memo();
@@ -34,30 +35,19 @@ function children(fn) {
34
35
  function devComponent(Comp, props) {
35
36
  return createRoot(() => {
36
37
  const owner = getOwner();
37
- owner._props = props;
38
- owner._name = Comp.name;
39
- owner._component = Comp;
40
- return untrack(() => {
41
- Object.assign(Comp, {
42
- [$DEVCOMP]: true
43
- });
44
- setStrictRead(`<${Comp.name || "Anonymous"}>`);
45
- try {
46
- return Comp(props);
47
- } finally {
48
- setStrictRead(false);
49
- }
38
+ owner._component = {
39
+ fn: Comp,
40
+ props,
41
+ name: Comp.name
42
+ };
43
+ Object.assign(Comp, {
44
+ [$DEVCOMP]: true
50
45
  });
46
+ return untrack(() => Comp(props), `<${Comp.name || "Anonymous"}>`);
51
47
  }, {
52
48
  transparent: true
53
49
  });
54
50
  }
55
- function registerGraph(value) {
56
- const owner = getOwner();
57
- if (!owner) return;
58
- if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
59
- value.graph = owner;
60
- }
61
51
 
62
52
  const NoHydrateContext = {
63
53
  id: Symbol("NoHydrateContext"),
@@ -99,6 +89,7 @@ function drainHydrationCallbacks() {
99
89
  setTimeout(() => {
100
90
  if (sharedConfig.verifyHydration) sharedConfig.verifyHydration();
101
91
  if (globalThis._$HY) globalThis._$HY.done = true;
92
+ sharedConfig.registry?.clear();
102
93
  });
103
94
  }
104
95
  function checkHydrationComplete() {
@@ -116,23 +107,10 @@ let _createOptimisticStore;
116
107
  let _createRenderEffect;
117
108
  let _createEffect;
118
109
  class MockPromise {
119
- static all() {
120
- return new MockPromise();
121
- }
122
- static allSettled() {
123
- return new MockPromise();
124
- }
125
- static any() {
126
- return new MockPromise();
127
- }
128
- static race() {
129
- return new MockPromise();
130
- }
131
- static reject() {
132
- return new MockPromise();
133
- }
134
- static resolve() {
135
- return new MockPromise();
110
+ static {
111
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
112
+ MockPromise[k] = () => new MockPromise();
113
+ }
136
114
  }
137
115
  catch() {
138
116
  return new MockPromise();
@@ -160,11 +138,67 @@ function subFetch(fn, prev) {
160
138
  Promise = ogPromise;
161
139
  }
162
140
  }
163
- function consumeFirstSync(ai) {
164
- const iter = ai[Symbol.asyncIterator]();
165
- const r = iter.next();
166
- const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
167
- 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 = 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
+ };
168
202
  }
169
203
  function applyPatches(target, patches) {
170
204
  for (const patch of patches) {
@@ -181,118 +215,211 @@ function applyPatches(target, patches) {
181
215
  }
182
216
  }
183
217
  }
184
- function scheduleIteratorConsumption(iter, apply) {
185
- const consume = () => {
186
- while (true) {
187
- const n = iter.next();
188
- if (n instanceof Promise) {
189
- n.then(r => {
190
- if (r.done) return;
191
- apply(r.value);
192
- consume();
193
- });
194
- 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);
195
251
  }
196
- if (n.done) break;
197
- apply(n.value);
252
+ }),
253
+ activate() {
254
+ useShadow = false;
198
255
  }
199
256
  };
200
- consume();
201
257
  }
202
- function isAsyncIterable(v) {
203
- 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
+ };
204
284
  }
205
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
285
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
206
286
  const parent = getOwner();
207
287
  const expectedId = peekNextChildId(parent);
208
288
  if (!sharedConfig.has(expectedId)) return null;
209
- const initP = sharedConfig.load(expectedId);
210
- if (!isAsyncIterable(initP)) return null;
211
- const [firstValue, iter] = consumeFirstSync(initP);
212
- const [get, set] = createSignal$1(firstValue);
213
- const result = coreFn(() => get(), firstValue, options);
214
- scheduleIteratorConsumption(iter, v => {
215
- set(() => v);
216
- flush();
217
- });
218
- 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);
219
301
  }
220
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
302
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
221
303
  const parent = getOwner();
222
304
  const expectedId = peekNextChildId(parent);
223
305
  if (!sharedConfig.has(expectedId)) return null;
224
- const initP = sharedConfig.load(expectedId);
225
- if (!isAsyncIterable(initP)) return null;
226
- const [firstState, iter] = consumeFirstSync(initP);
227
- const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
228
- scheduleIteratorConsumption(iter, patches => {
229
- setStore(d => {
230
- applyPatches(d, patches);
231
- });
232
- });
233
- 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
+ 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
+ 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);
234
383
  }
235
- function hydratedCreateMemo(compute, value, options) {
236
- if (!sharedConfig.hydrating) return createMemo$1(compute, value, options);
384
+ function hydratedCreateMemo(compute, options) {
385
+ if (!sharedConfig.hydrating || options?.transparent) {
386
+ return createMemo$1(compute, options);
387
+ }
237
388
  markTopLevelSnapshotScope();
238
389
  const ssrSource = options?.ssrSource;
239
390
  if (ssrSource === "client") {
240
- const [hydrated, setHydrated] = createSignal$1(false);
391
+ const [hydrated, setHydrated] = createSignal$1(false, {
392
+ ownedWrite: true
393
+ });
241
394
  const memo = createMemo$1(prev => {
242
- if (!hydrated()) return prev ?? value;
395
+ if (!hydrated()) return prev;
243
396
  return compute(prev);
244
- }, value, options);
397
+ }, options);
245
398
  setHydrated(true);
246
399
  return memo;
247
400
  }
248
- if (ssrSource === "initial") {
249
- return createMemo$1(prev => {
250
- if (!sharedConfig.hydrating) return compute(prev);
251
- subFetch(compute, prev);
252
- return prev ?? value;
253
- }, value, options);
254
- }
255
- const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, value, options);
401
+ const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, options);
256
402
  if (aiResult !== null) return aiResult;
257
- return createMemo$1(prev => {
258
- const o = getOwner();
259
- if (!sharedConfig.hydrating) return compute(prev);
260
- let initP;
261
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
262
- const init = initP?.v ?? initP;
263
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
264
- }, value, options);
265
- }
266
- function hydratedCreateSignal(fn, second, third) {
267
- if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second, third);
403
+ return createMemo$1(prev => readSerializedOrCompute(compute, prev), options);
404
+ }
405
+ function hydratedCreateSignal(fn, second) {
406
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second);
268
407
  markTopLevelSnapshotScope();
269
- const ssrSource = third?.ssrSource;
408
+ const ssrSource = second?.ssrSource;
270
409
  if (ssrSource === "client") {
271
- const [hydrated, setHydrated] = createSignal$1(false);
410
+ const [hydrated, setHydrated] = createSignal$1(false, {
411
+ ownedWrite: true
412
+ });
272
413
  const sig = createSignal$1(prev => {
273
- if (!hydrated()) return prev ?? second;
414
+ if (!hydrated()) return prev;
274
415
  return fn(prev);
275
- }, second, third);
416
+ }, second);
276
417
  setHydrated(true);
277
418
  return sig;
278
419
  }
279
- if (ssrSource === "initial") {
280
- return createSignal$1(prev => {
281
- if (!sharedConfig.hydrating) return fn(prev);
282
- subFetch(fn, prev);
283
- return prev ?? second;
284
- }, second, third);
285
- }
286
- const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second, third);
420
+ const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second);
287
421
  if (aiResult !== null) return aiResult;
288
- return createSignal$1(prev => {
289
- if (!sharedConfig.hydrating) return fn(prev);
290
- const o = getOwner();
291
- let initP;
292
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
293
- const init = initP?.v ?? initP;
294
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
295
- }, second, third);
422
+ return createSignal$1(prev => readSerializedOrCompute(fn, prev), second);
296
423
  }
297
424
  function hydratedCreateErrorBoundary(fn, fallback) {
298
425
  if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
@@ -314,127 +441,113 @@ function hydratedCreateErrorBoundary(fn, fallback) {
314
441
  }
315
442
  return createErrorBoundary$1(fn, fallback);
316
443
  }
317
- function hydratedCreateOptimistic(fn, second, third) {
318
- if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second, third);
444
+ function hydratedCreateOptimistic(fn, second) {
445
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second);
319
446
  markTopLevelSnapshotScope();
320
- const ssrSource = third?.ssrSource;
447
+ const ssrSource = second?.ssrSource;
321
448
  if (ssrSource === "client") {
322
- const [hydrated, setHydrated] = createSignal$1(false);
449
+ const [hydrated, setHydrated] = createSignal$1(false, {
450
+ ownedWrite: true
451
+ });
323
452
  const sig = createOptimistic$1(prev => {
324
- if (!hydrated()) return prev ?? second;
453
+ if (!hydrated()) return prev;
325
454
  return fn(prev);
326
- }, second, third);
455
+ }, second);
327
456
  setHydrated(true);
328
457
  return sig;
329
458
  }
330
- if (ssrSource === "initial") {
331
- return createOptimistic$1(prev => {
332
- if (!sharedConfig.hydrating) return fn(prev);
333
- subFetch(fn, prev);
334
- return prev ?? second;
335
- }, second, third);
336
- }
337
- const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second, third);
459
+ const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second);
338
460
  if (aiResult !== null) return aiResult;
339
- return createOptimistic$1(prev => {
340
- const o = getOwner();
341
- if (!sharedConfig.hydrating) return fn(prev);
342
- let initP;
343
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
344
- const init = initP?.v ?? initP;
345
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
346
- }, second, third);
347
- }
348
- function wrapStoreFn(fn, ssrSource) {
349
- if (ssrSource === "initial") {
350
- return draft => {
351
- if (!sharedConfig.hydrating) return fn(draft);
352
- subFetch(fn, draft);
353
- return undefined;
354
- };
461
+ return createOptimistic$1(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] = createSignal$1(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;
355
477
  }
356
- return draft => {
357
- const o = getOwner();
358
- if (!sharedConfig.hydrating) return fn(draft);
359
- let initP;
360
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
361
- const init = initP?.v ?? initP;
362
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
363
- };
478
+ if (ssrSource === "hybrid") {
479
+ const [hydrated, setHydrated] = createSignal$1(false, {
480
+ ownedWrite: true
481
+ });
482
+ const result = coreFn(draft => {
483
+ const o = 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);
364
505
  }
365
506
  function hydratedCreateStore(first, second, third) {
366
507
  if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
367
508
  markTopLevelSnapshotScope();
368
509
  const ssrSource = third?.ssrSource;
369
- if (ssrSource === "client" || ssrSource === "initial") {
370
- return createStore$1(second ?? {}, undefined, third);
371
- }
372
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
373
- if (aiResult !== null) return aiResult;
374
- return createStore$1(wrapStoreFn(first, ssrSource), second, third);
510
+ return hydrateStoreLikeFn(createStore$1, first, second ?? {}, third, ssrSource);
375
511
  }
376
512
  function hydratedCreateOptimisticStore(first, second, third) {
377
513
  if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
378
514
  markTopLevelSnapshotScope();
379
515
  const ssrSource = third?.ssrSource;
380
- if (ssrSource === "client" || ssrSource === "initial") {
381
- return createOptimisticStore$1(second ?? {}, undefined, third);
382
- }
383
- const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
384
- if (aiResult !== null) return aiResult;
385
- return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
516
+ return hydrateStoreLikeFn(createOptimisticStore$1, first, second ?? {}, third, ssrSource);
386
517
  }
387
518
  function hydratedCreateProjection(fn, initialValue, options) {
388
519
  if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
389
520
  markTopLevelSnapshotScope();
390
521
  const ssrSource = options?.ssrSource;
391
- if (ssrSource === "client" || ssrSource === "initial") {
392
- return createProjection$1(draft => draft, initialValue, options);
393
- }
394
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, initialValue, options);
395
- if (aiResult !== null) return aiResult[0];
396
- return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
522
+ return hydrateStoreLikeFn(createProjection$1, fn, initialValue, options, ssrSource);
397
523
  }
398
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
399
- 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);
400
526
  const ssrSource = options?.ssrSource;
401
527
  if (ssrSource === "client") {
402
- const [hydrated, setHydrated] = createSignal$1(false);
528
+ const [hydrated, setHydrated] = createSignal$1(false, {
529
+ ownedWrite: true
530
+ });
403
531
  let active = false;
404
532
  coreFn(prev => {
405
- if (!hydrated()) return value;
533
+ if (!hydrated()) return prev;
406
534
  active = true;
407
535
  return compute(prev);
408
536
  }, (next, prev) => {
409
537
  if (!active) return;
410
538
  return effectFn(next, prev);
411
- }, value, options);
539
+ }, options);
412
540
  setHydrated(true);
413
541
  return;
414
542
  }
415
- if (ssrSource === "initial") {
416
- coreFn(prev => {
417
- if (!sharedConfig.hydrating) return compute(prev);
418
- subFetch(compute, prev);
419
- return prev ?? value;
420
- }, effectFn, value, options);
421
- return;
422
- }
423
543
  markTopLevelSnapshotScope();
424
- coreFn(prev => {
425
- const o = getOwner();
426
- if (!sharedConfig.hydrating) return compute(prev);
427
- let initP;
428
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
429
- const init = initP?.v ?? initP;
430
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
431
- }, effectFn, value, options);
544
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
432
545
  }
433
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
434
- return hydratedEffect(createRenderEffect$1, compute, effectFn, value, options);
546
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
547
+ return hydratedEffect(createRenderEffect$1, compute, effectFn, options);
435
548
  }
436
- function hydratedCreateEffect(compute, effectFn, value, options) {
437
- return hydratedEffect(createEffect$1, compute, effectFn, value, options);
549
+ function hydratedCreateEffect(compute, effectFn, options) {
550
+ return hydratedEffect(createEffect$1, compute, effectFn, options);
438
551
  }
439
552
  function enableHydration() {
440
553
  _createMemo = hydratedCreateMemo;
@@ -493,24 +606,6 @@ const createStore = (...args) => (_createStore || createStore$1)(...args);
493
606
  const createOptimisticStore = (...args) => (_createOptimisticStore || createOptimisticStore$1)(...args);
494
607
  const createRenderEffect = (...args) => (_createRenderEffect || createRenderEffect$1)(...args);
495
608
  const createEffect = (...args) => (_createEffect || createEffect$1)(...args);
496
- function loadModuleAssets(mapping) {
497
- const hy = globalThis._$HY;
498
- if (!hy) return;
499
- if (!hy.modules) hy.modules = {};
500
- if (!hy.loading) hy.loading = {};
501
- const pending = [];
502
- for (const moduleUrl in mapping) {
503
- if (hy.modules[moduleUrl]) continue;
504
- const entryUrl = mapping[moduleUrl];
505
- if (!hy.loading[moduleUrl]) {
506
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
507
- hy.modules[moduleUrl] = mod;
508
- });
509
- }
510
- pending.push(hy.loading[moduleUrl]);
511
- }
512
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
513
- }
514
609
  function createBoundaryTrigger() {
515
610
  setSnapshotCapture(false);
516
611
  const [s, set] = createSignal$1(undefined, {
@@ -526,7 +621,7 @@ function resumeBoundaryHydration(o, id, set) {
526
621
  checkHydrationComplete();
527
622
  return;
528
623
  }
529
- sharedConfig.gather(id);
624
+ sharedConfig.gather?.(id);
530
625
  _hydratingValue = true;
531
626
  markSnapshotScope(o);
532
627
  _snapshotRootOwner = o;
@@ -538,38 +633,65 @@ function resumeBoundaryHydration(o, id, set) {
538
633
  flush();
539
634
  checkHydrationComplete();
540
635
  }
541
- function Loading(props) {
542
- if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
636
+ function initBoundaryResume(o, id) {
637
+ _pendingBoundaries++;
638
+ onCleanup(() => {
639
+ if (!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 createLoadingBoundary$1(fn, fallback, options);
670
+ let settledSerializationResumeQueued = false;
543
671
  return createMemo$1(() => {
544
672
  const o = getOwner();
545
673
  const id = o.id;
546
674
  let assetPromise;
547
675
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
548
676
  const mapping = sharedConfig.load(id + "_assets");
549
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
677
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
550
678
  }
551
679
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
552
- let ref = sharedConfig.load(id);
680
+ const ref = sharedConfig.load(id);
553
681
  let p;
554
682
  if (ref) {
555
- 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();
556
690
  }
557
691
  if (p) {
558
- _pendingBoundaries++;
559
- onCleanup(() => {
560
- if (!isDisposed(o)) return;
561
- sharedConfig.cleanupFragment?.(id);
562
- });
563
- const set = createBoundaryTrigger();
692
+ const [set, resume] = initBoundaryResume(o, id);
564
693
  if (p !== "$$f") {
565
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
566
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
567
- _pendingBoundaries--;
568
- checkHydrationComplete();
569
- runWithOwner(o, () => {
570
- throw err;
571
- });
572
- });
694
+ waitAndResume(p, resume, assetPromise);
573
695
  } else {
574
696
  const afterAssets = () => {
575
697
  _pendingBoundaries--;
@@ -578,16 +700,26 @@ function Loading(props) {
578
700
  };
579
701
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
580
702
  }
581
- 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();
582
713
  }
714
+ waitAndResume(fr, resume, assetPromise);
715
+ return fallback();
583
716
  }
584
- if (assetPromise) {
585
- _pendingBoundaries++;
586
- const set = createBoundaryTrigger();
587
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
717
+ if (assetPromise && !sharedConfig.has(id)) {
718
+ const [, resume] = initBoundaryResume(o, id);
719
+ assetPromise.then(resume);
588
720
  return undefined;
589
721
  }
590
- return createLoadBoundary(() => props.children, () => props.fallback);
722
+ return createLoadingBoundary$1(fn, fallback, options);
591
723
  });
592
724
  }
593
725
  function NoHydration(props) {
@@ -629,7 +761,9 @@ function lazy(fn, moduleUrl) {
629
761
  [$DEVCOMP]: true
630
762
  });
631
763
  return Comp(props);
632
- }) : "");
764
+ }) : "", {
765
+ sync: true
766
+ });
633
767
  };
634
768
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
635
769
  wrap.moduleUrl = moduleUrl;
@@ -661,33 +795,28 @@ function Repeat(props) {
661
795
  }
662
796
  function Show(props) {
663
797
  const keyed = props.keyed;
664
- const conditionValue = createMemo$1(() => props.when, undefined, {
798
+ const conditionValue = createMemo$1(() => props.when, {
665
799
  name: "condition value"
666
800
  } );
667
- const condition = keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
801
+ const condition = keyed ? conditionValue : createMemo$1(conditionValue, {
668
802
  equals: (a, b) => !a === !b,
669
- name: "condition"
803
+ name: "condition",
804
+ sync: true
670
805
  } );
671
806
  return createMemo$1(() => {
672
807
  const c = condition();
673
808
  if (c) {
674
809
  const child = props.children;
675
810
  const fn = typeof child === "function" && child.length > 0;
676
- return fn ? untrack(() => {
677
- setStrictRead("<Show>");
678
- try {
679
- return child(() => {
680
- if (!untrack(condition)) throw narrowedError("Show");
681
- return conditionValue();
682
- });
683
- } finally {
684
- setStrictRead(false);
685
- }
686
- }) : child;
811
+ return fn ? untrack(() => child(() => {
812
+ if (!untrack(condition)) throw narrowedError("Show");
813
+ return conditionValue();
814
+ }), "<Show>") : child;
687
815
  }
688
816
  return props.fallback;
689
- }, undefined, {
690
- name: "value"
817
+ }, {
818
+ name: "value",
819
+ sync: true
691
820
  } );
692
821
  }
693
822
  function Switch(props) {
@@ -699,16 +828,19 @@ function Switch(props) {
699
828
  const index = i;
700
829
  const mp = mps[i];
701
830
  const prevFunc = func;
702
- const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined, {
831
+ const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, {
703
832
  name: "condition value"
704
833
  } );
705
- const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
834
+ const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, {
706
835
  equals: (a, b) => !a === !b,
707
- name: "condition"
836
+ name: "condition",
837
+ sync: true
708
838
  } );
709
839
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
710
840
  }
711
841
  return func;
842
+ }, {
843
+ sync: true
712
844
  });
713
845
  return createMemo$1(() => {
714
846
  const sel = switchFunc()();
@@ -716,19 +848,13 @@ function Switch(props) {
716
848
  const [index, conditionValue, mp] = sel;
717
849
  const child = mp.children;
718
850
  const fn = typeof child === "function" && child.length > 0;
719
- return fn ? untrack(() => {
720
- setStrictRead("<Match>");
721
- try {
722
- return child(() => {
723
- if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
724
- return conditionValue();
725
- });
726
- } finally {
727
- setStrictRead(false);
728
- }
729
- }) : child;
730
- }, undefined, {
731
- name: "eval conditions"
851
+ return fn ? untrack(() => child(() => {
852
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
853
+ return conditionValue();
854
+ }), "<Match>") : child;
855
+ }, {
856
+ name: "eval conditions",
857
+ sync: true
732
858
  } );
733
859
  }
734
860
  function Match(props) {
@@ -741,16 +867,23 @@ function Errored(props) {
741
867
  return typeof f === "function" && f.length ? f(err, reset) : f;
742
868
  });
743
869
  }
870
+ function Loading(props) {
871
+ const onOpt = "on" in props ? {
872
+ on: () => props.on
873
+ } : undefined;
874
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
875
+ }
876
+ function Reveal(props) {
877
+ return createRevealOrder(() => props.children, {
878
+ order: () => props.order ?? "sequential",
879
+ collapsed: () => !!props.collapsed
880
+ });
881
+ }
744
882
 
745
883
  function ssrHandleError() {}
746
- function ssrRunInScope() {}
747
- const DevHooks = {};
748
- const DEV = {
749
- hooks: DevHooks,
750
- registerGraph
751
- } ;
884
+ const DEV = DEV$1 ;
752
885
  if (globalThis) {
753
886
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
754
887
  }
755
888
 
756
- 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 };
889
+ 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 };