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

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.
package/dist/dev.cjs CHANGED
@@ -38,17 +38,10 @@ function devComponent(Comp, props) {
38
38
  owner._props = props;
39
39
  owner._name = Comp.name;
40
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
- }
41
+ Object.assign(Comp, {
42
+ [$DEVCOMP]: true
51
43
  });
44
+ return signals.untrack(() => Comp(props), `<${Comp.name || "Anonymous"}>`);
52
45
  }, {
53
46
  transparent: true
54
47
  });
@@ -161,11 +154,41 @@ function subFetch(fn, prev) {
161
154
  Promise = ogPromise;
162
155
  }
163
156
  }
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];
157
+ function syncThenable(value) {
158
+ return {
159
+ then(fn) {
160
+ fn(value);
161
+ }
162
+ };
163
+ }
164
+ function normalizeIterator(it) {
165
+ let first = true;
166
+ let buffered = null;
167
+ return {
168
+ next() {
169
+ if (first) {
170
+ first = false;
171
+ const r = it.next();
172
+ return r && typeof r.then === "function" ? r : syncThenable(r);
173
+ }
174
+ if (buffered) {
175
+ const b = buffered;
176
+ buffered = null;
177
+ return b;
178
+ }
179
+ let latest = it.next();
180
+ if (latest && typeof latest.then === "function") return latest;
181
+ while (!latest.done) {
182
+ const peek = it.next();
183
+ if (peek && typeof peek.then === "function") {
184
+ buffered = peek;
185
+ break;
186
+ }
187
+ latest = peek;
188
+ }
189
+ return Promise.resolve(latest);
190
+ }
191
+ };
169
192
  }
170
193
  function applyPatches(target, patches) {
171
194
  for (const patch of patches) {
@@ -182,24 +205,6 @@ function applyPatches(target, patches) {
182
205
  }
183
206
  }
184
207
  }
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;
196
- }
197
- if (n.done) break;
198
- apply(n.value);
199
- }
200
- };
201
- consume();
202
- }
203
208
  function isAsyncIterable(v) {
204
209
  return v != null && typeof v[Symbol.asyncIterator] === "function";
205
210
  }
@@ -207,34 +212,85 @@ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
207
212
  const parent = signals.getOwner();
208
213
  const expectedId = signals.peekNextChildId(parent);
209
214
  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;
215
+ const loaded = sharedConfig.load(expectedId);
216
+ if (!isAsyncIterable(loaded)) return null;
217
+ const it = normalizeIterator(loaded[Symbol.asyncIterator]());
218
+ const iterable = {
219
+ [Symbol.asyncIterator]() {
220
+ return it;
221
+ }
222
+ };
223
+ return coreFn(() => iterable, value, options);
220
224
  }
221
225
  function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
222
226
  const parent = signals.getOwner();
223
227
  const expectedId = signals.peekNextChildId(parent);
224
228
  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];
229
+ const loaded = sharedConfig.load(expectedId);
230
+ if (!isAsyncIterable(loaded)) return null;
231
+ const srcIt = loaded[Symbol.asyncIterator]();
232
+ let isFirst = true;
233
+ let buffered = null;
234
+ return coreFn(draft => {
235
+ const process = res => {
236
+ if (res.done) return {
237
+ done: true,
238
+ value: undefined
239
+ };
240
+ if (isFirst) {
241
+ isFirst = false;
242
+ if (Array.isArray(res.value)) {
243
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
244
+ draft.length = res.value.length;
245
+ } else {
246
+ Object.assign(draft, res.value);
247
+ }
248
+ } else {
249
+ applyPatches(draft, res.value);
250
+ }
251
+ return {
252
+ done: false,
253
+ value: undefined
254
+ };
255
+ };
256
+ return {
257
+ [Symbol.asyncIterator]() {
258
+ return {
259
+ next() {
260
+ if (isFirst) {
261
+ const r = srcIt.next();
262
+ return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
263
+ }
264
+ if (buffered) {
265
+ const b = buffered;
266
+ buffered = null;
267
+ return b.then(process);
268
+ }
269
+ let r = srcIt.next();
270
+ if (r && typeof r.then === "function") {
271
+ return r.then(process);
272
+ }
273
+ let result = process(r);
274
+ while (!r.done) {
275
+ const peek = srcIt.next();
276
+ if (peek && typeof peek.then === "function") {
277
+ buffered = peek;
278
+ break;
279
+ }
280
+ r = peek;
281
+ if (!r.done) result = process(r);
282
+ }
283
+ return Promise.resolve(result);
284
+ }
285
+ };
286
+ }
287
+ };
288
+ }, initialValue, options);
235
289
  }
236
290
  function hydratedCreateMemo(compute, value, options) {
237
- if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
291
+ if (!sharedConfig.hydrating) {
292
+ return signals.createMemo(compute, value, options);
293
+ }
238
294
  markTopLevelSnapshotScope();
239
295
  const ssrSource = options?.ssrSource;
240
296
  if (ssrSource === "client") {
@@ -386,14 +442,16 @@ function hydratedCreateOptimisticStore(first, second, third) {
386
442
  return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
387
443
  }
388
444
  function hydratedCreateProjection(fn, initialValue, options) {
389
- if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
445
+ if (!sharedConfig.hydrating) {
446
+ return signals.createProjection(fn, initialValue, options);
447
+ }
390
448
  markTopLevelSnapshotScope();
391
449
  const ssrSource = options?.ssrSource;
392
450
  if (ssrSource === "client" || ssrSource === "initial") {
393
451
  return signals.createProjection(draft => draft, initialValue, options);
394
452
  }
395
- const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
396
- if (aiResult !== null) return aiResult[0];
453
+ const aiResult = hydrateStoreFromAsyncIterable(signals.createProjection, initialValue, options);
454
+ if (aiResult !== null) return aiResult;
397
455
  return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
398
456
  }
399
457
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
@@ -674,17 +732,10 @@ function Show(props) {
674
732
  if (c) {
675
733
  const child = props.children;
676
734
  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;
735
+ return fn ? signals.untrack(() => child(() => {
736
+ if (!signals.untrack(condition)) throw narrowedError("Show");
737
+ return conditionValue();
738
+ }), "<Show>") : child;
688
739
  }
689
740
  return props.fallback;
690
741
  }, undefined, {
@@ -717,17 +768,10 @@ function Switch(props) {
717
768
  const [index, conditionValue, mp] = sel;
718
769
  const child = mp.children;
719
770
  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;
771
+ return fn ? signals.untrack(() => child(() => {
772
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
773
+ return conditionValue();
774
+ }), "<Match>") : child;
731
775
  }, undefined, {
732
776
  name: "eval conditions"
733
777
  } );
@@ -758,6 +802,10 @@ Object.defineProperty(exports, "$PROXY", {
758
802
  enumerable: true,
759
803
  get: function () { return signals.$PROXY; }
760
804
  });
805
+ Object.defineProperty(exports, "$REFRESH", {
806
+ enumerable: true,
807
+ get: function () { return signals.$REFRESH; }
808
+ });
761
809
  Object.defineProperty(exports, "$TRACK", {
762
810
  enumerable: true,
763
811
  get: function () { return signals.$TRACK; }
@@ -870,6 +918,10 @@ Object.defineProperty(exports, "runWithOwner", {
870
918
  enumerable: true,
871
919
  get: function () { return signals.runWithOwner; }
872
920
  });
921
+ Object.defineProperty(exports, "setOnUnhandledAsync", {
922
+ enumerable: true,
923
+ get: function () { return signals.setOnUnhandledAsync; }
924
+ });
873
925
  Object.defineProperty(exports, "snapshot", {
874
926
  enumerable: true,
875
927
  get: function () { return signals.snapshot; }
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, getOwner, createRoot, setContext, untrack, 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, $REFRESH, $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, setOnUnhandledAsync, snapshot, storePath, untrack } from '@solidjs/signals';
3
3
 
4
4
  const $DEVCOMP = Symbol("COMPONENT_DEV" );
5
5
  function createContext(defaultValue, options) {
@@ -37,17 +37,10 @@ function devComponent(Comp, props) {
37
37
  owner._props = props;
38
38
  owner._name = Comp.name;
39
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
- }
40
+ Object.assign(Comp, {
41
+ [$DEVCOMP]: true
50
42
  });
43
+ return untrack(() => Comp(props), `<${Comp.name || "Anonymous"}>`);
51
44
  }, {
52
45
  transparent: true
53
46
  });
@@ -160,11 +153,41 @@ function subFetch(fn, prev) {
160
153
  Promise = ogPromise;
161
154
  }
162
155
  }
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];
156
+ function syncThenable(value) {
157
+ return {
158
+ then(fn) {
159
+ fn(value);
160
+ }
161
+ };
162
+ }
163
+ function normalizeIterator(it) {
164
+ let first = true;
165
+ let buffered = null;
166
+ return {
167
+ next() {
168
+ if (first) {
169
+ first = false;
170
+ const r = it.next();
171
+ return r && typeof r.then === "function" ? r : syncThenable(r);
172
+ }
173
+ if (buffered) {
174
+ const b = buffered;
175
+ buffered = null;
176
+ return b;
177
+ }
178
+ let latest = it.next();
179
+ if (latest && typeof latest.then === "function") return latest;
180
+ while (!latest.done) {
181
+ const peek = it.next();
182
+ if (peek && typeof peek.then === "function") {
183
+ buffered = peek;
184
+ break;
185
+ }
186
+ latest = peek;
187
+ }
188
+ return Promise.resolve(latest);
189
+ }
190
+ };
168
191
  }
169
192
  function applyPatches(target, patches) {
170
193
  for (const patch of patches) {
@@ -181,24 +204,6 @@ function applyPatches(target, patches) {
181
204
  }
182
205
  }
183
206
  }
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;
195
- }
196
- if (n.done) break;
197
- apply(n.value);
198
- }
199
- };
200
- consume();
201
- }
202
207
  function isAsyncIterable(v) {
203
208
  return v != null && typeof v[Symbol.asyncIterator] === "function";
204
209
  }
@@ -206,34 +211,85 @@ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
206
211
  const parent = getOwner();
207
212
  const expectedId = peekNextChildId(parent);
208
213
  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;
214
+ const loaded = sharedConfig.load(expectedId);
215
+ if (!isAsyncIterable(loaded)) return null;
216
+ const it = normalizeIterator(loaded[Symbol.asyncIterator]());
217
+ const iterable = {
218
+ [Symbol.asyncIterator]() {
219
+ return it;
220
+ }
221
+ };
222
+ return coreFn(() => iterable, value, options);
219
223
  }
220
224
  function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
221
225
  const parent = getOwner();
222
226
  const expectedId = peekNextChildId(parent);
223
227
  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];
228
+ const loaded = sharedConfig.load(expectedId);
229
+ if (!isAsyncIterable(loaded)) return null;
230
+ const srcIt = loaded[Symbol.asyncIterator]();
231
+ let isFirst = true;
232
+ let buffered = null;
233
+ return coreFn(draft => {
234
+ const process = res => {
235
+ if (res.done) return {
236
+ done: true,
237
+ value: undefined
238
+ };
239
+ if (isFirst) {
240
+ isFirst = false;
241
+ if (Array.isArray(res.value)) {
242
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
243
+ draft.length = res.value.length;
244
+ } else {
245
+ Object.assign(draft, res.value);
246
+ }
247
+ } else {
248
+ applyPatches(draft, res.value);
249
+ }
250
+ return {
251
+ done: false,
252
+ value: undefined
253
+ };
254
+ };
255
+ return {
256
+ [Symbol.asyncIterator]() {
257
+ return {
258
+ next() {
259
+ if (isFirst) {
260
+ const r = srcIt.next();
261
+ return r && typeof r.then === "function" ? r.then(process) : syncThenable(process(r));
262
+ }
263
+ if (buffered) {
264
+ const b = buffered;
265
+ buffered = null;
266
+ return b.then(process);
267
+ }
268
+ let r = srcIt.next();
269
+ if (r && typeof r.then === "function") {
270
+ return r.then(process);
271
+ }
272
+ let result = process(r);
273
+ while (!r.done) {
274
+ const peek = srcIt.next();
275
+ if (peek && typeof peek.then === "function") {
276
+ buffered = peek;
277
+ break;
278
+ }
279
+ r = peek;
280
+ if (!r.done) result = process(r);
281
+ }
282
+ return Promise.resolve(result);
283
+ }
284
+ };
285
+ }
286
+ };
287
+ }, initialValue, options);
234
288
  }
235
289
  function hydratedCreateMemo(compute, value, options) {
236
- if (!sharedConfig.hydrating) return createMemo$1(compute, value, options);
290
+ if (!sharedConfig.hydrating) {
291
+ return createMemo$1(compute, value, options);
292
+ }
237
293
  markTopLevelSnapshotScope();
238
294
  const ssrSource = options?.ssrSource;
239
295
  if (ssrSource === "client") {
@@ -385,14 +441,16 @@ function hydratedCreateOptimisticStore(first, second, third) {
385
441
  return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
386
442
  }
387
443
  function hydratedCreateProjection(fn, initialValue, options) {
388
- if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
444
+ if (!sharedConfig.hydrating) {
445
+ return createProjection$1(fn, initialValue, options);
446
+ }
389
447
  markTopLevelSnapshotScope();
390
448
  const ssrSource = options?.ssrSource;
391
449
  if (ssrSource === "client" || ssrSource === "initial") {
392
450
  return createProjection$1(draft => draft, initialValue, options);
393
451
  }
394
- const aiResult = hydrateStoreFromAsyncIterable(createStore$1, initialValue, options);
395
- if (aiResult !== null) return aiResult[0];
452
+ const aiResult = hydrateStoreFromAsyncIterable(createProjection$1, initialValue, options);
453
+ if (aiResult !== null) return aiResult;
396
454
  return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
397
455
  }
398
456
  function hydratedEffect(coreFn, compute, effectFn, value, options) {
@@ -673,17 +731,10 @@ function Show(props) {
673
731
  if (c) {
674
732
  const child = props.children;
675
733
  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;
734
+ return fn ? untrack(() => child(() => {
735
+ if (!untrack(condition)) throw narrowedError("Show");
736
+ return conditionValue();
737
+ }), "<Show>") : child;
687
738
  }
688
739
  return props.fallback;
689
740
  }, undefined, {
@@ -716,17 +767,10 @@ function Switch(props) {
716
767
  const [index, conditionValue, mp] = sel;
717
768
  const child = mp.children;
718
769
  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;
770
+ return fn ? untrack(() => child(() => {
771
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
772
+ return conditionValue();
773
+ }), "<Match>") : child;
730
774
  }, undefined, {
731
775
  name: "eval conditions"
732
776
  } );