solid-js 1.3.0-beta.7 → 1.3.0-rc.1
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 +45 -36
- package/dist/dev.js +45 -37
- package/dist/server.cjs +10 -10
- package/dist/server.js +10 -10
- package/dist/solid.cjs +45 -36
- package/dist/solid.js +45 -37
- package/package.json +2 -2
- package/types/index.d.ts +2 -2
- package/types/reactive/signal.d.ts +15 -4
- package/types/server/rendering.d.ts +1 -1
- package/web/dist/dev.cjs +1 -1
- package/web/dist/dev.js +1 -1
- package/web/dist/server.cjs +21 -20
- package/web/dist/server.js +21 -20
- package/web/dist/web.cjs +1 -1
- package/web/dist/web.js +1 -1
- package/web/types/server-mock.d.ts +0 -3
package/dist/dev.cjs
CHANGED
|
@@ -236,6 +236,9 @@ function createResource(source, fetcher, options) {
|
|
|
236
236
|
fetcher = source;
|
|
237
237
|
source = true;
|
|
238
238
|
}
|
|
239
|
+
Resources || (Resources = new Set());
|
|
240
|
+
Resources.add(load);
|
|
241
|
+
onCleanup(() => Resources.delete(load));
|
|
239
242
|
const contexts = new Set(),
|
|
240
243
|
[s, set] = createSignal((options || {}).initialValue),
|
|
241
244
|
[track, trigger] = createSignal(undefined, {
|
|
@@ -247,13 +250,10 @@ function createResource(source, fetcher, options) {
|
|
|
247
250
|
pr = null,
|
|
248
251
|
initP = null,
|
|
249
252
|
id = null,
|
|
250
|
-
ctx,
|
|
251
253
|
loadedUnderTransition = false,
|
|
252
254
|
dynamic = typeof source === "function";
|
|
253
255
|
if (sharedConfig.context) {
|
|
254
256
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
255
|
-
ctx = { ...sharedConfig.context
|
|
256
|
-
};
|
|
257
257
|
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
258
258
|
}
|
|
259
259
|
function loadEnd(p, v, e) {
|
|
@@ -271,14 +271,7 @@ function createResource(source, fetcher, options) {
|
|
|
271
271
|
}
|
|
272
272
|
completeLoad(v);
|
|
273
273
|
}, false);
|
|
274
|
-
} else
|
|
275
|
-
if (p === initP) setHydrateContext(ctx);
|
|
276
|
-
completeLoad(v);
|
|
277
|
-
if (p === initP) {
|
|
278
|
-
initP = null;
|
|
279
|
-
setHydrateContext();
|
|
280
|
-
}
|
|
281
|
-
}
|
|
274
|
+
} else completeLoad(v);
|
|
282
275
|
}
|
|
283
276
|
return v;
|
|
284
277
|
}
|
|
@@ -307,7 +300,7 @@ function createResource(source, fetcher, options) {
|
|
|
307
300
|
}
|
|
308
301
|
return v;
|
|
309
302
|
}
|
|
310
|
-
function load() {
|
|
303
|
+
function load(refetching = true) {
|
|
311
304
|
setError(err = undefined);
|
|
312
305
|
const lookup = dynamic ? source() : source;
|
|
313
306
|
loadedUnderTransition = Transition && Transition.running;
|
|
@@ -316,7 +309,11 @@ function createResource(source, fetcher, options) {
|
|
|
316
309
|
return;
|
|
317
310
|
}
|
|
318
311
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
319
|
-
const p =
|
|
312
|
+
const p = initP || untrack(() => fetcher(lookup, {
|
|
313
|
+
value: s(),
|
|
314
|
+
refetching
|
|
315
|
+
}));
|
|
316
|
+
initP = null;
|
|
320
317
|
if (typeof p !== "object" || !("then" in p)) {
|
|
321
318
|
loadEnd(pr, p);
|
|
322
319
|
return;
|
|
@@ -340,12 +337,16 @@ function createResource(source, fetcher, options) {
|
|
|
340
337
|
}
|
|
341
338
|
}
|
|
342
339
|
});
|
|
343
|
-
if (dynamic) createComputed(load);else load();
|
|
340
|
+
if (dynamic) createComputed(() => load(false));else load(false);
|
|
344
341
|
return [read, {
|
|
345
342
|
refetch: load,
|
|
346
343
|
mutate: set
|
|
347
344
|
}];
|
|
348
345
|
}
|
|
346
|
+
let Resources;
|
|
347
|
+
function refetchResources(info) {
|
|
348
|
+
Resources && Resources.forEach(fn => fn(info));
|
|
349
|
+
}
|
|
349
350
|
function createDeferred(source, options) {
|
|
350
351
|
let t,
|
|
351
352
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -1294,7 +1295,9 @@ function lazy(fn) {
|
|
|
1294
1295
|
});
|
|
1295
1296
|
comp = s;
|
|
1296
1297
|
} else if (!comp) {
|
|
1297
|
-
const [s] = createResource((
|
|
1298
|
+
const [s] = createResource((_, {
|
|
1299
|
+
value
|
|
1300
|
+
}) => value || (p || (p = fn())).then(mod => mod.default));
|
|
1298
1301
|
comp = s;
|
|
1299
1302
|
} else {
|
|
1300
1303
|
const c = comp();
|
|
@@ -1457,7 +1460,7 @@ function Suspense(props) {
|
|
|
1457
1460
|
showContent,
|
|
1458
1461
|
showFallback,
|
|
1459
1462
|
ctx,
|
|
1460
|
-
|
|
1463
|
+
p,
|
|
1461
1464
|
flicker,
|
|
1462
1465
|
error;
|
|
1463
1466
|
const [inFallback, setFallback] = createSignal(false),
|
|
@@ -1476,21 +1479,22 @@ function Suspense(props) {
|
|
|
1476
1479
|
owner = getOwner();
|
|
1477
1480
|
if (sharedConfig.context) {
|
|
1478
1481
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1479
|
-
|
|
1482
|
+
p = sharedConfig.load(key);
|
|
1480
1483
|
if (p) {
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1484
|
+
if (typeof p !== "object" || !("then" in p)) error = p;else {
|
|
1485
|
+
const [s, set] = createSignal(undefined, {
|
|
1486
|
+
equals: false
|
|
1487
|
+
});
|
|
1488
|
+
flicker = s;
|
|
1489
|
+
p.then(err => {
|
|
1490
|
+
if (error = err) return set();
|
|
1491
|
+
sharedConfig.gather(key);
|
|
1492
|
+
setHydrateContext(ctx);
|
|
1493
|
+
set();
|
|
1494
|
+
setHydrateContext();
|
|
1495
|
+
p = undefined;
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1494
1498
|
}
|
|
1495
1499
|
}
|
|
1496
1500
|
const listContext = useContext(SuspenseListContext);
|
|
@@ -1502,18 +1506,19 @@ function Suspense(props) {
|
|
|
1502
1506
|
get children() {
|
|
1503
1507
|
return createMemo(() => {
|
|
1504
1508
|
if (error) throw error;
|
|
1509
|
+
ctx = sharedConfig.context;
|
|
1505
1510
|
if (flicker) {
|
|
1506
|
-
ctx = sharedConfig.context;
|
|
1507
1511
|
flicker();
|
|
1508
1512
|
return flicker = undefined;
|
|
1509
1513
|
}
|
|
1514
|
+
if (ctx && p === undefined) setHydrateContext();
|
|
1510
1515
|
const rendered = untrack(() => props.children);
|
|
1511
1516
|
return createMemo(() => {
|
|
1512
1517
|
const inFallback = store.inFallback(),
|
|
1513
1518
|
visibleContent = showContent ? showContent() : true,
|
|
1514
1519
|
visibleFallback = showFallback ? showFallback() : true;
|
|
1515
1520
|
dispose && dispose();
|
|
1516
|
-
if ((!inFallback ||
|
|
1521
|
+
if ((!inFallback || p !== undefined) && visibleContent) {
|
|
1517
1522
|
store.resolved = true;
|
|
1518
1523
|
resumeEffects(store.effects);
|
|
1519
1524
|
return rendered;
|
|
@@ -1521,10 +1526,13 @@ function Suspense(props) {
|
|
|
1521
1526
|
if (!visibleFallback) return;
|
|
1522
1527
|
return createRoot(disposer => {
|
|
1523
1528
|
dispose = disposer;
|
|
1524
|
-
if (
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1529
|
+
if (ctx) {
|
|
1530
|
+
setHydrateContext({
|
|
1531
|
+
id: ctx.id + "f",
|
|
1532
|
+
count: 0
|
|
1533
|
+
});
|
|
1534
|
+
ctx = undefined;
|
|
1535
|
+
}
|
|
1528
1536
|
return props.fallback;
|
|
1529
1537
|
}, owner);
|
|
1530
1538
|
});
|
|
@@ -1586,6 +1594,7 @@ exports.on = on;
|
|
|
1586
1594
|
exports.onCleanup = onCleanup;
|
|
1587
1595
|
exports.onError = onError;
|
|
1588
1596
|
exports.onMount = onMount;
|
|
1597
|
+
exports.refetchResources = refetchResources;
|
|
1589
1598
|
exports.requestCallback = requestCallback;
|
|
1590
1599
|
exports.runWithOwner = runWithOwner;
|
|
1591
1600
|
exports.sharedConfig = sharedConfig;
|
package/dist/dev.js
CHANGED
|
@@ -232,6 +232,9 @@ function createResource(source, fetcher, options) {
|
|
|
232
232
|
fetcher = source;
|
|
233
233
|
source = true;
|
|
234
234
|
}
|
|
235
|
+
Resources || (Resources = new Set());
|
|
236
|
+
Resources.add(load);
|
|
237
|
+
onCleanup(() => Resources.delete(load));
|
|
235
238
|
const contexts = new Set(),
|
|
236
239
|
[s, set] = createSignal((options || {}).initialValue),
|
|
237
240
|
[track, trigger] = createSignal(undefined, {
|
|
@@ -243,13 +246,10 @@ function createResource(source, fetcher, options) {
|
|
|
243
246
|
pr = null,
|
|
244
247
|
initP = null,
|
|
245
248
|
id = null,
|
|
246
|
-
ctx,
|
|
247
249
|
loadedUnderTransition = false,
|
|
248
250
|
dynamic = typeof source === "function";
|
|
249
251
|
if (sharedConfig.context) {
|
|
250
252
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
251
|
-
ctx = { ...sharedConfig.context
|
|
252
|
-
};
|
|
253
253
|
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
254
254
|
}
|
|
255
255
|
function loadEnd(p, v, e) {
|
|
@@ -267,14 +267,7 @@ function createResource(source, fetcher, options) {
|
|
|
267
267
|
}
|
|
268
268
|
completeLoad(v);
|
|
269
269
|
}, false);
|
|
270
|
-
} else
|
|
271
|
-
if (p === initP) setHydrateContext(ctx);
|
|
272
|
-
completeLoad(v);
|
|
273
|
-
if (p === initP) {
|
|
274
|
-
initP = null;
|
|
275
|
-
setHydrateContext();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
270
|
+
} else completeLoad(v);
|
|
278
271
|
}
|
|
279
272
|
return v;
|
|
280
273
|
}
|
|
@@ -303,7 +296,7 @@ function createResource(source, fetcher, options) {
|
|
|
303
296
|
}
|
|
304
297
|
return v;
|
|
305
298
|
}
|
|
306
|
-
function load() {
|
|
299
|
+
function load(refetching = true) {
|
|
307
300
|
setError(err = undefined);
|
|
308
301
|
const lookup = dynamic ? source() : source;
|
|
309
302
|
loadedUnderTransition = Transition && Transition.running;
|
|
@@ -312,7 +305,11 @@ function createResource(source, fetcher, options) {
|
|
|
312
305
|
return;
|
|
313
306
|
}
|
|
314
307
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
315
|
-
const p =
|
|
308
|
+
const p = initP || untrack(() => fetcher(lookup, {
|
|
309
|
+
value: s(),
|
|
310
|
+
refetching
|
|
311
|
+
}));
|
|
312
|
+
initP = null;
|
|
316
313
|
if (typeof p !== "object" || !("then" in p)) {
|
|
317
314
|
loadEnd(pr, p);
|
|
318
315
|
return;
|
|
@@ -336,12 +333,16 @@ function createResource(source, fetcher, options) {
|
|
|
336
333
|
}
|
|
337
334
|
}
|
|
338
335
|
});
|
|
339
|
-
if (dynamic) createComputed(load);else load();
|
|
336
|
+
if (dynamic) createComputed(() => load(false));else load(false);
|
|
340
337
|
return [read, {
|
|
341
338
|
refetch: load,
|
|
342
339
|
mutate: set
|
|
343
340
|
}];
|
|
344
341
|
}
|
|
342
|
+
let Resources;
|
|
343
|
+
function refetchResources(info) {
|
|
344
|
+
Resources && Resources.forEach(fn => fn(info));
|
|
345
|
+
}
|
|
345
346
|
function createDeferred(source, options) {
|
|
346
347
|
let t,
|
|
347
348
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -1290,7 +1291,9 @@ function lazy(fn) {
|
|
|
1290
1291
|
});
|
|
1291
1292
|
comp = s;
|
|
1292
1293
|
} else if (!comp) {
|
|
1293
|
-
const [s] = createResource((
|
|
1294
|
+
const [s] = createResource((_, {
|
|
1295
|
+
value
|
|
1296
|
+
}) => value || (p || (p = fn())).then(mod => mod.default));
|
|
1294
1297
|
comp = s;
|
|
1295
1298
|
} else {
|
|
1296
1299
|
const c = comp();
|
|
@@ -1453,7 +1456,7 @@ function Suspense(props) {
|
|
|
1453
1456
|
showContent,
|
|
1454
1457
|
showFallback,
|
|
1455
1458
|
ctx,
|
|
1456
|
-
|
|
1459
|
+
p,
|
|
1457
1460
|
flicker,
|
|
1458
1461
|
error;
|
|
1459
1462
|
const [inFallback, setFallback] = createSignal(false),
|
|
@@ -1472,21 +1475,22 @@ function Suspense(props) {
|
|
|
1472
1475
|
owner = getOwner();
|
|
1473
1476
|
if (sharedConfig.context) {
|
|
1474
1477
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1475
|
-
|
|
1478
|
+
p = sharedConfig.load(key);
|
|
1476
1479
|
if (p) {
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1480
|
+
if (typeof p !== "object" || !("then" in p)) error = p;else {
|
|
1481
|
+
const [s, set] = createSignal(undefined, {
|
|
1482
|
+
equals: false
|
|
1483
|
+
});
|
|
1484
|
+
flicker = s;
|
|
1485
|
+
p.then(err => {
|
|
1486
|
+
if (error = err) return set();
|
|
1487
|
+
sharedConfig.gather(key);
|
|
1488
|
+
setHydrateContext(ctx);
|
|
1489
|
+
set();
|
|
1490
|
+
setHydrateContext();
|
|
1491
|
+
p = undefined;
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1490
1494
|
}
|
|
1491
1495
|
}
|
|
1492
1496
|
const listContext = useContext(SuspenseListContext);
|
|
@@ -1498,18 +1502,19 @@ function Suspense(props) {
|
|
|
1498
1502
|
get children() {
|
|
1499
1503
|
return createMemo(() => {
|
|
1500
1504
|
if (error) throw error;
|
|
1505
|
+
ctx = sharedConfig.context;
|
|
1501
1506
|
if (flicker) {
|
|
1502
|
-
ctx = sharedConfig.context;
|
|
1503
1507
|
flicker();
|
|
1504
1508
|
return flicker = undefined;
|
|
1505
1509
|
}
|
|
1510
|
+
if (ctx && p === undefined) setHydrateContext();
|
|
1506
1511
|
const rendered = untrack(() => props.children);
|
|
1507
1512
|
return createMemo(() => {
|
|
1508
1513
|
const inFallback = store.inFallback(),
|
|
1509
1514
|
visibleContent = showContent ? showContent() : true,
|
|
1510
1515
|
visibleFallback = showFallback ? showFallback() : true;
|
|
1511
1516
|
dispose && dispose();
|
|
1512
|
-
if ((!inFallback ||
|
|
1517
|
+
if ((!inFallback || p !== undefined) && visibleContent) {
|
|
1513
1518
|
store.resolved = true;
|
|
1514
1519
|
resumeEffects(store.effects);
|
|
1515
1520
|
return rendered;
|
|
@@ -1517,10 +1522,13 @@ function Suspense(props) {
|
|
|
1517
1522
|
if (!visibleFallback) return;
|
|
1518
1523
|
return createRoot(disposer => {
|
|
1519
1524
|
dispose = disposer;
|
|
1520
|
-
if (
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1525
|
+
if (ctx) {
|
|
1526
|
+
setHydrateContext({
|
|
1527
|
+
id: ctx.id + "f",
|
|
1528
|
+
count: 0
|
|
1529
|
+
});
|
|
1530
|
+
ctx = undefined;
|
|
1531
|
+
}
|
|
1524
1532
|
return props.fallback;
|
|
1525
1533
|
}, owner);
|
|
1526
1534
|
});
|
|
@@ -1542,4 +1550,4 @@ if (globalThis) {
|
|
|
1542
1550
|
if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
|
|
1543
1551
|
}
|
|
1544
1552
|
|
|
1545
|
-
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, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
|
|
1553
|
+
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, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, refetchResources, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
|
package/dist/server.cjs
CHANGED
|
@@ -461,7 +461,6 @@ function Suspense(props) {
|
|
|
461
461
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
462
462
|
resources: new Map(),
|
|
463
463
|
completed: () => {
|
|
464
|
-
if (ctx.dataOnly) return done();
|
|
465
464
|
const res = runSuspense();
|
|
466
465
|
if (suspenseComplete(value)) {
|
|
467
466
|
done(resolveSSRNode(res));
|
|
@@ -482,20 +481,21 @@ function Suspense(props) {
|
|
|
482
481
|
});
|
|
483
482
|
}
|
|
484
483
|
const res = runSuspense();
|
|
485
|
-
if (suspenseComplete(value))
|
|
484
|
+
if (suspenseComplete(value)) {
|
|
485
|
+
ctx.writeResource(id, null);
|
|
486
|
+
return res;
|
|
487
|
+
}
|
|
486
488
|
onError(err => {
|
|
487
489
|
if (!done || !done(undefined, err)) throw err;
|
|
488
490
|
});
|
|
489
491
|
done = ctx.async ? ctx.registerFragment(id) : undefined;
|
|
490
492
|
if (ctx.streaming) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return res;
|
|
498
|
-
}
|
|
493
|
+
setHydrateContext(undefined);
|
|
494
|
+
const res = {
|
|
495
|
+
t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
|
|
496
|
+
};
|
|
497
|
+
setHydrateContext(ctx);
|
|
498
|
+
return res;
|
|
499
499
|
} else if (ctx.async) {
|
|
500
500
|
return {
|
|
501
501
|
t: `<![${id}]>`
|
package/dist/server.js
CHANGED
|
@@ -457,7 +457,6 @@ function Suspense(props) {
|
|
|
457
457
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
458
458
|
resources: new Map(),
|
|
459
459
|
completed: () => {
|
|
460
|
-
if (ctx.dataOnly) return done();
|
|
461
460
|
const res = runSuspense();
|
|
462
461
|
if (suspenseComplete(value)) {
|
|
463
462
|
done(resolveSSRNode(res));
|
|
@@ -478,20 +477,21 @@ function Suspense(props) {
|
|
|
478
477
|
});
|
|
479
478
|
}
|
|
480
479
|
const res = runSuspense();
|
|
481
|
-
if (suspenseComplete(value))
|
|
480
|
+
if (suspenseComplete(value)) {
|
|
481
|
+
ctx.writeResource(id, null);
|
|
482
|
+
return res;
|
|
483
|
+
}
|
|
482
484
|
onError(err => {
|
|
483
485
|
if (!done || !done(undefined, err)) throw err;
|
|
484
486
|
});
|
|
485
487
|
done = ctx.async ? ctx.registerFragment(id) : undefined;
|
|
486
488
|
if (ctx.streaming) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return res;
|
|
494
|
-
}
|
|
489
|
+
setHydrateContext(undefined);
|
|
490
|
+
const res = {
|
|
491
|
+
t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
|
|
492
|
+
};
|
|
493
|
+
setHydrateContext(ctx);
|
|
494
|
+
return res;
|
|
495
495
|
} else if (ctx.async) {
|
|
496
496
|
return {
|
|
497
497
|
t: `<![${id}]>`
|
package/dist/solid.cjs
CHANGED
|
@@ -233,6 +233,9 @@ function createResource(source, fetcher, options) {
|
|
|
233
233
|
fetcher = source;
|
|
234
234
|
source = true;
|
|
235
235
|
}
|
|
236
|
+
Resources || (Resources = new Set());
|
|
237
|
+
Resources.add(load);
|
|
238
|
+
onCleanup(() => Resources.delete(load));
|
|
236
239
|
const contexts = new Set(),
|
|
237
240
|
[s, set] = createSignal((options || {}).initialValue),
|
|
238
241
|
[track, trigger] = createSignal(undefined, {
|
|
@@ -244,13 +247,10 @@ function createResource(source, fetcher, options) {
|
|
|
244
247
|
pr = null,
|
|
245
248
|
initP = null,
|
|
246
249
|
id = null,
|
|
247
|
-
ctx,
|
|
248
250
|
loadedUnderTransition = false,
|
|
249
251
|
dynamic = typeof source === "function";
|
|
250
252
|
if (sharedConfig.context) {
|
|
251
253
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
252
|
-
ctx = { ...sharedConfig.context
|
|
253
|
-
};
|
|
254
254
|
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
255
255
|
}
|
|
256
256
|
function loadEnd(p, v, e) {
|
|
@@ -268,14 +268,7 @@ function createResource(source, fetcher, options) {
|
|
|
268
268
|
}
|
|
269
269
|
completeLoad(v);
|
|
270
270
|
}, false);
|
|
271
|
-
} else
|
|
272
|
-
if (p === initP) setHydrateContext(ctx);
|
|
273
|
-
completeLoad(v);
|
|
274
|
-
if (p === initP) {
|
|
275
|
-
initP = null;
|
|
276
|
-
setHydrateContext();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
271
|
+
} else completeLoad(v);
|
|
279
272
|
}
|
|
280
273
|
return v;
|
|
281
274
|
}
|
|
@@ -304,7 +297,7 @@ function createResource(source, fetcher, options) {
|
|
|
304
297
|
}
|
|
305
298
|
return v;
|
|
306
299
|
}
|
|
307
|
-
function load() {
|
|
300
|
+
function load(refetching = true) {
|
|
308
301
|
setError(err = undefined);
|
|
309
302
|
const lookup = dynamic ? source() : source;
|
|
310
303
|
loadedUnderTransition = Transition && Transition.running;
|
|
@@ -313,7 +306,11 @@ function createResource(source, fetcher, options) {
|
|
|
313
306
|
return;
|
|
314
307
|
}
|
|
315
308
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
316
|
-
const p =
|
|
309
|
+
const p = initP || untrack(() => fetcher(lookup, {
|
|
310
|
+
value: s(),
|
|
311
|
+
refetching
|
|
312
|
+
}));
|
|
313
|
+
initP = null;
|
|
317
314
|
if (typeof p !== "object" || !("then" in p)) {
|
|
318
315
|
loadEnd(pr, p);
|
|
319
316
|
return;
|
|
@@ -337,12 +334,16 @@ function createResource(source, fetcher, options) {
|
|
|
337
334
|
}
|
|
338
335
|
}
|
|
339
336
|
});
|
|
340
|
-
if (dynamic) createComputed(load);else load();
|
|
337
|
+
if (dynamic) createComputed(() => load(false));else load(false);
|
|
341
338
|
return [read, {
|
|
342
339
|
refetch: load,
|
|
343
340
|
mutate: set
|
|
344
341
|
}];
|
|
345
342
|
}
|
|
343
|
+
let Resources;
|
|
344
|
+
function refetchResources(info) {
|
|
345
|
+
Resources && Resources.forEach(fn => fn(info));
|
|
346
|
+
}
|
|
346
347
|
function createDeferred(source, options) {
|
|
347
348
|
let t,
|
|
348
349
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -1218,7 +1219,9 @@ function lazy(fn) {
|
|
|
1218
1219
|
});
|
|
1219
1220
|
comp = s;
|
|
1220
1221
|
} else if (!comp) {
|
|
1221
|
-
const [s] = createResource((
|
|
1222
|
+
const [s] = createResource((_, {
|
|
1223
|
+
value
|
|
1224
|
+
}) => value || (p || (p = fn())).then(mod => mod.default));
|
|
1222
1225
|
comp = s;
|
|
1223
1226
|
} else {
|
|
1224
1227
|
const c = comp();
|
|
@@ -1381,7 +1384,7 @@ function Suspense(props) {
|
|
|
1381
1384
|
showContent,
|
|
1382
1385
|
showFallback,
|
|
1383
1386
|
ctx,
|
|
1384
|
-
|
|
1387
|
+
p,
|
|
1385
1388
|
flicker,
|
|
1386
1389
|
error;
|
|
1387
1390
|
const [inFallback, setFallback] = createSignal(false),
|
|
@@ -1400,21 +1403,22 @@ function Suspense(props) {
|
|
|
1400
1403
|
owner = getOwner();
|
|
1401
1404
|
if (sharedConfig.context) {
|
|
1402
1405
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1403
|
-
|
|
1406
|
+
p = sharedConfig.load(key);
|
|
1404
1407
|
if (p) {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1408
|
+
if (typeof p !== "object" || !("then" in p)) error = p;else {
|
|
1409
|
+
const [s, set] = createSignal(undefined, {
|
|
1410
|
+
equals: false
|
|
1411
|
+
});
|
|
1412
|
+
flicker = s;
|
|
1413
|
+
p.then(err => {
|
|
1414
|
+
if (error = err) return set();
|
|
1415
|
+
sharedConfig.gather(key);
|
|
1416
|
+
setHydrateContext(ctx);
|
|
1417
|
+
set();
|
|
1418
|
+
setHydrateContext();
|
|
1419
|
+
p = undefined;
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1418
1422
|
}
|
|
1419
1423
|
}
|
|
1420
1424
|
const listContext = useContext(SuspenseListContext);
|
|
@@ -1426,18 +1430,19 @@ function Suspense(props) {
|
|
|
1426
1430
|
get children() {
|
|
1427
1431
|
return createMemo(() => {
|
|
1428
1432
|
if (error) throw error;
|
|
1433
|
+
ctx = sharedConfig.context;
|
|
1429
1434
|
if (flicker) {
|
|
1430
|
-
ctx = sharedConfig.context;
|
|
1431
1435
|
flicker();
|
|
1432
1436
|
return flicker = undefined;
|
|
1433
1437
|
}
|
|
1438
|
+
if (ctx && p === undefined) setHydrateContext();
|
|
1434
1439
|
const rendered = untrack(() => props.children);
|
|
1435
1440
|
return createMemo(() => {
|
|
1436
1441
|
const inFallback = store.inFallback(),
|
|
1437
1442
|
visibleContent = showContent ? showContent() : true,
|
|
1438
1443
|
visibleFallback = showFallback ? showFallback() : true;
|
|
1439
1444
|
dispose && dispose();
|
|
1440
|
-
if ((!inFallback ||
|
|
1445
|
+
if ((!inFallback || p !== undefined) && visibleContent) {
|
|
1441
1446
|
store.resolved = true;
|
|
1442
1447
|
resumeEffects(store.effects);
|
|
1443
1448
|
return rendered;
|
|
@@ -1445,10 +1450,13 @@ function Suspense(props) {
|
|
|
1445
1450
|
if (!visibleFallback) return;
|
|
1446
1451
|
return createRoot(disposer => {
|
|
1447
1452
|
dispose = disposer;
|
|
1448
|
-
if (
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1453
|
+
if (ctx) {
|
|
1454
|
+
setHydrateContext({
|
|
1455
|
+
id: ctx.id + "f",
|
|
1456
|
+
count: 0
|
|
1457
|
+
});
|
|
1458
|
+
ctx = undefined;
|
|
1459
|
+
}
|
|
1452
1460
|
return props.fallback;
|
|
1453
1461
|
}, owner);
|
|
1454
1462
|
});
|
|
@@ -1500,6 +1508,7 @@ exports.on = on;
|
|
|
1500
1508
|
exports.onCleanup = onCleanup;
|
|
1501
1509
|
exports.onError = onError;
|
|
1502
1510
|
exports.onMount = onMount;
|
|
1511
|
+
exports.refetchResources = refetchResources;
|
|
1503
1512
|
exports.requestCallback = requestCallback;
|
|
1504
1513
|
exports.runWithOwner = runWithOwner;
|
|
1505
1514
|
exports.sharedConfig = sharedConfig;
|
package/dist/solid.js
CHANGED
|
@@ -229,6 +229,9 @@ function createResource(source, fetcher, options) {
|
|
|
229
229
|
fetcher = source;
|
|
230
230
|
source = true;
|
|
231
231
|
}
|
|
232
|
+
Resources || (Resources = new Set());
|
|
233
|
+
Resources.add(load);
|
|
234
|
+
onCleanup(() => Resources.delete(load));
|
|
232
235
|
const contexts = new Set(),
|
|
233
236
|
[s, set] = createSignal((options || {}).initialValue),
|
|
234
237
|
[track, trigger] = createSignal(undefined, {
|
|
@@ -240,13 +243,10 @@ function createResource(source, fetcher, options) {
|
|
|
240
243
|
pr = null,
|
|
241
244
|
initP = null,
|
|
242
245
|
id = null,
|
|
243
|
-
ctx,
|
|
244
246
|
loadedUnderTransition = false,
|
|
245
247
|
dynamic = typeof source === "function";
|
|
246
248
|
if (sharedConfig.context) {
|
|
247
249
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
248
|
-
ctx = { ...sharedConfig.context
|
|
249
|
-
};
|
|
250
250
|
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
251
251
|
}
|
|
252
252
|
function loadEnd(p, v, e) {
|
|
@@ -264,14 +264,7 @@ function createResource(source, fetcher, options) {
|
|
|
264
264
|
}
|
|
265
265
|
completeLoad(v);
|
|
266
266
|
}, false);
|
|
267
|
-
} else
|
|
268
|
-
if (p === initP) setHydrateContext(ctx);
|
|
269
|
-
completeLoad(v);
|
|
270
|
-
if (p === initP) {
|
|
271
|
-
initP = null;
|
|
272
|
-
setHydrateContext();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
267
|
+
} else completeLoad(v);
|
|
275
268
|
}
|
|
276
269
|
return v;
|
|
277
270
|
}
|
|
@@ -300,7 +293,7 @@ function createResource(source, fetcher, options) {
|
|
|
300
293
|
}
|
|
301
294
|
return v;
|
|
302
295
|
}
|
|
303
|
-
function load() {
|
|
296
|
+
function load(refetching = true) {
|
|
304
297
|
setError(err = undefined);
|
|
305
298
|
const lookup = dynamic ? source() : source;
|
|
306
299
|
loadedUnderTransition = Transition && Transition.running;
|
|
@@ -309,7 +302,11 @@ function createResource(source, fetcher, options) {
|
|
|
309
302
|
return;
|
|
310
303
|
}
|
|
311
304
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
312
|
-
const p =
|
|
305
|
+
const p = initP || untrack(() => fetcher(lookup, {
|
|
306
|
+
value: s(),
|
|
307
|
+
refetching
|
|
308
|
+
}));
|
|
309
|
+
initP = null;
|
|
313
310
|
if (typeof p !== "object" || !("then" in p)) {
|
|
314
311
|
loadEnd(pr, p);
|
|
315
312
|
return;
|
|
@@ -333,12 +330,16 @@ function createResource(source, fetcher, options) {
|
|
|
333
330
|
}
|
|
334
331
|
}
|
|
335
332
|
});
|
|
336
|
-
if (dynamic) createComputed(load);else load();
|
|
333
|
+
if (dynamic) createComputed(() => load(false));else load(false);
|
|
337
334
|
return [read, {
|
|
338
335
|
refetch: load,
|
|
339
336
|
mutate: set
|
|
340
337
|
}];
|
|
341
338
|
}
|
|
339
|
+
let Resources;
|
|
340
|
+
function refetchResources(info) {
|
|
341
|
+
Resources && Resources.forEach(fn => fn(info));
|
|
342
|
+
}
|
|
342
343
|
function createDeferred(source, options) {
|
|
343
344
|
let t,
|
|
344
345
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -1214,7 +1215,9 @@ function lazy(fn) {
|
|
|
1214
1215
|
});
|
|
1215
1216
|
comp = s;
|
|
1216
1217
|
} else if (!comp) {
|
|
1217
|
-
const [s] = createResource((
|
|
1218
|
+
const [s] = createResource((_, {
|
|
1219
|
+
value
|
|
1220
|
+
}) => value || (p || (p = fn())).then(mod => mod.default));
|
|
1218
1221
|
comp = s;
|
|
1219
1222
|
} else {
|
|
1220
1223
|
const c = comp();
|
|
@@ -1377,7 +1380,7 @@ function Suspense(props) {
|
|
|
1377
1380
|
showContent,
|
|
1378
1381
|
showFallback,
|
|
1379
1382
|
ctx,
|
|
1380
|
-
|
|
1383
|
+
p,
|
|
1381
1384
|
flicker,
|
|
1382
1385
|
error;
|
|
1383
1386
|
const [inFallback, setFallback] = createSignal(false),
|
|
@@ -1396,21 +1399,22 @@ function Suspense(props) {
|
|
|
1396
1399
|
owner = getOwner();
|
|
1397
1400
|
if (sharedConfig.context) {
|
|
1398
1401
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1399
|
-
|
|
1402
|
+
p = sharedConfig.load(key);
|
|
1400
1403
|
if (p) {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1404
|
+
if (typeof p !== "object" || !("then" in p)) error = p;else {
|
|
1405
|
+
const [s, set] = createSignal(undefined, {
|
|
1406
|
+
equals: false
|
|
1407
|
+
});
|
|
1408
|
+
flicker = s;
|
|
1409
|
+
p.then(err => {
|
|
1410
|
+
if (error = err) return set();
|
|
1411
|
+
sharedConfig.gather(key);
|
|
1412
|
+
setHydrateContext(ctx);
|
|
1413
|
+
set();
|
|
1414
|
+
setHydrateContext();
|
|
1415
|
+
p = undefined;
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1414
1418
|
}
|
|
1415
1419
|
}
|
|
1416
1420
|
const listContext = useContext(SuspenseListContext);
|
|
@@ -1422,18 +1426,19 @@ function Suspense(props) {
|
|
|
1422
1426
|
get children() {
|
|
1423
1427
|
return createMemo(() => {
|
|
1424
1428
|
if (error) throw error;
|
|
1429
|
+
ctx = sharedConfig.context;
|
|
1425
1430
|
if (flicker) {
|
|
1426
|
-
ctx = sharedConfig.context;
|
|
1427
1431
|
flicker();
|
|
1428
1432
|
return flicker = undefined;
|
|
1429
1433
|
}
|
|
1434
|
+
if (ctx && p === undefined) setHydrateContext();
|
|
1430
1435
|
const rendered = untrack(() => props.children);
|
|
1431
1436
|
return createMemo(() => {
|
|
1432
1437
|
const inFallback = store.inFallback(),
|
|
1433
1438
|
visibleContent = showContent ? showContent() : true,
|
|
1434
1439
|
visibleFallback = showFallback ? showFallback() : true;
|
|
1435
1440
|
dispose && dispose();
|
|
1436
|
-
if ((!inFallback ||
|
|
1441
|
+
if ((!inFallback || p !== undefined) && visibleContent) {
|
|
1437
1442
|
store.resolved = true;
|
|
1438
1443
|
resumeEffects(store.effects);
|
|
1439
1444
|
return rendered;
|
|
@@ -1441,10 +1446,13 @@ function Suspense(props) {
|
|
|
1441
1446
|
if (!visibleFallback) return;
|
|
1442
1447
|
return createRoot(disposer => {
|
|
1443
1448
|
dispose = disposer;
|
|
1444
|
-
if (
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1449
|
+
if (ctx) {
|
|
1450
|
+
setHydrateContext({
|
|
1451
|
+
id: ctx.id + "f",
|
|
1452
|
+
count: 0
|
|
1453
|
+
});
|
|
1454
|
+
ctx = undefined;
|
|
1455
|
+
}
|
|
1448
1456
|
return props.fallback;
|
|
1449
1457
|
}, owner);
|
|
1450
1458
|
});
|
|
@@ -1455,4 +1463,4 @@ function Suspense(props) {
|
|
|
1455
1463
|
|
|
1456
1464
|
let DEV;
|
|
1457
1465
|
|
|
1458
|
-
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, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
|
|
1466
|
+
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, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, refetchResources, 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.3.0-
|
|
4
|
+
"version": "1.3.0-rc.1",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -144,5 +144,5 @@
|
|
|
144
144
|
"compiler",
|
|
145
145
|
"performance"
|
|
146
146
|
],
|
|
147
|
-
"gitHead": "
|
|
147
|
+
"gitHead": "f39053a4af47e82f7e5dcca27b2c449209611c1d"
|
|
148
148
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $PROXY } from "./reactive/signal";
|
|
2
|
-
export type { Accessor, Setter, Resource, ResourceReturn, Context, ReturnTypes } from "./reactive/signal";
|
|
1
|
+
export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, refetchResources, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $PROXY } from "./reactive/signal";
|
|
2
|
+
export type { Accessor, Setter, Resource, ResourceReturn, ResourceFetcher, ResourceFetcherInfo, Context, ReturnTypes } from "./reactive/signal";
|
|
3
3
|
export * from "./reactive/observable";
|
|
4
4
|
export * from "./reactive/scheduler";
|
|
5
5
|
export * from "./reactive/array";
|
|
@@ -185,11 +185,15 @@ export interface Resource<T> extends Accessor<T> {
|
|
|
185
185
|
}
|
|
186
186
|
export declare type ResourceActions<T> = {
|
|
187
187
|
mutate: Setter<T>;
|
|
188
|
-
refetch: () => void;
|
|
188
|
+
refetch: (info?: unknown) => void;
|
|
189
189
|
};
|
|
190
190
|
export declare type ResourceReturn<T> = [Resource<T>, ResourceActions<T>];
|
|
191
191
|
export declare type ResourceSource<S> = S | false | null | (() => S | false | null);
|
|
192
|
-
export declare type ResourceFetcher<S, T> = (k: S,
|
|
192
|
+
export declare type ResourceFetcher<S, T> = (k: S, info: ResourceFetcherInfo<T>) => T | Promise<T>;
|
|
193
|
+
export declare type ResourceFetcherInfo<T> = {
|
|
194
|
+
value: T | undefined;
|
|
195
|
+
refetching?: unknown;
|
|
196
|
+
};
|
|
193
197
|
export declare type ResourceOptions<T> = T extends undefined ? {
|
|
194
198
|
initialValue?: T;
|
|
195
199
|
name?: string;
|
|
@@ -200,14 +204,14 @@ export declare type ResourceOptions<T> = T extends undefined ? {
|
|
|
200
204
|
/**
|
|
201
205
|
* Creates a resource that wraps a repeated promise in a reactive pattern:
|
|
202
206
|
* ```typescript
|
|
203
|
-
* const [resource, { mutate, refetch }] =
|
|
207
|
+
* const [resource, { mutate, refetch }] = createResource(source, fetcher, options);
|
|
204
208
|
* ```
|
|
205
209
|
* @param source - reactive data function to toggle the request, optional
|
|
206
210
|
* @param fetcher - function that receives the source (or true) and an accessor for the last or initial value and returns a value or a Promise with the value:
|
|
207
211
|
* ```typescript
|
|
208
212
|
* const fetcher: ResourceFetcher<S, T, > = (
|
|
209
213
|
* sourceOutput: ReturnValue<typeof source>,
|
|
210
|
-
*
|
|
214
|
+
* info: ResourceFetcherInfo<T>
|
|
211
215
|
* ) => T | Promise<T>;
|
|
212
216
|
* ```
|
|
213
217
|
* @param options - an optional object with the initialValue and the name (for debugging purposes)
|
|
@@ -226,6 +230,7 @@ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S,
|
|
|
226
230
|
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
227
231
|
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
|
|
228
232
|
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
233
|
+
export declare function refetchResources(info?: unknown): void;
|
|
229
234
|
export interface DeferredOptions<T> {
|
|
230
235
|
equals?: false | ((prev: T, next: T) => boolean);
|
|
231
236
|
name?: string;
|
|
@@ -348,6 +353,12 @@ export declare function getListener(): Computation<any, any> | null;
|
|
|
348
353
|
export declare function getOwner(): Owner | null;
|
|
349
354
|
export declare function runWithOwner(o: Owner, fn: () => any): any;
|
|
350
355
|
export declare function enableScheduling(scheduler?: typeof requestCallback): void;
|
|
356
|
+
/**
|
|
357
|
+
* ```typescript
|
|
358
|
+
* export function startTransition(fn: () => void, cb?: () => void) => void
|
|
359
|
+
*
|
|
360
|
+
* @description https://www.solidjs.com/docs/latest/api#usetransition
|
|
361
|
+
*/
|
|
351
362
|
export declare function startTransition(fn: () => void, cb?: () => void): void;
|
|
352
363
|
export declare type Transition = [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
|
|
353
364
|
/**
|
|
@@ -82,6 +82,7 @@ export declare function createResource<T, U = true>(fetcher: (k: U, getPrev: ()
|
|
|
82
82
|
export declare function createResource<T, U>(fn: U | false | (() => U | false), fetcher: (k: U, getPrev: () => T | undefined) => T | Promise<T>, options?: {
|
|
83
83
|
initialValue?: T;
|
|
84
84
|
}): ResourceReturn<T>;
|
|
85
|
+
export declare function refetchResources(info?: unknown): void;
|
|
85
86
|
export declare function lazy(fn: () => Promise<{
|
|
86
87
|
default: any;
|
|
87
88
|
}>): (props: any) => string;
|
|
@@ -97,7 +98,6 @@ declare type HydrationContext = {
|
|
|
97
98
|
registerFragment: (v: string) => (v?: string, err?: any) => boolean;
|
|
98
99
|
async?: boolean;
|
|
99
100
|
streaming?: boolean;
|
|
100
|
-
dataOnly?: boolean;
|
|
101
101
|
noHydrate: boolean;
|
|
102
102
|
};
|
|
103
103
|
export declare function SuspenseList(props: {
|
package/web/dist/dev.cjs
CHANGED
|
@@ -409,7 +409,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
409
409
|
cleanChildren(parent, current, null, value);
|
|
410
410
|
} else if (current == null || current === "" || !parent.firstChild) {
|
|
411
411
|
parent.appendChild(value);
|
|
412
|
-
} else parent.replaceChild(value, parent.firstChild);
|
|
412
|
+
} else parent.replaceChild(value, multi ? current : parent.firstChild);
|
|
413
413
|
current = value;
|
|
414
414
|
} else console.warn(`Unrecognized value. Skipped inserting`, value);
|
|
415
415
|
return current;
|
package/web/dist/dev.js
CHANGED
|
@@ -406,7 +406,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
406
406
|
cleanChildren(parent, current, null, value);
|
|
407
407
|
} else if (current == null || current === "" || !parent.firstChild) {
|
|
408
408
|
parent.appendChild(value);
|
|
409
|
-
} else parent.replaceChild(value, parent.firstChild);
|
|
409
|
+
} else parent.replaceChild(value, multi ? current : parent.firstChild);
|
|
410
410
|
current = value;
|
|
411
411
|
} else console.warn(`Unrecognized value. Skipped inserting`, value);
|
|
412
412
|
return current;
|
package/web/dist/server.cjs
CHANGED
|
@@ -232,7 +232,7 @@ function stringifyString(str) {
|
|
|
232
232
|
return result;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
|
|
235
|
+
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y||null)}`;
|
|
236
236
|
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
237
237
|
function renderToString(code, options = {}) {
|
|
238
238
|
let scripts = "";
|
|
@@ -243,7 +243,8 @@ function renderToString(code, options = {}) {
|
|
|
243
243
|
assets: [],
|
|
244
244
|
nonce: options.nonce,
|
|
245
245
|
writeResource(id, p, error) {
|
|
246
|
-
if (error) scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
246
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
247
|
+
scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
247
248
|
}
|
|
248
249
|
};
|
|
249
250
|
let html = injectAssets(solidJs.sharedConfig.context.assets, resolveSSRNode(escape(code())));
|
|
@@ -251,6 +252,7 @@ function renderToString(code, options = {}) {
|
|
|
251
252
|
return html;
|
|
252
253
|
}
|
|
253
254
|
function renderToStringAsync(code, options = {}) {
|
|
255
|
+
let scripts = "";
|
|
254
256
|
const {
|
|
255
257
|
nonce,
|
|
256
258
|
renderId,
|
|
@@ -263,12 +265,12 @@ function renderToStringAsync(code, options = {}) {
|
|
|
263
265
|
suspense: {},
|
|
264
266
|
assets: [],
|
|
265
267
|
async: true,
|
|
266
|
-
nonce
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
nonce,
|
|
269
|
+
writeResource(id, p, error) {
|
|
270
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
271
|
+
if (!p || typeof p !== "object" || !("then" in p)) return scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
272
|
+
p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", {});`);
|
|
273
|
+
}
|
|
272
274
|
};
|
|
273
275
|
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
274
276
|
function asyncWrap(fn) {
|
|
@@ -281,9 +283,10 @@ function renderToStringAsync(code, options = {}) {
|
|
|
281
283
|
function register(key) {
|
|
282
284
|
registry.add(key);
|
|
283
285
|
return (value = "", error) => {
|
|
286
|
+
if (!registry.has(key)) return;
|
|
284
287
|
cache[key] = value;
|
|
285
288
|
registry.delete(key);
|
|
286
|
-
if (error)
|
|
289
|
+
if (error) scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;else scripts += `_$HY.set("${key}", null);`;
|
|
287
290
|
if (!registry.size) Promise.resolve().then(() => {
|
|
288
291
|
let source = resolveSSRNode(rendered);
|
|
289
292
|
let final = "";
|
|
@@ -310,7 +313,6 @@ function renderToStream(code, options = {}) {
|
|
|
310
313
|
nonce,
|
|
311
314
|
onCompleteShell,
|
|
312
315
|
onCompleteAll,
|
|
313
|
-
dataOnly,
|
|
314
316
|
renderId
|
|
315
317
|
} = options;
|
|
316
318
|
const tmp = [];
|
|
@@ -344,7 +346,6 @@ function renderToStream(code, options = {}) {
|
|
|
344
346
|
count: 0,
|
|
345
347
|
async: true,
|
|
346
348
|
streaming: true,
|
|
347
|
-
dataOnly,
|
|
348
349
|
resources: {},
|
|
349
350
|
suspense: {},
|
|
350
351
|
assets: [],
|
|
@@ -355,22 +356,21 @@ function renderToStream(code, options = {}) {
|
|
|
355
356
|
scheduled = true;
|
|
356
357
|
}
|
|
357
358
|
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
359
|
+
if (!p || typeof p !== "object" || !("then" in p)) return tasks.push(`_$HY.set("${id}", ${devalue(p)})`);
|
|
358
360
|
tasks.push(`_$HY.init("${id}")`);
|
|
359
361
|
p.then(d => {
|
|
360
362
|
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
361
|
-
}).catch(
|
|
362
|
-
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}",
|
|
363
|
+
}).catch(err => {
|
|
364
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", {})</script>`);
|
|
363
365
|
});
|
|
364
366
|
},
|
|
365
367
|
registerFragment(key) {
|
|
366
368
|
registry.set(key, []);
|
|
367
|
-
if (!
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
scheduled = true;
|
|
371
|
-
}
|
|
372
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
369
|
+
if (!scheduled) {
|
|
370
|
+
Promise.resolve().then(writeInitialScript);
|
|
371
|
+
scheduled = true;
|
|
373
372
|
}
|
|
373
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
374
374
|
return (value, error) => {
|
|
375
375
|
const keys = registry.get(key);
|
|
376
376
|
registry.delete(key);
|
|
@@ -404,6 +404,7 @@ function renderToStream(code, options = {}) {
|
|
|
404
404
|
const writer = w.getWriter();
|
|
405
405
|
writable = {
|
|
406
406
|
end() {
|
|
407
|
+
writer.releaseLock();
|
|
407
408
|
w.close();
|
|
408
409
|
}
|
|
409
410
|
};
|
|
@@ -573,7 +574,7 @@ function generateHydrationScript({
|
|
|
573
574
|
eventNames = ["click", "input"],
|
|
574
575
|
nonce
|
|
575
576
|
}) {
|
|
576
|
-
return `<script${nonce ? ` nonce="${nonce}"` : ""}>((e,t,o={})=>{t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{let
|
|
577
|
+
return `<script${nonce ? ` nonce="${nonce}"` : ""}>((e,t,o={})=>{t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,n=t(s);n&&!e.completed.has(n)&&e.events.push([n,o])})))),e.init=(e,t)=>{o[e]=[new Promise(((e,o)=>t=e)),t]},e.set=(e,t,s)=>{(s=o[e])&&s[1](t),o[e]=[t]},e.unset=e=>{delete o[e]},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet}))</script><!xs>`;
|
|
577
578
|
}
|
|
578
579
|
function injectAssets(assets, html) {
|
|
579
580
|
for (let i = 0; i < assets.length; i++) {
|
package/web/dist/server.js
CHANGED
|
@@ -229,7 +229,7 @@ function stringifyString(str) {
|
|
|
229
229
|
return result;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
|
|
232
|
+
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y||null)}`;
|
|
233
233
|
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
234
234
|
function renderToString(code, options = {}) {
|
|
235
235
|
let scripts = "";
|
|
@@ -240,7 +240,8 @@ function renderToString(code, options = {}) {
|
|
|
240
240
|
assets: [],
|
|
241
241
|
nonce: options.nonce,
|
|
242
242
|
writeResource(id, p, error) {
|
|
243
|
-
if (error) scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
243
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
244
|
+
scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
244
245
|
}
|
|
245
246
|
};
|
|
246
247
|
let html = injectAssets(sharedConfig.context.assets, resolveSSRNode(escape(code())));
|
|
@@ -248,6 +249,7 @@ function renderToString(code, options = {}) {
|
|
|
248
249
|
return html;
|
|
249
250
|
}
|
|
250
251
|
function renderToStringAsync(code, options = {}) {
|
|
252
|
+
let scripts = "";
|
|
251
253
|
const {
|
|
252
254
|
nonce,
|
|
253
255
|
renderId,
|
|
@@ -260,12 +262,12 @@ function renderToStringAsync(code, options = {}) {
|
|
|
260
262
|
suspense: {},
|
|
261
263
|
assets: [],
|
|
262
264
|
async: true,
|
|
263
|
-
nonce
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
nonce,
|
|
266
|
+
writeResource(id, p, error) {
|
|
267
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
268
|
+
if (!p || typeof p !== "object" || !("then" in p)) return scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
269
|
+
p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", {});`);
|
|
270
|
+
}
|
|
269
271
|
};
|
|
270
272
|
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
271
273
|
function asyncWrap(fn) {
|
|
@@ -278,9 +280,10 @@ function renderToStringAsync(code, options = {}) {
|
|
|
278
280
|
function register(key) {
|
|
279
281
|
registry.add(key);
|
|
280
282
|
return (value = "", error) => {
|
|
283
|
+
if (!registry.has(key)) return;
|
|
281
284
|
cache[key] = value;
|
|
282
285
|
registry.delete(key);
|
|
283
|
-
if (error)
|
|
286
|
+
if (error) scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;else scripts += `_$HY.set("${key}", null);`;
|
|
284
287
|
if (!registry.size) Promise.resolve().then(() => {
|
|
285
288
|
let source = resolveSSRNode(rendered);
|
|
286
289
|
let final = "";
|
|
@@ -307,7 +310,6 @@ function renderToStream(code, options = {}) {
|
|
|
307
310
|
nonce,
|
|
308
311
|
onCompleteShell,
|
|
309
312
|
onCompleteAll,
|
|
310
|
-
dataOnly,
|
|
311
313
|
renderId
|
|
312
314
|
} = options;
|
|
313
315
|
const tmp = [];
|
|
@@ -341,7 +343,6 @@ function renderToStream(code, options = {}) {
|
|
|
341
343
|
count: 0,
|
|
342
344
|
async: true,
|
|
343
345
|
streaming: true,
|
|
344
|
-
dataOnly,
|
|
345
346
|
resources: {},
|
|
346
347
|
suspense: {},
|
|
347
348
|
assets: [],
|
|
@@ -352,22 +353,21 @@ function renderToStream(code, options = {}) {
|
|
|
352
353
|
scheduled = true;
|
|
353
354
|
}
|
|
354
355
|
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
356
|
+
if (!p || typeof p !== "object" || !("then" in p)) return tasks.push(`_$HY.set("${id}", ${devalue(p)})`);
|
|
355
357
|
tasks.push(`_$HY.init("${id}")`);
|
|
356
358
|
p.then(d => {
|
|
357
359
|
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
358
|
-
}).catch(
|
|
359
|
-
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}",
|
|
360
|
+
}).catch(err => {
|
|
361
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", {})</script>`);
|
|
360
362
|
});
|
|
361
363
|
},
|
|
362
364
|
registerFragment(key) {
|
|
363
365
|
registry.set(key, []);
|
|
364
|
-
if (!
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
scheduled = true;
|
|
368
|
-
}
|
|
369
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
366
|
+
if (!scheduled) {
|
|
367
|
+
Promise.resolve().then(writeInitialScript);
|
|
368
|
+
scheduled = true;
|
|
370
369
|
}
|
|
370
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
371
371
|
return (value, error) => {
|
|
372
372
|
const keys = registry.get(key);
|
|
373
373
|
registry.delete(key);
|
|
@@ -401,6 +401,7 @@ function renderToStream(code, options = {}) {
|
|
|
401
401
|
const writer = w.getWriter();
|
|
402
402
|
writable = {
|
|
403
403
|
end() {
|
|
404
|
+
writer.releaseLock();
|
|
404
405
|
w.close();
|
|
405
406
|
}
|
|
406
407
|
};
|
|
@@ -570,7 +571,7 @@ function generateHydrationScript({
|
|
|
570
571
|
eventNames = ["click", "input"],
|
|
571
572
|
nonce
|
|
572
573
|
}) {
|
|
573
|
-
return `<script${nonce ? ` nonce="${nonce}"` : ""}>((e,t,o={})=>{t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{let
|
|
574
|
+
return `<script${nonce ? ` nonce="${nonce}"` : ""}>((e,t,o={})=>{t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,n=t(s);n&&!e.completed.has(n)&&e.events.push([n,o])})))),e.init=(e,t)=>{o[e]=[new Promise(((e,o)=>t=e)),t]},e.set=(e,t,s)=>{(s=o[e])&&s[1](t),o[e]=[t]},e.unset=e=>{delete o[e]},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet}))</script><!xs>`;
|
|
574
575
|
}
|
|
575
576
|
function injectAssets(assets, html) {
|
|
576
577
|
for (let i = 0; i < assets.length; i++) {
|
package/web/dist/web.cjs
CHANGED
|
@@ -408,7 +408,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
408
408
|
cleanChildren(parent, current, null, value);
|
|
409
409
|
} else if (current == null || current === "" || !parent.firstChild) {
|
|
410
410
|
parent.appendChild(value);
|
|
411
|
-
} else parent.replaceChild(value, parent.firstChild);
|
|
411
|
+
} else parent.replaceChild(value, multi ? current : parent.firstChild);
|
|
412
412
|
current = value;
|
|
413
413
|
} else ;
|
|
414
414
|
return current;
|
package/web/dist/web.js
CHANGED
|
@@ -405,7 +405,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
405
405
|
cleanChildren(parent, current, null, value);
|
|
406
406
|
} else if (current == null || current === "" || !parent.firstChild) {
|
|
407
407
|
parent.appendChild(value);
|
|
408
|
-
} else parent.replaceChild(value, parent.firstChild);
|
|
408
|
+
} else parent.replaceChild(value, multi ? current : parent.firstChild);
|
|
409
409
|
current = value;
|
|
410
410
|
} else ;
|
|
411
411
|
return current;
|
|
@@ -9,7 +9,6 @@ export declare function renderToStringAsync<T>(fn: () => T, options?: {
|
|
|
9
9
|
}): Promise<string>;
|
|
10
10
|
export declare function renderToStream<T>(fn: () => T, options?: {
|
|
11
11
|
nonce?: string;
|
|
12
|
-
dataOnly?: boolean;
|
|
13
12
|
renderId?: string;
|
|
14
13
|
onCompleteShell?: () => void;
|
|
15
14
|
onCompleteAll?: () => void;
|
|
@@ -42,7 +41,6 @@ export declare type LegacyResults = {
|
|
|
42
41
|
*/
|
|
43
42
|
export declare function pipeToWritable<T>(fn: () => T, writable: WritableStream, options?: {
|
|
44
43
|
nonce?: string;
|
|
45
|
-
dataOnly?: boolean;
|
|
46
44
|
onReady?: (res: LegacyResults) => void;
|
|
47
45
|
onCompleteAll?: () => void;
|
|
48
46
|
}): void;
|
|
@@ -53,7 +51,6 @@ export declare function pipeToNodeWritable<T>(fn: () => T, writable: {
|
|
|
53
51
|
write: (v: string) => void;
|
|
54
52
|
}, options?: {
|
|
55
53
|
nonce?: string;
|
|
56
|
-
dataOnly?: boolean;
|
|
57
54
|
onReady?: (res: LegacyResults) => void;
|
|
58
55
|
onCompleteAll?: () => void;
|
|
59
56
|
}): void;
|