solid-js 2.0.0-experimental.5 → 2.0.0-experimental.7

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
@@ -98,7 +98,7 @@ function from(producer, initialValue = undefined) {
98
98
  }
99
99
 
100
100
  const sharedConfig = {
101
- context: undefined,
101
+ hydrating: false,
102
102
  registry: undefined,
103
103
  done: false,
104
104
  getNextContextId() {
@@ -107,8 +107,90 @@ const sharedConfig = {
107
107
  return o.getNextChildId();
108
108
  }
109
109
  };
110
- function setHydrateContext(context) {
111
- sharedConfig.context = context;
110
+ function Suspense(props) {
111
+ if (!sharedConfig.hydrating) return signals.createSuspense(() => props.children, () => props.fallback);
112
+ return signals.createMemo(() => {
113
+ const o = signals.getOwner();
114
+ const id = o.id;
115
+ if (sharedConfig.hydrating && sharedConfig.has(id)) {
116
+ let ref = sharedConfig.load(id);
117
+ let p;
118
+ if (ref) {
119
+ if (typeof ref !== "object" || ref.s !== "success") p = ref;else sharedConfig.gather(id);
120
+ }
121
+ if (p) {
122
+ const [s, set] = signals.createSignal(undefined, {
123
+ equals: false
124
+ });
125
+ s();
126
+ if (p !== "$$f") {
127
+ p.then(() => {
128
+ sharedConfig.gather(id);
129
+ sharedConfig.hydrating = true;
130
+ set();
131
+ signals.flush();
132
+ sharedConfig.hydrating = false;
133
+ }, err => signals.runWithObserver(o, () => {
134
+ throw err;
135
+ }));
136
+ } else queueMicrotask(set);
137
+ return props.fallback;
138
+ }
139
+ }
140
+ return signals.createSuspense(() => props.children, () => props.fallback);
141
+ });
142
+ }
143
+ function createAsync(compute, value, options) {
144
+ if (!sharedConfig.hydrating) return signals.createAsync(compute, value, options);
145
+ return signals.createAsync(prev => {
146
+ if (!sharedConfig.hydrating) return compute(prev);
147
+ const o = signals.getOwner();
148
+ let initP;
149
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
150
+ const init = initP?.value || initP;
151
+ return init ? (subFetch(compute, prev), init) : compute(prev);
152
+ }, value, options);
153
+ }
154
+ class MockPromise {
155
+ static all() {
156
+ return new MockPromise();
157
+ }
158
+ static allSettled() {
159
+ return new MockPromise();
160
+ }
161
+ static any() {
162
+ return new MockPromise();
163
+ }
164
+ static race() {
165
+ return new MockPromise();
166
+ }
167
+ static reject() {
168
+ return new MockPromise();
169
+ }
170
+ static resolve() {
171
+ return new MockPromise();
172
+ }
173
+ catch() {
174
+ return new MockPromise();
175
+ }
176
+ then() {
177
+ return new MockPromise();
178
+ }
179
+ finally() {
180
+ return new MockPromise();
181
+ }
182
+ }
183
+ function subFetch(fn, prev) {
184
+ const ogFetch = fetch;
185
+ const ogPromise = Promise;
186
+ try {
187
+ window.fetch = () => new MockPromise();
188
+ Promise = MockPromise;
189
+ return fn(prev);
190
+ } finally {
191
+ window.fetch = ogFetch;
192
+ Promise = ogPromise;
193
+ }
112
194
  }
113
195
 
114
196
  function enableHydration() {
@@ -120,19 +202,7 @@ function lazy(fn) {
120
202
  let comp;
121
203
  let p;
122
204
  const wrap = props => {
123
- const ctx = sharedConfig.context;
124
- if (ctx) {
125
- const [s, set] = signals.createSignal();
126
- sharedConfig.count || (sharedConfig.count = 0);
127
- sharedConfig.count++;
128
- (p || (p = fn())).then(mod => {
129
- !sharedConfig.done && setHydrateContext(ctx);
130
- sharedConfig.count--;
131
- set(() => mod.default);
132
- setHydrateContext();
133
- });
134
- comp = s;
135
- } else if (!comp) {
205
+ if (!comp) {
136
206
  const s = signals.createAsync(() => (p || (p = fn())).then(mod => mod.default));
137
207
  comp = s;
138
208
  }
@@ -141,12 +211,7 @@ function lazy(fn) {
141
211
  Object.assign(Comp, {
142
212
  [$DEVCOMP]: true
143
213
  });
144
- if (!ctx || sharedConfig.done) return Comp(props);
145
- const c = sharedConfig.context;
146
- setHydrateContext(ctx);
147
- const r = Comp(props);
148
- setHydrateContext(c);
149
- return r;
214
+ return Comp(props);
150
215
  }) : "");
151
216
  };
152
217
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
@@ -154,8 +219,7 @@ function lazy(fn) {
154
219
  }
155
220
  let counter = 0;
156
221
  function createUniqueId() {
157
- const ctx = sharedConfig.context;
158
- return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
222
+ return sharedConfig.hydrating ? sharedConfig.getNextContextId() : `cl-${counter++}`;
159
223
  }
160
224
 
161
225
  const narrowedError = name => `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.` ;
@@ -248,9 +312,6 @@ function ErrorBoundary(props) {
248
312
  return typeof f === "function" && f.length ? f(err, reset) : f;
249
313
  });
250
314
  }
251
- function Suspense(props) {
252
- return signals.createSuspense(() => props.children, () => props.fallback);
253
- }
254
315
  function Boundary(props) {
255
316
  return signals.createBoundary(() => props.children, () => props.mode);
256
317
  }
@@ -270,18 +331,10 @@ Object.defineProperty(exports, "$PROXY", {
270
331
  enumerable: true,
271
332
  get: function () { return signals.$PROXY; }
272
333
  });
273
- Object.defineProperty(exports, "$RAW", {
274
- enumerable: true,
275
- get: function () { return signals.$RAW; }
276
- });
277
334
  Object.defineProperty(exports, "$TRACK", {
278
335
  enumerable: true,
279
336
  get: function () { return signals.$TRACK; }
280
337
  });
281
- Object.defineProperty(exports, "createAsync", {
282
- enumerable: true,
283
- get: function () { return signals.createAsync; }
284
- });
285
338
  Object.defineProperty(exports, "createEffect", {
286
339
  enumerable: true,
287
340
  get: function () { return signals.createEffect; }
@@ -290,6 +343,10 @@ Object.defineProperty(exports, "createMemo", {
290
343
  enumerable: true,
291
344
  get: function () { return signals.createMemo; }
292
345
  });
346
+ Object.defineProperty(exports, "createOptimistic", {
347
+ enumerable: true,
348
+ get: function () { return signals.createOptimistic; }
349
+ });
293
350
  Object.defineProperty(exports, "createProjection", {
294
351
  enumerable: true,
295
352
  get: function () { return signals.createProjection; }
@@ -310,13 +367,17 @@ Object.defineProperty(exports, "createStore", {
310
367
  enumerable: true,
311
368
  get: function () { return signals.createStore; }
312
369
  });
370
+ Object.defineProperty(exports, "deep", {
371
+ enumerable: true,
372
+ get: function () { return signals.deep; }
373
+ });
313
374
  Object.defineProperty(exports, "flatten", {
314
375
  enumerable: true,
315
376
  get: function () { return signals.flatten; }
316
377
  });
317
- Object.defineProperty(exports, "flushSync", {
378
+ Object.defineProperty(exports, "flush", {
318
379
  enumerable: true,
319
- get: function () { return signals.flushSync; }
380
+ get: function () { return signals.flush; }
320
381
  });
321
382
  Object.defineProperty(exports, "getObserver", {
322
383
  enumerable: true,
@@ -378,6 +439,14 @@ Object.defineProperty(exports, "runWithOwner", {
378
439
  enumerable: true,
379
440
  get: function () { return signals.runWithOwner; }
380
441
  });
442
+ Object.defineProperty(exports, "snapshot", {
443
+ enumerable: true,
444
+ get: function () { return signals.snapshot; }
445
+ });
446
+ Object.defineProperty(exports, "transition", {
447
+ enumerable: true,
448
+ get: function () { return signals.transition; }
449
+ });
381
450
  Object.defineProperty(exports, "tryCatch", {
382
451
  enumerable: true,
383
452
  get: function () { return signals.tryCatch; }
@@ -386,10 +455,6 @@ Object.defineProperty(exports, "untrack", {
386
455
  enumerable: true,
387
456
  get: function () { return signals.untrack; }
388
457
  });
389
- Object.defineProperty(exports, "unwrap", {
390
- enumerable: true,
391
- get: function () { return signals.unwrap; }
392
- });
393
458
  exports.$DEVCOMP = $DEVCOMP;
394
459
  exports.Boundary = Boundary;
395
460
  exports.DEV = DEV;
@@ -401,6 +466,7 @@ exports.Show = Show;
401
466
  exports.Suspense = Suspense;
402
467
  exports.Switch = Switch;
403
468
  exports.children = children;
469
+ exports.createAsync = createAsync;
404
470
  exports.createComponent = createComponent;
405
471
  exports.createContext = createContext;
406
472
  exports.createUniqueId = createUniqueId;
package/dist/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createEffect, getContext, createMemo, flatten, createRoot, setContext, getOwner, untrack, onCleanup, createSignal, createAsync, mapArray, repeat, createErrorBoundary, createSuspense, createBoundary } from '@solidjs/signals';
2
- export { $PROXY, $RAW, $TRACK, createAsync, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, flatten, flushSync, getObserver, getOwner, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, tryCatch, untrack, unwrap } from '@solidjs/signals';
1
+ import { createEffect, getContext, createMemo, flatten, createRoot, setContext, getOwner, untrack, onCleanup, createSignal, createSuspense, flush, runWithObserver, createAsync as createAsync$1, mapArray, repeat, createErrorBoundary, createBoundary } from '@solidjs/signals';
2
+ export { $PROXY, $TRACK, createEffect, createMemo, createOptimistic, createProjection, createRenderEffect, createRoot, createSignal, createStore, deep, flatten, flush, getObserver, getOwner, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, snapshot, transition, tryCatch, untrack } from '@solidjs/signals';
3
3
 
4
4
  const $DEVCOMP = Symbol("COMPONENT_DEV" );
5
5
  function onMount(fn) {
@@ -97,7 +97,7 @@ function from(producer, initialValue = undefined) {
97
97
  }
98
98
 
99
99
  const sharedConfig = {
100
- context: undefined,
100
+ hydrating: false,
101
101
  registry: undefined,
102
102
  done: false,
103
103
  getNextContextId() {
@@ -106,8 +106,90 @@ const sharedConfig = {
106
106
  return o.getNextChildId();
107
107
  }
108
108
  };
109
- function setHydrateContext(context) {
110
- sharedConfig.context = context;
109
+ function Suspense(props) {
110
+ if (!sharedConfig.hydrating) return createSuspense(() => props.children, () => props.fallback);
111
+ return createMemo(() => {
112
+ const o = getOwner();
113
+ const id = o.id;
114
+ if (sharedConfig.hydrating && sharedConfig.has(id)) {
115
+ let ref = sharedConfig.load(id);
116
+ let p;
117
+ if (ref) {
118
+ if (typeof ref !== "object" || ref.s !== "success") p = ref;else sharedConfig.gather(id);
119
+ }
120
+ if (p) {
121
+ const [s, set] = createSignal(undefined, {
122
+ equals: false
123
+ });
124
+ s();
125
+ if (p !== "$$f") {
126
+ p.then(() => {
127
+ sharedConfig.gather(id);
128
+ sharedConfig.hydrating = true;
129
+ set();
130
+ flush();
131
+ sharedConfig.hydrating = false;
132
+ }, err => runWithObserver(o, () => {
133
+ throw err;
134
+ }));
135
+ } else queueMicrotask(set);
136
+ return props.fallback;
137
+ }
138
+ }
139
+ return createSuspense(() => props.children, () => props.fallback);
140
+ });
141
+ }
142
+ function createAsync(compute, value, options) {
143
+ if (!sharedConfig.hydrating) return createAsync$1(compute, value, options);
144
+ return createAsync$1(prev => {
145
+ if (!sharedConfig.hydrating) return compute(prev);
146
+ const o = getOwner();
147
+ let initP;
148
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
149
+ const init = initP?.value || initP;
150
+ return init ? (subFetch(compute, prev), init) : compute(prev);
151
+ }, value, options);
152
+ }
153
+ class MockPromise {
154
+ static all() {
155
+ return new MockPromise();
156
+ }
157
+ static allSettled() {
158
+ return new MockPromise();
159
+ }
160
+ static any() {
161
+ return new MockPromise();
162
+ }
163
+ static race() {
164
+ return new MockPromise();
165
+ }
166
+ static reject() {
167
+ return new MockPromise();
168
+ }
169
+ static resolve() {
170
+ return new MockPromise();
171
+ }
172
+ catch() {
173
+ return new MockPromise();
174
+ }
175
+ then() {
176
+ return new MockPromise();
177
+ }
178
+ finally() {
179
+ return new MockPromise();
180
+ }
181
+ }
182
+ function subFetch(fn, prev) {
183
+ const ogFetch = fetch;
184
+ const ogPromise = Promise;
185
+ try {
186
+ window.fetch = () => new MockPromise();
187
+ Promise = MockPromise;
188
+ return fn(prev);
189
+ } finally {
190
+ window.fetch = ogFetch;
191
+ Promise = ogPromise;
192
+ }
111
193
  }
112
194
 
113
195
  function enableHydration() {
@@ -119,20 +201,8 @@ function lazy(fn) {
119
201
  let comp;
120
202
  let p;
121
203
  const wrap = props => {
122
- const ctx = sharedConfig.context;
123
- if (ctx) {
124
- const [s, set] = createSignal();
125
- sharedConfig.count || (sharedConfig.count = 0);
126
- sharedConfig.count++;
127
- (p || (p = fn())).then(mod => {
128
- !sharedConfig.done && setHydrateContext(ctx);
129
- sharedConfig.count--;
130
- set(() => mod.default);
131
- setHydrateContext();
132
- });
133
- comp = s;
134
- } else if (!comp) {
135
- const s = createAsync(() => (p || (p = fn())).then(mod => mod.default));
204
+ if (!comp) {
205
+ const s = createAsync$1(() => (p || (p = fn())).then(mod => mod.default));
136
206
  comp = s;
137
207
  }
138
208
  let Comp;
@@ -140,12 +210,7 @@ function lazy(fn) {
140
210
  Object.assign(Comp, {
141
211
  [$DEVCOMP]: true
142
212
  });
143
- if (!ctx || sharedConfig.done) return Comp(props);
144
- const c = sharedConfig.context;
145
- setHydrateContext(ctx);
146
- const r = Comp(props);
147
- setHydrateContext(c);
148
- return r;
213
+ return Comp(props);
149
214
  }) : "");
150
215
  };
151
216
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
@@ -153,8 +218,7 @@ function lazy(fn) {
153
218
  }
154
219
  let counter = 0;
155
220
  function createUniqueId() {
156
- const ctx = sharedConfig.context;
157
- return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
221
+ return sharedConfig.hydrating ? sharedConfig.getNextContextId() : `cl-${counter++}`;
158
222
  }
159
223
 
160
224
  const narrowedError = name => `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.` ;
@@ -247,9 +311,6 @@ function ErrorBoundary(props) {
247
311
  return typeof f === "function" && f.length ? f(err, reset) : f;
248
312
  });
249
313
  }
250
- function Suspense(props) {
251
- return createSuspense(() => props.children, () => props.fallback);
252
- }
253
314
  function Boundary(props) {
254
315
  return createBoundary(() => props.children, () => props.mode);
255
316
  }
@@ -265,4 +326,4 @@ if (globalThis) {
265
326
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
266
327
  }
267
328
 
268
- export { $DEVCOMP, Boundary, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, ssrHandleError, ssrRunInScope, useContext };
329
+ export { $DEVCOMP, Boundary, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createAsync, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, ssrHandleError, ssrRunInScope, useContext };