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/solid.cjs CHANGED
@@ -184,18 +184,21 @@ function createSignal(value, options) {
184
184
  pending: NOTPENDING,
185
185
  comparator: options.equals || undefined
186
186
  };
187
- return [readSignal.bind(s), value => {
187
+ const setter = value => {
188
188
  if (typeof value === "function") {
189
189
  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);
190
190
  }
191
191
  return writeSignal(s, value);
192
- }];
192
+ };
193
+ return [readSignal.bind(s), setter];
193
194
  }
194
195
  function createComputed(fn, value, options) {
195
- updateComputation(createComputation(fn, value, true, STALE));
196
+ const c = createComputation(fn, value, true, STALE);
197
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
196
198
  }
197
199
  function createRenderEffect(fn, value, options) {
198
- updateComputation(createComputation(fn, value, false, STALE));
200
+ const c = createComputation(fn, value, false, STALE);
201
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
199
202
  }
200
203
  function createEffect(fn, value, options) {
201
204
  runEffects = runUserEffects;
@@ -212,7 +215,10 @@ function createMemo(fn, value, options) {
212
215
  c.observers = null;
213
216
  c.observerSlots = null;
214
217
  c.comparator = options.equals || undefined;
215
- updateComputation(c);
218
+ if (Scheduler && Transition && Transition.running) {
219
+ c.tState = STALE;
220
+ Updates.push(c);
221
+ } else updateComputation(c);
216
222
  return readSignal.bind(c);
217
223
  }
218
224
  function createResource(source, fetcher, options) {
@@ -241,12 +247,7 @@ function createResource(source, fetcher, options) {
241
247
  dynamic = typeof source === "function";
242
248
  if (sharedConfig.context) {
243
249
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
244
- if (sharedConfig.context.loadResource) {
245
- initP = sharedConfig.context.loadResource(id);
246
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
247
- initP = sharedConfig.resources[id];
248
- delete sharedConfig.resources[id];
249
- }
250
+ if (sharedConfig.load) initP = sharedConfig.load(id);
250
251
  }
251
252
  function loadEnd(p, v, e) {
252
253
  if (pr === p) {
@@ -350,7 +351,7 @@ function createSelector(source, fn = equalFn, options) {
350
351
  const subs = new Map();
351
352
  const node = createComputation(p => {
352
353
  const v = source();
353
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
354
+ for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
354
355
  const l = subs.get(key);
355
356
  for (const c of l.values()) {
356
357
  c.state = STALE;
@@ -401,7 +402,8 @@ function untrack(fn) {
401
402
  Listener = listener;
402
403
  return result;
403
404
  }
404
- function on(deps, fn, options) {
405
+ function on(deps, fn,
406
+ options) {
405
407
  const isArray = Array.isArray(deps);
406
408
  let prevInput;
407
409
  let defer = options && options.defer;
@@ -654,7 +656,7 @@ function runTop(node) {
654
656
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
655
657
  const updates = Updates;
656
658
  Updates = null;
657
- lookDownstream(node);
659
+ lookDownstream(node, ancestors[0]);
658
660
  Updates = updates;
659
661
  }
660
662
  }
@@ -752,13 +754,15 @@ function runUserEffects(queue) {
752
754
  for (i = 0; i < userLength; i++) runTop(queue[i]);
753
755
  for (i = resume; i < queue.length; i++) runTop(queue[i]);
754
756
  }
755
- function lookDownstream(node) {
757
+ function lookDownstream(node, ignore) {
756
758
  node.state = 0;
757
759
  const runningTransition = Transition && Transition.running;
758
760
  for (let i = 0; i < node.sources.length; i += 1) {
759
761
  const source = node.sources[i];
760
762
  if (source.sources) {
761
- if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) runTop(source);else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source);
763
+ if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
764
+ if (source !== ignore) runTop(source);
765
+ } else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
762
766
  }
763
767
  }
764
768
  }
@@ -1156,7 +1160,7 @@ function lazy(fn) {
1156
1160
  let comp;
1157
1161
  const wrap = props => {
1158
1162
  const ctx = sharedConfig.context;
1159
- if (ctx && sharedConfig.resources) {
1163
+ if (ctx) {
1160
1164
  ctx.count++;
1161
1165
  const [s, set] = createSignal();
1162
1166
  fn().then(mod => {
@@ -1229,7 +1233,7 @@ function Switch(props) {
1229
1233
  }
1230
1234
  return [-1];
1231
1235
  }, undefined, {
1232
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1236
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1233
1237
  });
1234
1238
  return createMemo(() => {
1235
1239
  const [index, when, cond] = evalConditions();
@@ -1323,7 +1327,10 @@ function SuspenseList(props) {
1323
1327
  function Suspense(props) {
1324
1328
  let counter = 0,
1325
1329
  showContent,
1326
- showFallback;
1330
+ showFallback,
1331
+ ctx,
1332
+ waitingHydration,
1333
+ flicker;
1327
1334
  const [inFallback, setFallback] = createSignal(false),
1328
1335
  SuspenseContext = getSuspenseContext(),
1329
1336
  store = {
@@ -1338,6 +1345,24 @@ function Suspense(props) {
1338
1345
  resolved: false
1339
1346
  },
1340
1347
  owner = getOwner();
1348
+ if (sharedConfig.context && sharedConfig.load) {
1349
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1350
+ const p = sharedConfig.load(key);
1351
+ if (p) {
1352
+ const [s, set] = createSignal(undefined, {
1353
+ equals: false
1354
+ });
1355
+ flicker = s;
1356
+ p.then(() => {
1357
+ sharedConfig.gather(key);
1358
+ waitingHydration = true;
1359
+ setHydrateContext(ctx);
1360
+ set();
1361
+ setHydrateContext(undefined);
1362
+ waitingHydration = false;
1363
+ });
1364
+ }
1365
+ }
1341
1366
  const listContext = useContext(SuspenseListContext);
1342
1367
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1343
1368
  let dispose;
@@ -1345,28 +1370,35 @@ function Suspense(props) {
1345
1370
  return createComponent(SuspenseContext.Provider, {
1346
1371
  value: store,
1347
1372
  get children() {
1348
- const rendered = untrack(() => props.children);
1349
1373
  return createMemo(() => {
1350
- const inFallback = store.inFallback(),
1351
- visibleContent = showContent ? showContent() : true,
1352
- visibleFallback = showFallback ? showFallback() : true;
1353
- dispose && dispose();
1354
- if (!inFallback && visibleContent) {
1355
- store.resolved = true;
1356
- resumeEffects(store.effects);
1357
- return rendered;
1374
+ if (flicker) {
1375
+ ctx = sharedConfig.context;
1376
+ flicker();
1377
+ return flicker = undefined;
1358
1378
  }
1359
- if (!visibleFallback) return;
1360
- return createRoot(disposer => {
1361
- dispose = disposer;
1362
- return props.fallback;
1363
- }, owner);
1379
+ const rendered = untrack(() => props.children);
1380
+ return createMemo(() => {
1381
+ const inFallback = store.inFallback(),
1382
+ visibleContent = showContent ? showContent() : true,
1383
+ visibleFallback = showFallback ? showFallback() : true;
1384
+ dispose && dispose();
1385
+ if ((!inFallback || waitingHydration) && visibleContent) {
1386
+ store.resolved = true;
1387
+ resumeEffects(store.effects);
1388
+ return rendered;
1389
+ }
1390
+ if (!visibleFallback) return;
1391
+ return createRoot(disposer => {
1392
+ dispose = disposer;
1393
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1394
+ return props.fallback;
1395
+ }, owner);
1396
+ });
1364
1397
  });
1365
1398
  }
1366
1399
  });
1367
1400
  }
1368
1401
 
1369
- function awaitSuspense() {}
1370
1402
  let DEV;
1371
1403
 
1372
1404
  exports.$PROXY = $PROXY;
@@ -1379,7 +1411,6 @@ exports.Show = Show;
1379
1411
  exports.Suspense = Suspense;
1380
1412
  exports.SuspenseList = SuspenseList;
1381
1413
  exports.Switch = Switch;
1382
- exports.awaitSuspense = awaitSuspense;
1383
1414
  exports.batch = batch;
1384
1415
  exports.cancelCallback = cancelCallback;
1385
1416
  exports.children = children;
package/dist/solid.js CHANGED
@@ -180,18 +180,21 @@ function createSignal(value, options) {
180
180
  pending: NOTPENDING,
181
181
  comparator: options.equals || undefined
182
182
  };
183
- return [readSignal.bind(s), value => {
183
+ const setter = value => {
184
184
  if (typeof value === "function") {
185
185
  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);
186
186
  }
187
187
  return writeSignal(s, value);
188
- }];
188
+ };
189
+ return [readSignal.bind(s), setter];
189
190
  }
190
191
  function createComputed(fn, value, options) {
191
- updateComputation(createComputation(fn, value, true, STALE));
192
+ const c = createComputation(fn, value, true, STALE);
193
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
192
194
  }
193
195
  function createRenderEffect(fn, value, options) {
194
- updateComputation(createComputation(fn, value, false, STALE));
196
+ const c = createComputation(fn, value, false, STALE);
197
+ if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
195
198
  }
196
199
  function createEffect(fn, value, options) {
197
200
  runEffects = runUserEffects;
@@ -208,7 +211,10 @@ function createMemo(fn, value, options) {
208
211
  c.observers = null;
209
212
  c.observerSlots = null;
210
213
  c.comparator = options.equals || undefined;
211
- updateComputation(c);
214
+ if (Scheduler && Transition && Transition.running) {
215
+ c.tState = STALE;
216
+ Updates.push(c);
217
+ } else updateComputation(c);
212
218
  return readSignal.bind(c);
213
219
  }
214
220
  function createResource(source, fetcher, options) {
@@ -237,12 +243,7 @@ function createResource(source, fetcher, options) {
237
243
  dynamic = typeof source === "function";
238
244
  if (sharedConfig.context) {
239
245
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
240
- if (sharedConfig.context.loadResource) {
241
- initP = sharedConfig.context.loadResource(id);
242
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
243
- initP = sharedConfig.resources[id];
244
- delete sharedConfig.resources[id];
245
- }
246
+ if (sharedConfig.load) initP = sharedConfig.load(id);
246
247
  }
247
248
  function loadEnd(p, v, e) {
248
249
  if (pr === p) {
@@ -346,7 +347,7 @@ function createSelector(source, fn = equalFn, options) {
346
347
  const subs = new Map();
347
348
  const node = createComputation(p => {
348
349
  const v = source();
349
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
350
+ for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
350
351
  const l = subs.get(key);
351
352
  for (const c of l.values()) {
352
353
  c.state = STALE;
@@ -397,7 +398,8 @@ function untrack(fn) {
397
398
  Listener = listener;
398
399
  return result;
399
400
  }
400
- function on(deps, fn, options) {
401
+ function on(deps, fn,
402
+ options) {
401
403
  const isArray = Array.isArray(deps);
402
404
  let prevInput;
403
405
  let defer = options && options.defer;
@@ -650,7 +652,7 @@ function runTop(node) {
650
652
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
651
653
  const updates = Updates;
652
654
  Updates = null;
653
- lookDownstream(node);
655
+ lookDownstream(node, ancestors[0]);
654
656
  Updates = updates;
655
657
  }
656
658
  }
@@ -748,13 +750,15 @@ function runUserEffects(queue) {
748
750
  for (i = 0; i < userLength; i++) runTop(queue[i]);
749
751
  for (i = resume; i < queue.length; i++) runTop(queue[i]);
750
752
  }
751
- function lookDownstream(node) {
753
+ function lookDownstream(node, ignore) {
752
754
  node.state = 0;
753
755
  const runningTransition = Transition && Transition.running;
754
756
  for (let i = 0; i < node.sources.length; i += 1) {
755
757
  const source = node.sources[i];
756
758
  if (source.sources) {
757
- if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) runTop(source);else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source);
759
+ if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
760
+ if (source !== ignore) runTop(source);
761
+ } else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
758
762
  }
759
763
  }
760
764
  }
@@ -1152,7 +1156,7 @@ function lazy(fn) {
1152
1156
  let comp;
1153
1157
  const wrap = props => {
1154
1158
  const ctx = sharedConfig.context;
1155
- if (ctx && sharedConfig.resources) {
1159
+ if (ctx) {
1156
1160
  ctx.count++;
1157
1161
  const [s, set] = createSignal();
1158
1162
  fn().then(mod => {
@@ -1225,7 +1229,7 @@ function Switch(props) {
1225
1229
  }
1226
1230
  return [-1];
1227
1231
  }, undefined, {
1228
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1232
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1229
1233
  });
1230
1234
  return createMemo(() => {
1231
1235
  const [index, when, cond] = evalConditions();
@@ -1319,7 +1323,10 @@ function SuspenseList(props) {
1319
1323
  function Suspense(props) {
1320
1324
  let counter = 0,
1321
1325
  showContent,
1322
- showFallback;
1326
+ showFallback,
1327
+ ctx,
1328
+ waitingHydration,
1329
+ flicker;
1323
1330
  const [inFallback, setFallback] = createSignal(false),
1324
1331
  SuspenseContext = getSuspenseContext(),
1325
1332
  store = {
@@ -1334,6 +1341,24 @@ function Suspense(props) {
1334
1341
  resolved: false
1335
1342
  },
1336
1343
  owner = getOwner();
1344
+ if (sharedConfig.context && sharedConfig.load) {
1345
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1346
+ const p = sharedConfig.load(key);
1347
+ if (p) {
1348
+ const [s, set] = createSignal(undefined, {
1349
+ equals: false
1350
+ });
1351
+ flicker = s;
1352
+ p.then(() => {
1353
+ sharedConfig.gather(key);
1354
+ waitingHydration = true;
1355
+ setHydrateContext(ctx);
1356
+ set();
1357
+ setHydrateContext(undefined);
1358
+ waitingHydration = false;
1359
+ });
1360
+ }
1361
+ }
1337
1362
  const listContext = useContext(SuspenseListContext);
1338
1363
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1339
1364
  let dispose;
@@ -1341,28 +1366,35 @@ function Suspense(props) {
1341
1366
  return createComponent(SuspenseContext.Provider, {
1342
1367
  value: store,
1343
1368
  get children() {
1344
- const rendered = untrack(() => props.children);
1345
1369
  return createMemo(() => {
1346
- const inFallback = store.inFallback(),
1347
- visibleContent = showContent ? showContent() : true,
1348
- visibleFallback = showFallback ? showFallback() : true;
1349
- dispose && dispose();
1350
- if (!inFallback && visibleContent) {
1351
- store.resolved = true;
1352
- resumeEffects(store.effects);
1353
- return rendered;
1370
+ if (flicker) {
1371
+ ctx = sharedConfig.context;
1372
+ flicker();
1373
+ return flicker = undefined;
1354
1374
  }
1355
- if (!visibleFallback) return;
1356
- return createRoot(disposer => {
1357
- dispose = disposer;
1358
- return props.fallback;
1359
- }, owner);
1375
+ const rendered = untrack(() => props.children);
1376
+ return createMemo(() => {
1377
+ const inFallback = store.inFallback(),
1378
+ visibleContent = showContent ? showContent() : true,
1379
+ visibleFallback = showFallback ? showFallback() : true;
1380
+ dispose && dispose();
1381
+ if ((!inFallback || waitingHydration) && visibleContent) {
1382
+ store.resolved = true;
1383
+ resumeEffects(store.effects);
1384
+ return rendered;
1385
+ }
1386
+ if (!visibleFallback) return;
1387
+ return createRoot(disposer => {
1388
+ dispose = disposer;
1389
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1390
+ return props.fallback;
1391
+ }, owner);
1392
+ });
1360
1393
  });
1361
1394
  }
1362
1395
  });
1363
1396
  }
1364
1397
 
1365
- function awaitSuspense() {}
1366
1398
  let DEV;
1367
1399
 
1368
- 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 };
1400
+ 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.2.4",
4
+ "version": "1.3.0-beta.2",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/solidjs/solid#readme",
@@ -132,5 +132,5 @@
132
132
  "compiler",
133
133
  "performance"
134
134
  ],
135
- "gitHead": "2866e83def4f3a02c305277fa8f589e355ab8952"
135
+ "gitHead": "afe407af6463d4956c2c283370895b4d02b205e8"
136
136
  }
package/types/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from "./render";
7
7
  import type { JSX } from "./jsx";
8
8
  declare type JSXElement = JSX.Element;
9
9
  export type { JSXElement, JSX };
10
- export declare function awaitSuspense(): void;
11
10
  import { writeSignal, serializeGraph, registerGraph, hashValue } from "./reactive/signal";
12
11
  declare let DEV: {
13
12
  writeSignal: typeof writeSignal;