solid-js 2.0.0-experimental.4 → 2.0.0-experimental.6

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
@@ -9,8 +9,8 @@ function onMount(fn) {
9
9
  function createContext(defaultValue, options) {
10
10
  const id = Symbol(options && options.name || "");
11
11
  function provider(props) {
12
- return signals.createMemo(() => {
13
- signals.setContext(provider, signals.untrack(() => props.value));
12
+ return signals.createRoot(() => {
13
+ signals.setContext(provider, props.value);
14
14
  return children(() => props.children);
15
15
  });
16
16
  }
@@ -98,65 +98,111 @@ 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
- getContextId() {
105
- return getContextId(this.context.count);
106
- },
107
104
  getNextContextId() {
108
- return getContextId(this.context.count++);
105
+ const o = signals.getOwner();
106
+ if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
107
+ return o.getNextChildId();
109
108
  }
110
109
  };
111
- function getContextId(count) {
112
- const num = String(count),
113
- len = num.length - 1;
114
- return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
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
+ });
115
142
  }
116
- function setHydrateContext(context) {
117
- sharedConfig.context = context;
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);
118
153
  }
119
- function nextHydrateContext() {
120
- return {
121
- ...sharedConfig.context,
122
- id: sharedConfig.getNextContextId(),
123
- count: 0
124
- };
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
+ }
125
194
  }
126
195
 
127
- let hydrationEnabled = false;
128
196
  function enableHydration() {
129
- hydrationEnabled = true;
130
197
  }
131
198
  function createComponent(Comp, props) {
132
- if (hydrationEnabled) {
133
- if (sharedConfig.context) {
134
- const c = sharedConfig.context;
135
- setHydrateContext(nextHydrateContext());
136
- const r = devComponent(Comp, props || {}) ;
137
- setHydrateContext(c);
138
- return r;
139
- }
140
- }
141
199
  return devComponent(Comp, props || {});
142
200
  }
143
201
  function lazy(fn) {
144
202
  let comp;
145
203
  let p;
146
204
  const wrap = props => {
147
- const ctx = sharedConfig.context;
148
- if (ctx) {
149
- const [s, set] = signals.createSignal();
150
- sharedConfig.count || (sharedConfig.count = 0);
151
- sharedConfig.count++;
152
- (p || (p = fn())).then(mod => {
153
- !sharedConfig.done && setHydrateContext(ctx);
154
- sharedConfig.count--;
155
- set(() => mod.default);
156
- setHydrateContext();
157
- });
158
- comp = s;
159
- } else if (!comp) {
205
+ if (!comp) {
160
206
  const s = signals.createAsync(() => (p || (p = fn())).then(mod => mod.default));
161
207
  comp = s;
162
208
  }
@@ -165,12 +211,7 @@ function lazy(fn) {
165
211
  Object.assign(Comp, {
166
212
  [$DEVCOMP]: true
167
213
  });
168
- if (!ctx || sharedConfig.done) return Comp(props);
169
- const c = sharedConfig.context;
170
- setHydrateContext(ctx);
171
- const r = Comp(props);
172
- setHydrateContext(c);
173
- return r;
214
+ return Comp(props);
174
215
  }) : "");
175
216
  };
176
217
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
@@ -178,8 +219,7 @@ function lazy(fn) {
178
219
  }
179
220
  let counter = 0;
180
221
  function createUniqueId() {
181
- const ctx = sharedConfig.context;
182
- return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
222
+ return sharedConfig.hydrating ? sharedConfig.getNextContextId() : `cl-${counter++}`;
183
223
  }
184
224
 
185
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.` ;
@@ -272,10 +312,12 @@ function ErrorBoundary(props) {
272
312
  return typeof f === "function" && f.length ? f(err, reset) : f;
273
313
  });
274
314
  }
275
- function Suspense(props) {
276
- return signals.createSuspense(() => props.children, () => props.fallback);
315
+ function Boundary(props) {
316
+ return signals.createBoundary(() => props.children, () => props.mode);
277
317
  }
278
318
 
319
+ function ssrHandleError() {}
320
+ function ssrRunInScope() {}
279
321
  const DevHooks = {};
280
322
  const DEV = {
281
323
  hooks: DevHooks,
@@ -289,22 +331,10 @@ Object.defineProperty(exports, "$PROXY", {
289
331
  enumerable: true,
290
332
  get: function () { return signals.$PROXY; }
291
333
  });
292
- Object.defineProperty(exports, "$RAW", {
293
- enumerable: true,
294
- get: function () { return signals.$RAW; }
295
- });
296
334
  Object.defineProperty(exports, "$TRACK", {
297
335
  enumerable: true,
298
336
  get: function () { return signals.$TRACK; }
299
337
  });
300
- Object.defineProperty(exports, "catchError", {
301
- enumerable: true,
302
- get: function () { return signals.catchError; }
303
- });
304
- Object.defineProperty(exports, "createAsync", {
305
- enumerable: true,
306
- get: function () { return signals.createAsync; }
307
- });
308
338
  Object.defineProperty(exports, "createEffect", {
309
339
  enumerable: true,
310
340
  get: function () { return signals.createEffect; }
@@ -333,13 +363,17 @@ Object.defineProperty(exports, "createStore", {
333
363
  enumerable: true,
334
364
  get: function () { return signals.createStore; }
335
365
  });
366
+ Object.defineProperty(exports, "deep", {
367
+ enumerable: true,
368
+ get: function () { return signals.deep; }
369
+ });
336
370
  Object.defineProperty(exports, "flatten", {
337
371
  enumerable: true,
338
372
  get: function () { return signals.flatten; }
339
373
  });
340
- Object.defineProperty(exports, "flushSync", {
374
+ Object.defineProperty(exports, "flush", {
341
375
  enumerable: true,
342
- get: function () { return signals.flushSync; }
376
+ get: function () { return signals.flush; }
343
377
  });
344
378
  Object.defineProperty(exports, "getObserver", {
345
379
  enumerable: true,
@@ -401,15 +435,20 @@ Object.defineProperty(exports, "runWithOwner", {
401
435
  enumerable: true,
402
436
  get: function () { return signals.runWithOwner; }
403
437
  });
404
- Object.defineProperty(exports, "untrack", {
438
+ Object.defineProperty(exports, "snapshot", {
405
439
  enumerable: true,
406
- get: function () { return signals.untrack; }
440
+ get: function () { return signals.snapshot; }
407
441
  });
408
- Object.defineProperty(exports, "unwrap", {
442
+ Object.defineProperty(exports, "tryCatch", {
409
443
  enumerable: true,
410
- get: function () { return signals.unwrap; }
444
+ get: function () { return signals.tryCatch; }
445
+ });
446
+ Object.defineProperty(exports, "untrack", {
447
+ enumerable: true,
448
+ get: function () { return signals.untrack; }
411
449
  });
412
450
  exports.$DEVCOMP = $DEVCOMP;
451
+ exports.Boundary = Boundary;
413
452
  exports.DEV = DEV;
414
453
  exports.ErrorBoundary = ErrorBoundary;
415
454
  exports.For = For;
@@ -419,6 +458,7 @@ exports.Show = Show;
419
458
  exports.Suspense = Suspense;
420
459
  exports.Switch = Switch;
421
460
  exports.children = children;
461
+ exports.createAsync = createAsync;
422
462
  exports.createComponent = createComponent;
423
463
  exports.createContext = createContext;
424
464
  exports.createUniqueId = createUniqueId;
@@ -428,4 +468,6 @@ exports.lazy = lazy;
428
468
  exports.observable = observable;
429
469
  exports.onMount = onMount;
430
470
  exports.sharedConfig = sharedConfig;
471
+ exports.ssrHandleError = ssrHandleError;
472
+ exports.ssrRunInScope = ssrRunInScope;
431
473
  exports.useContext = useContext;