solid-js 1.2.4 → 1.3.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
@@ -187,18 +187,21 @@ function createSignal(value, options) {
187
187
  comparator: options.equals || undefined
188
188
  };
189
189
  if (!options.internal) s.name = registerGraph(options.name || hashValue(value), s);
190
- return [readSignal.bind(s), value => {
190
+ const setter = value => {
191
191
  if (typeof value === "function") {
192
192
  if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
193
193
  }
194
194
  return writeSignal(s, value);
195
- }];
195
+ };
196
+ return [readSignal.bind(s), setter];
196
197
  }
197
198
  function createComputed(fn, value, options) {
198
- updateComputation(createComputation(fn, value, true, STALE, options ));
199
+ const c = createComputation(fn, value, true, STALE, options );
200
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
199
201
  }
200
202
  function createRenderEffect(fn, value, options) {
201
- updateComputation(createComputation(fn, value, false, STALE, options ));
203
+ const c = createComputation(fn, value, false, STALE, options );
204
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
202
205
  }
203
206
  function createEffect(fn, value, options) {
204
207
  runEffects = runUserEffects;
@@ -215,7 +218,10 @@ function createMemo(fn, value, options) {
215
218
  c.observers = null;
216
219
  c.observerSlots = null;
217
220
  c.comparator = options.equals || undefined;
218
- updateComputation(c);
221
+ if (Scheduler && Transition && Transition.running) {
222
+ c.tState = STALE;
223
+ Updates.push(c);
224
+ } else updateComputation(c);
219
225
  return readSignal.bind(c);
220
226
  }
221
227
  function createResource(source, fetcher, options) {
@@ -244,12 +250,7 @@ function createResource(source, fetcher, options) {
244
250
  dynamic = typeof source === "function";
245
251
  if (sharedConfig.context) {
246
252
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
247
- if (sharedConfig.context.loadResource) {
248
- initP = sharedConfig.context.loadResource(id);
249
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
250
- initP = sharedConfig.resources[id];
251
- delete sharedConfig.resources[id];
252
- }
253
+ if (sharedConfig.load) initP = sharedConfig.load(id);
253
254
  }
254
255
  function loadEnd(p, v, e) {
255
256
  if (pr === p) {
@@ -353,7 +354,7 @@ function createSelector(source, fn = equalFn, options) {
353
354
  const subs = new Map();
354
355
  const node = createComputation(p => {
355
356
  const v = source();
356
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
357
+ for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
357
358
  const l = subs.get(key);
358
359
  for (const c of l.values()) {
359
360
  c.state = STALE;
@@ -404,7 +405,8 @@ function untrack(fn) {
404
405
  Listener = listener;
405
406
  return result;
406
407
  }
407
- function on(deps, fn, options) {
408
+ function on(deps, fn,
409
+ options) {
408
410
  const isArray = Array.isArray(deps);
409
411
  let prevInput;
410
412
  let defer = options && options.defer;
@@ -706,7 +708,7 @@ function runTop(node) {
706
708
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
707
709
  const updates = Updates;
708
710
  Updates = null;
709
- lookDownstream(node);
711
+ lookDownstream(node, ancestors[0]);
710
712
  Updates = updates;
711
713
  }
712
714
  }
@@ -805,13 +807,15 @@ function runUserEffects(queue) {
805
807
  for (i = 0; i < userLength; i++) runTop(queue[i]);
806
808
  for (i = resume; i < queue.length; i++) runTop(queue[i]);
807
809
  }
808
- function lookDownstream(node) {
810
+ function lookDownstream(node, ignore) {
809
811
  node.state = 0;
810
812
  const runningTransition = Transition && Transition.running;
811
813
  for (let i = 0; i < node.sources.length; i += 1) {
812
814
  const source = node.sources[i];
813
815
  if (source.sources) {
814
- if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) runTop(source);else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source);
816
+ if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
817
+ if (source !== ignore) runTop(source);
818
+ } else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
815
819
  }
816
820
  }
817
821
  }
@@ -1232,7 +1236,7 @@ function lazy(fn) {
1232
1236
  let comp;
1233
1237
  const wrap = props => {
1234
1238
  const ctx = sharedConfig.context;
1235
- if (ctx && sharedConfig.resources) {
1239
+ if (ctx) {
1236
1240
  ctx.count++;
1237
1241
  const [s, set] = createSignal();
1238
1242
  fn().then(mod => {
@@ -1305,7 +1309,7 @@ function Switch(props) {
1305
1309
  }
1306
1310
  return [-1];
1307
1311
  }, undefined, {
1308
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1312
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1309
1313
  });
1310
1314
  return createMemo(() => {
1311
1315
  const [index, when, cond] = evalConditions();
@@ -1399,7 +1403,10 @@ function SuspenseList(props) {
1399
1403
  function Suspense(props) {
1400
1404
  let counter = 0,
1401
1405
  showContent,
1402
- showFallback;
1406
+ showFallback,
1407
+ ctx,
1408
+ waitingHydration,
1409
+ flicker;
1403
1410
  const [inFallback, setFallback] = createSignal(false),
1404
1411
  SuspenseContext = getSuspenseContext(),
1405
1412
  store = {
@@ -1414,6 +1421,24 @@ function Suspense(props) {
1414
1421
  resolved: false
1415
1422
  },
1416
1423
  owner = getOwner();
1424
+ if (sharedConfig.context && sharedConfig.load) {
1425
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1426
+ const p = sharedConfig.load(key);
1427
+ if (p) {
1428
+ const [s, set] = createSignal(undefined, {
1429
+ equals: false
1430
+ });
1431
+ flicker = s;
1432
+ p.then(() => {
1433
+ sharedConfig.gather(key);
1434
+ waitingHydration = true;
1435
+ setHydrateContext(ctx);
1436
+ set();
1437
+ setHydrateContext(undefined);
1438
+ waitingHydration = false;
1439
+ });
1440
+ }
1441
+ }
1417
1442
  const listContext = useContext(SuspenseListContext);
1418
1443
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1419
1444
  let dispose;
@@ -1421,28 +1446,35 @@ function Suspense(props) {
1421
1446
  return createComponent(SuspenseContext.Provider, {
1422
1447
  value: store,
1423
1448
  get children() {
1424
- const rendered = untrack(() => props.children);
1425
1449
  return createMemo(() => {
1426
- const inFallback = store.inFallback(),
1427
- visibleContent = showContent ? showContent() : true,
1428
- visibleFallback = showFallback ? showFallback() : true;
1429
- dispose && dispose();
1430
- if (!inFallback && visibleContent) {
1431
- store.resolved = true;
1432
- resumeEffects(store.effects);
1433
- return rendered;
1450
+ if (flicker) {
1451
+ ctx = sharedConfig.context;
1452
+ flicker();
1453
+ return flicker = undefined;
1434
1454
  }
1435
- if (!visibleFallback) return;
1436
- return createRoot(disposer => {
1437
- dispose = disposer;
1438
- return props.fallback;
1439
- }, owner);
1455
+ const rendered = untrack(() => props.children);
1456
+ return createMemo(() => {
1457
+ const inFallback = store.inFallback(),
1458
+ visibleContent = showContent ? showContent() : true,
1459
+ visibleFallback = showFallback ? showFallback() : true;
1460
+ dispose && dispose();
1461
+ if ((!inFallback || waitingHydration) && visibleContent) {
1462
+ store.resolved = true;
1463
+ resumeEffects(store.effects);
1464
+ return rendered;
1465
+ }
1466
+ if (!visibleFallback) return;
1467
+ return createRoot(disposer => {
1468
+ dispose = disposer;
1469
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1470
+ return props.fallback;
1471
+ }, owner);
1472
+ });
1440
1473
  });
1441
1474
  }
1442
1475
  });
1443
1476
  }
1444
1477
 
1445
- function awaitSuspense() {}
1446
1478
  exports.DEV = void 0;
1447
1479
  {
1448
1480
  exports.DEV = {
@@ -1465,7 +1497,6 @@ exports.Show = Show;
1465
1497
  exports.Suspense = Suspense;
1466
1498
  exports.SuspenseList = SuspenseList;
1467
1499
  exports.Switch = Switch;
1468
- exports.awaitSuspense = awaitSuspense;
1469
1500
  exports.batch = batch;
1470
1501
  exports.cancelCallback = cancelCallback;
1471
1502
  exports.children = children;
package/dist/dev.js CHANGED
@@ -183,18 +183,21 @@ function createSignal(value, options) {
183
183
  comparator: options.equals || undefined
184
184
  };
185
185
  if (!options.internal) s.name = registerGraph(options.name || hashValue(value), s);
186
- return [readSignal.bind(s), value => {
186
+ const setter = value => {
187
187
  if (typeof value === "function") {
188
188
  if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
189
189
  }
190
190
  return writeSignal(s, value);
191
- }];
191
+ };
192
+ return [readSignal.bind(s), setter];
192
193
  }
193
194
  function createComputed(fn, value, options) {
194
- updateComputation(createComputation(fn, value, true, STALE, options ));
195
+ const c = createComputation(fn, value, true, STALE, options );
196
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
195
197
  }
196
198
  function createRenderEffect(fn, value, options) {
197
- updateComputation(createComputation(fn, value, false, STALE, options ));
199
+ const c = createComputation(fn, value, false, STALE, options );
200
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
198
201
  }
199
202
  function createEffect(fn, value, options) {
200
203
  runEffects = runUserEffects;
@@ -211,7 +214,10 @@ function createMemo(fn, value, options) {
211
214
  c.observers = null;
212
215
  c.observerSlots = null;
213
216
  c.comparator = options.equals || undefined;
214
- updateComputation(c);
217
+ if (Scheduler && Transition && Transition.running) {
218
+ c.tState = STALE;
219
+ Updates.push(c);
220
+ } else updateComputation(c);
215
221
  return readSignal.bind(c);
216
222
  }
217
223
  function createResource(source, fetcher, options) {
@@ -240,12 +246,7 @@ function createResource(source, fetcher, options) {
240
246
  dynamic = typeof source === "function";
241
247
  if (sharedConfig.context) {
242
248
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
243
- if (sharedConfig.context.loadResource) {
244
- initP = sharedConfig.context.loadResource(id);
245
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
246
- initP = sharedConfig.resources[id];
247
- delete sharedConfig.resources[id];
248
- }
249
+ if (sharedConfig.load) initP = sharedConfig.load(id);
249
250
  }
250
251
  function loadEnd(p, v, e) {
251
252
  if (pr === p) {
@@ -349,7 +350,7 @@ function createSelector(source, fn = equalFn, options) {
349
350
  const subs = new Map();
350
351
  const node = createComputation(p => {
351
352
  const v = source();
352
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
353
+ for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
353
354
  const l = subs.get(key);
354
355
  for (const c of l.values()) {
355
356
  c.state = STALE;
@@ -400,7 +401,8 @@ function untrack(fn) {
400
401
  Listener = listener;
401
402
  return result;
402
403
  }
403
- function on(deps, fn, options) {
404
+ function on(deps, fn,
405
+ options) {
404
406
  const isArray = Array.isArray(deps);
405
407
  let prevInput;
406
408
  let defer = options && options.defer;
@@ -702,7 +704,7 @@ function runTop(node) {
702
704
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
703
705
  const updates = Updates;
704
706
  Updates = null;
705
- lookDownstream(node);
707
+ lookDownstream(node, ancestors[0]);
706
708
  Updates = updates;
707
709
  }
708
710
  }
@@ -801,13 +803,15 @@ function runUserEffects(queue) {
801
803
  for (i = 0; i < userLength; i++) runTop(queue[i]);
802
804
  for (i = resume; i < queue.length; i++) runTop(queue[i]);
803
805
  }
804
- function lookDownstream(node) {
806
+ function lookDownstream(node, ignore) {
805
807
  node.state = 0;
806
808
  const runningTransition = Transition && Transition.running;
807
809
  for (let i = 0; i < node.sources.length; i += 1) {
808
810
  const source = node.sources[i];
809
811
  if (source.sources) {
810
- if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) runTop(source);else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source);
812
+ if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
813
+ if (source !== ignore) runTop(source);
814
+ } else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
811
815
  }
812
816
  }
813
817
  }
@@ -1228,7 +1232,7 @@ function lazy(fn) {
1228
1232
  let comp;
1229
1233
  const wrap = props => {
1230
1234
  const ctx = sharedConfig.context;
1231
- if (ctx && sharedConfig.resources) {
1235
+ if (ctx) {
1232
1236
  ctx.count++;
1233
1237
  const [s, set] = createSignal();
1234
1238
  fn().then(mod => {
@@ -1301,7 +1305,7 @@ function Switch(props) {
1301
1305
  }
1302
1306
  return [-1];
1303
1307
  }, undefined, {
1304
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1308
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1305
1309
  });
1306
1310
  return createMemo(() => {
1307
1311
  const [index, when, cond] = evalConditions();
@@ -1395,7 +1399,10 @@ function SuspenseList(props) {
1395
1399
  function Suspense(props) {
1396
1400
  let counter = 0,
1397
1401
  showContent,
1398
- showFallback;
1402
+ showFallback,
1403
+ ctx,
1404
+ waitingHydration,
1405
+ flicker;
1399
1406
  const [inFallback, setFallback] = createSignal(false),
1400
1407
  SuspenseContext = getSuspenseContext(),
1401
1408
  store = {
@@ -1410,6 +1417,24 @@ function Suspense(props) {
1410
1417
  resolved: false
1411
1418
  },
1412
1419
  owner = getOwner();
1420
+ if (sharedConfig.context && sharedConfig.load) {
1421
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1422
+ const p = sharedConfig.load(key);
1423
+ if (p) {
1424
+ const [s, set] = createSignal(undefined, {
1425
+ equals: false
1426
+ });
1427
+ flicker = s;
1428
+ p.then(() => {
1429
+ sharedConfig.gather(key);
1430
+ waitingHydration = true;
1431
+ setHydrateContext(ctx);
1432
+ set();
1433
+ setHydrateContext(undefined);
1434
+ waitingHydration = false;
1435
+ });
1436
+ }
1437
+ }
1413
1438
  const listContext = useContext(SuspenseListContext);
1414
1439
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1415
1440
  let dispose;
@@ -1417,28 +1442,35 @@ function Suspense(props) {
1417
1442
  return createComponent(SuspenseContext.Provider, {
1418
1443
  value: store,
1419
1444
  get children() {
1420
- const rendered = untrack(() => props.children);
1421
1445
  return createMemo(() => {
1422
- const inFallback = store.inFallback(),
1423
- visibleContent = showContent ? showContent() : true,
1424
- visibleFallback = showFallback ? showFallback() : true;
1425
- dispose && dispose();
1426
- if (!inFallback && visibleContent) {
1427
- store.resolved = true;
1428
- resumeEffects(store.effects);
1429
- return rendered;
1446
+ if (flicker) {
1447
+ ctx = sharedConfig.context;
1448
+ flicker();
1449
+ return flicker = undefined;
1430
1450
  }
1431
- if (!visibleFallback) return;
1432
- return createRoot(disposer => {
1433
- dispose = disposer;
1434
- return props.fallback;
1435
- }, owner);
1451
+ const rendered = untrack(() => props.children);
1452
+ return createMemo(() => {
1453
+ const inFallback = store.inFallback(),
1454
+ visibleContent = showContent ? showContent() : true,
1455
+ visibleFallback = showFallback ? showFallback() : true;
1456
+ dispose && dispose();
1457
+ if ((!inFallback || waitingHydration) && visibleContent) {
1458
+ store.resolved = true;
1459
+ resumeEffects(store.effects);
1460
+ return rendered;
1461
+ }
1462
+ if (!visibleFallback) return;
1463
+ return createRoot(disposer => {
1464
+ dispose = disposer;
1465
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1466
+ return props.fallback;
1467
+ }, owner);
1468
+ });
1436
1469
  });
1437
1470
  }
1438
1471
  });
1439
1472
  }
1440
1473
 
1441
- function awaitSuspense() {}
1442
1474
  let DEV;
1443
1475
  {
1444
1476
  DEV = {
@@ -1452,4 +1484,4 @@ if (globalThis) {
1452
1484
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
1453
1485
  }
1454
1486
 
1455
- export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, awaitSuspense, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1487
+ export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
package/dist/server.cjs CHANGED
@@ -219,7 +219,7 @@ function createUniqueId() {
219
219
  return `${ctx.id}${ctx.count++}`;
220
220
  }
221
221
  function createComponent(Comp, props) {
222
- if (sharedConfig.context) {
222
+ if (sharedConfig.context && !sharedConfig.context.noHydrate) {
223
223
  const c = sharedConfig.context;
224
224
  setHydrateContext(nextHydrateContext());
225
225
  const r = Comp(props);
@@ -320,7 +320,7 @@ function createResource(fn, fetcher, options = {}) {
320
320
  const read = () => {
321
321
  if (resourceContext && p) resourceContext.push(p);
322
322
  const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
323
- if (sharedConfig.context.async && !resolved) {
323
+ if (!resolved) {
324
324
  const ctx = useContext(SuspenseContext);
325
325
  if (ctx) {
326
326
  ctx.resources.set(id, read);
@@ -332,7 +332,7 @@ function createResource(fn, fetcher, options = {}) {
332
332
  read.loading = false;
333
333
  function load() {
334
334
  const ctx = sharedConfig.context;
335
- if (!ctx.async && !ctx.streaming) return;
335
+ if (!ctx.async) return read.loading = true;
336
336
  if (ctx.resources && id in ctx.resources && ctx.resources[id].data) {
337
337
  value = ctx.resources[id].data;
338
338
  return;
@@ -349,15 +349,7 @@ function createResource(fn, fetcher, options = {}) {
349
349
  }
350
350
  read.loading = true;
351
351
  if ("then" in p) {
352
- if (ctx.writeResource) {
353
- ctx.writeResource(id, p);
354
- p.then(v => {
355
- value = v;
356
- read.loading = false;
357
- p = null;
358
- });
359
- return;
360
- }
352
+ if (ctx.writeResource) ctx.writeResource(id, p);
361
353
  p.then(res => {
362
354
  read.loading = false;
363
355
  ctx.resources[id].data = res;
@@ -392,7 +384,7 @@ function lazy(fn) {
392
384
  ctx.resources.set(id, track);
393
385
  contexts.add(ctx);
394
386
  }
395
- p.then(() => {
387
+ if (sharedConfig.context.async) p.then(() => {
396
388
  track.loading = false;
397
389
  notifySuspense(contexts);
398
390
  });
@@ -425,15 +417,10 @@ function useTransition() {
425
417
  function SuspenseList(props) {
426
418
  return props.children;
427
419
  }
428
- const SUSPENSE_GLOBAL = Symbol("suspense-global");
429
420
  function Suspense(props) {
430
421
  const ctx = sharedConfig.context;
431
- if (!ctx.async) return createComponent(() => {
432
- props.children;
433
- return props.fallback;
434
- }, {});
435
422
  const id = ctx.id + ctx.count;
436
- const done = ctx.async ? lookup(Owner, SUSPENSE_GLOBAL)(id) : () => {};
423
+ const done = ctx.async ? ctx.registerFragment(id) : () => {};
437
424
  const o = Owner;
438
425
  const value = ctx.suspense[id] || (ctx.suspense[id] = {
439
426
  resources: new Map(),
@@ -462,40 +449,23 @@ function Suspense(props) {
462
449
  done();
463
450
  return res;
464
451
  }
465
- return sharedConfig.context.async ? {
466
- t: `<#${id}#>`
467
- } : props.fallback;
468
- }
469
- const SUSPENSE_REPLACE = /<#([\d.]+)#>/;
470
- function awaitSuspense(fn) {
471
- return new Promise(resolve => {
472
- const registry = new Set();
473
- const cache = Object.create(null);
474
- const res = createMemo(() => {
475
- Owner.context = {
476
- [SUSPENSE_GLOBAL]: getCallback
477
- };
478
- return fn();
479
- });
480
- if (!registry.size) resolve(res());
481
- function getCallback(key) {
482
- registry.add(key);
483
- return value => {
484
- if (value) cache[key] = value;
485
- registry.delete(key);
486
- if (!registry.size) Promise.resolve().then(() => {
487
- let source = resolveSSRNode(res());
488
- let final = "";
489
- let match;
490
- while (match = source.match(SUSPENSE_REPLACE)) {
491
- final += source.substring(0, match.index);
492
- source = cache[match[1]] + source.substring(match.index + match[0].length);
493
- }
494
- resolve(final + source);
495
- });
452
+ if (sharedConfig.context.async) {
453
+ if (sharedConfig.context.streaming) {
454
+ setHydrateContext(undefined);
455
+ const res = {
456
+ t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
496
457
  };
458
+ setHydrateContext(ctx);
459
+ return res;
497
460
  }
461
+ return {
462
+ t: `<![${id}]>`
463
+ };
464
+ }
465
+ setHydrateContext({ ...ctx,
466
+ count: 0
498
467
  });
468
+ return createComponent(() => props.fallback, {});
499
469
  }
500
470
 
501
471
  exports.$PROXY = $PROXY;
@@ -508,7 +478,6 @@ exports.Show = Show;
508
478
  exports.Suspense = Suspense;
509
479
  exports.SuspenseList = SuspenseList;
510
480
  exports.Switch = Switch;
511
- exports.awaitSuspense = awaitSuspense;
512
481
  exports.batch = batch;
513
482
  exports.children = children;
514
483
  exports.createComponent = createComponent;
package/dist/server.js CHANGED
@@ -215,7 +215,7 @@ function createUniqueId() {
215
215
  return `${ctx.id}${ctx.count++}`;
216
216
  }
217
217
  function createComponent(Comp, props) {
218
- if (sharedConfig.context) {
218
+ if (sharedConfig.context && !sharedConfig.context.noHydrate) {
219
219
  const c = sharedConfig.context;
220
220
  setHydrateContext(nextHydrateContext());
221
221
  const r = Comp(props);
@@ -316,7 +316,7 @@ function createResource(fn, fetcher, options = {}) {
316
316
  const read = () => {
317
317
  if (resourceContext && p) resourceContext.push(p);
318
318
  const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
319
- if (sharedConfig.context.async && !resolved) {
319
+ if (!resolved) {
320
320
  const ctx = useContext(SuspenseContext);
321
321
  if (ctx) {
322
322
  ctx.resources.set(id, read);
@@ -328,7 +328,7 @@ function createResource(fn, fetcher, options = {}) {
328
328
  read.loading = false;
329
329
  function load() {
330
330
  const ctx = sharedConfig.context;
331
- if (!ctx.async && !ctx.streaming) return;
331
+ if (!ctx.async) return read.loading = true;
332
332
  if (ctx.resources && id in ctx.resources && ctx.resources[id].data) {
333
333
  value = ctx.resources[id].data;
334
334
  return;
@@ -345,15 +345,7 @@ function createResource(fn, fetcher, options = {}) {
345
345
  }
346
346
  read.loading = true;
347
347
  if ("then" in p) {
348
- if (ctx.writeResource) {
349
- ctx.writeResource(id, p);
350
- p.then(v => {
351
- value = v;
352
- read.loading = false;
353
- p = null;
354
- });
355
- return;
356
- }
348
+ if (ctx.writeResource) ctx.writeResource(id, p);
357
349
  p.then(res => {
358
350
  read.loading = false;
359
351
  ctx.resources[id].data = res;
@@ -388,7 +380,7 @@ function lazy(fn) {
388
380
  ctx.resources.set(id, track);
389
381
  contexts.add(ctx);
390
382
  }
391
- p.then(() => {
383
+ if (sharedConfig.context.async) p.then(() => {
392
384
  track.loading = false;
393
385
  notifySuspense(contexts);
394
386
  });
@@ -421,15 +413,10 @@ function useTransition() {
421
413
  function SuspenseList(props) {
422
414
  return props.children;
423
415
  }
424
- const SUSPENSE_GLOBAL = Symbol("suspense-global");
425
416
  function Suspense(props) {
426
417
  const ctx = sharedConfig.context;
427
- if (!ctx.async) return createComponent(() => {
428
- props.children;
429
- return props.fallback;
430
- }, {});
431
418
  const id = ctx.id + ctx.count;
432
- const done = ctx.async ? lookup(Owner, SUSPENSE_GLOBAL)(id) : () => {};
419
+ const done = ctx.async ? ctx.registerFragment(id) : () => {};
433
420
  const o = Owner;
434
421
  const value = ctx.suspense[id] || (ctx.suspense[id] = {
435
422
  resources: new Map(),
@@ -458,40 +445,23 @@ function Suspense(props) {
458
445
  done();
459
446
  return res;
460
447
  }
461
- return sharedConfig.context.async ? {
462
- t: `<#${id}#>`
463
- } : props.fallback;
464
- }
465
- const SUSPENSE_REPLACE = /<#([\d.]+)#>/;
466
- function awaitSuspense(fn) {
467
- return new Promise(resolve => {
468
- const registry = new Set();
469
- const cache = Object.create(null);
470
- const res = createMemo(() => {
471
- Owner.context = {
472
- [SUSPENSE_GLOBAL]: getCallback
473
- };
474
- return fn();
475
- });
476
- if (!registry.size) resolve(res());
477
- function getCallback(key) {
478
- registry.add(key);
479
- return value => {
480
- if (value) cache[key] = value;
481
- registry.delete(key);
482
- if (!registry.size) Promise.resolve().then(() => {
483
- let source = resolveSSRNode(res());
484
- let final = "";
485
- let match;
486
- while (match = source.match(SUSPENSE_REPLACE)) {
487
- final += source.substring(0, match.index);
488
- source = cache[match[1]] + source.substring(match.index + match[0].length);
489
- }
490
- resolve(final + source);
491
- });
448
+ if (sharedConfig.context.async) {
449
+ if (sharedConfig.context.streaming) {
450
+ setHydrateContext(undefined);
451
+ const res = {
452
+ t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
492
453
  };
454
+ setHydrateContext(ctx);
455
+ return res;
493
456
  }
457
+ return {
458
+ t: `<![${id}]>`
459
+ };
460
+ }
461
+ setHydrateContext({ ...ctx,
462
+ count: 0
494
463
  });
464
+ return createComponent(() => props.fallback, {});
495
465
  }
496
466
 
497
- export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, awaitSuspense, batch, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
467
+ export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };