solid-js 1.3.0-beta.2 → 1.3.0-beta.3
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/README.md +3 -1
- package/dist/dev.cjs +11 -4
- package/dist/dev.js +11 -4
- package/dist/server.cjs +50 -12
- package/dist/server.js +50 -12
- package/dist/solid.cjs +11 -4
- package/dist/solid.js +11 -4
- package/package.json +15 -15
- package/types/server/rendering.d.ts +6 -5
- package/web/dist/dev.cjs +2 -2
- package/web/dist/dev.js +2 -2
- package/web/dist/server.cjs +103 -67
- package/web/dist/server.js +103 -67
- package/web/dist/web.cjs +2 -2
- package/web/dist/web.js +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
<p>
|
|
2
|
+
<img width="100%" src="https://raw.githubusercontent.com/solidjs/solid/master/banner.png" alt="SolidJS">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
5
|
[](https://github.com/solidjs/solid/actions/workflows/main-ci.yml)
|
|
4
6
|
[](https://coveralls.io/github/solidjs/solid?branch=main)
|
package/dist/dev.cjs
CHANGED
|
@@ -1322,7 +1322,11 @@ function Match(props) {
|
|
|
1322
1322
|
return props;
|
|
1323
1323
|
}
|
|
1324
1324
|
function ErrorBoundary(props) {
|
|
1325
|
-
|
|
1325
|
+
let err = undefined;
|
|
1326
|
+
if (sharedConfig.context && sharedConfig.load) {
|
|
1327
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1328
|
+
}
|
|
1329
|
+
const [errored, setErrored] = createSignal(err);
|
|
1326
1330
|
let e;
|
|
1327
1331
|
return createMemo(() => {
|
|
1328
1332
|
if ((e = errored()) != null) {
|
|
@@ -1406,7 +1410,8 @@ function Suspense(props) {
|
|
|
1406
1410
|
showFallback,
|
|
1407
1411
|
ctx,
|
|
1408
1412
|
waitingHydration,
|
|
1409
|
-
flicker
|
|
1413
|
+
flicker,
|
|
1414
|
+
error;
|
|
1410
1415
|
const [inFallback, setFallback] = createSignal(false),
|
|
1411
1416
|
SuspenseContext = getSuspenseContext(),
|
|
1412
1417
|
store = {
|
|
@@ -1421,7 +1426,7 @@ function Suspense(props) {
|
|
|
1421
1426
|
resolved: false
|
|
1422
1427
|
},
|
|
1423
1428
|
owner = getOwner();
|
|
1424
|
-
if (sharedConfig.context
|
|
1429
|
+
if (sharedConfig.context) {
|
|
1425
1430
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1426
1431
|
const p = sharedConfig.load(key);
|
|
1427
1432
|
if (p) {
|
|
@@ -1429,7 +1434,8 @@ function Suspense(props) {
|
|
|
1429
1434
|
equals: false
|
|
1430
1435
|
});
|
|
1431
1436
|
flicker = s;
|
|
1432
|
-
p.then(
|
|
1437
|
+
p.then(err => {
|
|
1438
|
+
if (error = err) return set();
|
|
1433
1439
|
sharedConfig.gather(key);
|
|
1434
1440
|
waitingHydration = true;
|
|
1435
1441
|
setHydrateContext(ctx);
|
|
@@ -1447,6 +1453,7 @@ function Suspense(props) {
|
|
|
1447
1453
|
value: store,
|
|
1448
1454
|
get children() {
|
|
1449
1455
|
return createMemo(() => {
|
|
1456
|
+
if (error) throw error;
|
|
1450
1457
|
if (flicker) {
|
|
1451
1458
|
ctx = sharedConfig.context;
|
|
1452
1459
|
flicker();
|
package/dist/dev.js
CHANGED
|
@@ -1318,7 +1318,11 @@ function Match(props) {
|
|
|
1318
1318
|
return props;
|
|
1319
1319
|
}
|
|
1320
1320
|
function ErrorBoundary(props) {
|
|
1321
|
-
|
|
1321
|
+
let err = undefined;
|
|
1322
|
+
if (sharedConfig.context && sharedConfig.load) {
|
|
1323
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1324
|
+
}
|
|
1325
|
+
const [errored, setErrored] = createSignal(err);
|
|
1322
1326
|
let e;
|
|
1323
1327
|
return createMemo(() => {
|
|
1324
1328
|
if ((e = errored()) != null) {
|
|
@@ -1402,7 +1406,8 @@ function Suspense(props) {
|
|
|
1402
1406
|
showFallback,
|
|
1403
1407
|
ctx,
|
|
1404
1408
|
waitingHydration,
|
|
1405
|
-
flicker
|
|
1409
|
+
flicker,
|
|
1410
|
+
error;
|
|
1406
1411
|
const [inFallback, setFallback] = createSignal(false),
|
|
1407
1412
|
SuspenseContext = getSuspenseContext(),
|
|
1408
1413
|
store = {
|
|
@@ -1417,7 +1422,7 @@ function Suspense(props) {
|
|
|
1417
1422
|
resolved: false
|
|
1418
1423
|
},
|
|
1419
1424
|
owner = getOwner();
|
|
1420
|
-
if (sharedConfig.context
|
|
1425
|
+
if (sharedConfig.context) {
|
|
1421
1426
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1422
1427
|
const p = sharedConfig.load(key);
|
|
1423
1428
|
if (p) {
|
|
@@ -1425,7 +1430,8 @@ function Suspense(props) {
|
|
|
1425
1430
|
equals: false
|
|
1426
1431
|
});
|
|
1427
1432
|
flicker = s;
|
|
1428
|
-
p.then(
|
|
1433
|
+
p.then(err => {
|
|
1434
|
+
if (error = err) return set();
|
|
1429
1435
|
sharedConfig.gather(key);
|
|
1430
1436
|
waitingHydration = true;
|
|
1431
1437
|
setHydrateContext(ctx);
|
|
@@ -1443,6 +1449,7 @@ function Suspense(props) {
|
|
|
1443
1449
|
value: store,
|
|
1444
1450
|
get children() {
|
|
1445
1451
|
return createMemo(() => {
|
|
1452
|
+
if (error) throw error;
|
|
1446
1453
|
if (flicker) {
|
|
1447
1454
|
ctx = sharedConfig.context;
|
|
1448
1455
|
flicker();
|
package/dist/server.cjs
CHANGED
|
@@ -41,8 +41,15 @@ function createComputed(fn, value) {
|
|
|
41
41
|
owner: Owner,
|
|
42
42
|
context: null
|
|
43
43
|
};
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
fn(value);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
const fns = lookup(Owner, ERROR);
|
|
48
|
+
if (!fns) throw err;
|
|
49
|
+
fns.forEach(f => f(err));
|
|
50
|
+
} finally {
|
|
51
|
+
Owner = Owner.owner;
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
const createRenderEffect = createComputed;
|
|
48
55
|
function createEffect(fn, value) {}
|
|
@@ -51,8 +58,16 @@ function createMemo(fn, value) {
|
|
|
51
58
|
owner: Owner,
|
|
52
59
|
context: null
|
|
53
60
|
};
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
let v;
|
|
62
|
+
try {
|
|
63
|
+
v = fn(value);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
const fns = lookup(Owner, ERROR);
|
|
66
|
+
if (!fns) throw err;
|
|
67
|
+
fns.forEach(f => f(err));
|
|
68
|
+
} finally {
|
|
69
|
+
Owner = Owner.owner;
|
|
70
|
+
}
|
|
56
71
|
return () => v;
|
|
57
72
|
}
|
|
58
73
|
function createDeferred(source) {
|
|
@@ -290,7 +305,20 @@ function Match(props) {
|
|
|
290
305
|
return props;
|
|
291
306
|
}
|
|
292
307
|
function ErrorBoundary(props) {
|
|
293
|
-
|
|
308
|
+
let error, res;
|
|
309
|
+
const ctx = sharedConfig.context;
|
|
310
|
+
const id = ctx.id + ctx.count;
|
|
311
|
+
onError(err => error = err);
|
|
312
|
+
createMemo(() => res = props.children);
|
|
313
|
+
if (error) {
|
|
314
|
+
ctx.writeResource(id, error, true);
|
|
315
|
+
setHydrateContext({ ...ctx,
|
|
316
|
+
count: 0
|
|
317
|
+
});
|
|
318
|
+
const f = props.fallback;
|
|
319
|
+
return typeof f === "function" && f.length ? f(error, () => {}) : f;
|
|
320
|
+
}
|
|
321
|
+
return res;
|
|
294
322
|
}
|
|
295
323
|
const SuspenseContext = createContext();
|
|
296
324
|
let resourceContext = null;
|
|
@@ -310,6 +338,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
310
338
|
let resource = {};
|
|
311
339
|
let value = options.initialValue;
|
|
312
340
|
let p;
|
|
341
|
+
let error;
|
|
313
342
|
if (sharedConfig.context.async) {
|
|
314
343
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
315
344
|
if (resource.ref) {
|
|
@@ -318,6 +347,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
318
347
|
}
|
|
319
348
|
}
|
|
320
349
|
const read = () => {
|
|
350
|
+
if (error) throw error;
|
|
321
351
|
if (resourceContext && p) resourceContext.push(p);
|
|
322
352
|
const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
|
|
323
353
|
if (!resolved) {
|
|
@@ -356,6 +386,11 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
356
386
|
p = null;
|
|
357
387
|
notifySuspense(contexts);
|
|
358
388
|
return res;
|
|
389
|
+
}).catch(err => {
|
|
390
|
+
read.loading = false;
|
|
391
|
+
error = err;
|
|
392
|
+
p = null;
|
|
393
|
+
notifySuspense(contexts);
|
|
359
394
|
});
|
|
360
395
|
return;
|
|
361
396
|
}
|
|
@@ -418,13 +453,14 @@ function SuspenseList(props) {
|
|
|
418
453
|
return props.children;
|
|
419
454
|
}
|
|
420
455
|
function Suspense(props) {
|
|
456
|
+
let done;
|
|
421
457
|
const ctx = sharedConfig.context;
|
|
422
458
|
const id = ctx.id + ctx.count;
|
|
423
|
-
const done = ctx.async ? ctx.registerFragment(id) : () => {};
|
|
424
459
|
const o = Owner;
|
|
425
460
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
426
461
|
resources: new Map(),
|
|
427
462
|
completed: () => {
|
|
463
|
+
if (ctx.dataOnly) return done();
|
|
428
464
|
const res = runSuspense();
|
|
429
465
|
if (suspenseComplete(value)) {
|
|
430
466
|
done(resolveSSRNode(res));
|
|
@@ -445,12 +481,13 @@ function Suspense(props) {
|
|
|
445
481
|
});
|
|
446
482
|
}
|
|
447
483
|
const res = runSuspense();
|
|
448
|
-
if (suspenseComplete(value))
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
484
|
+
if (suspenseComplete(value)) return res;
|
|
485
|
+
onError(err => {
|
|
486
|
+
if (!done || !done(undefined, err)) throw err;
|
|
487
|
+
});
|
|
488
|
+
done = ctx.async ? ctx.registerFragment(id) : undefined;
|
|
489
|
+
if (ctx.streaming) {
|
|
490
|
+
if (!ctx.dataOnly) {
|
|
454
491
|
setHydrateContext(undefined);
|
|
455
492
|
const res = {
|
|
456
493
|
t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
|
|
@@ -458,6 +495,7 @@ function Suspense(props) {
|
|
|
458
495
|
setHydrateContext(ctx);
|
|
459
496
|
return res;
|
|
460
497
|
}
|
|
498
|
+
} else if (ctx.async) {
|
|
461
499
|
return {
|
|
462
500
|
t: `<![${id}]>`
|
|
463
501
|
};
|
package/dist/server.js
CHANGED
|
@@ -37,8 +37,15 @@ function createComputed(fn, value) {
|
|
|
37
37
|
owner: Owner,
|
|
38
38
|
context: null
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
try {
|
|
41
|
+
fn(value);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const fns = lookup(Owner, ERROR);
|
|
44
|
+
if (!fns) throw err;
|
|
45
|
+
fns.forEach(f => f(err));
|
|
46
|
+
} finally {
|
|
47
|
+
Owner = Owner.owner;
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
const createRenderEffect = createComputed;
|
|
44
51
|
function createEffect(fn, value) {}
|
|
@@ -47,8 +54,16 @@ function createMemo(fn, value) {
|
|
|
47
54
|
owner: Owner,
|
|
48
55
|
context: null
|
|
49
56
|
};
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
let v;
|
|
58
|
+
try {
|
|
59
|
+
v = fn(value);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const fns = lookup(Owner, ERROR);
|
|
62
|
+
if (!fns) throw err;
|
|
63
|
+
fns.forEach(f => f(err));
|
|
64
|
+
} finally {
|
|
65
|
+
Owner = Owner.owner;
|
|
66
|
+
}
|
|
52
67
|
return () => v;
|
|
53
68
|
}
|
|
54
69
|
function createDeferred(source) {
|
|
@@ -286,7 +301,20 @@ function Match(props) {
|
|
|
286
301
|
return props;
|
|
287
302
|
}
|
|
288
303
|
function ErrorBoundary(props) {
|
|
289
|
-
|
|
304
|
+
let error, res;
|
|
305
|
+
const ctx = sharedConfig.context;
|
|
306
|
+
const id = ctx.id + ctx.count;
|
|
307
|
+
onError(err => error = err);
|
|
308
|
+
createMemo(() => res = props.children);
|
|
309
|
+
if (error) {
|
|
310
|
+
ctx.writeResource(id, error, true);
|
|
311
|
+
setHydrateContext({ ...ctx,
|
|
312
|
+
count: 0
|
|
313
|
+
});
|
|
314
|
+
const f = props.fallback;
|
|
315
|
+
return typeof f === "function" && f.length ? f(error, () => {}) : f;
|
|
316
|
+
}
|
|
317
|
+
return res;
|
|
290
318
|
}
|
|
291
319
|
const SuspenseContext = createContext();
|
|
292
320
|
let resourceContext = null;
|
|
@@ -306,6 +334,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
306
334
|
let resource = {};
|
|
307
335
|
let value = options.initialValue;
|
|
308
336
|
let p;
|
|
337
|
+
let error;
|
|
309
338
|
if (sharedConfig.context.async) {
|
|
310
339
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
311
340
|
if (resource.ref) {
|
|
@@ -314,6 +343,7 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
314
343
|
}
|
|
315
344
|
}
|
|
316
345
|
const read = () => {
|
|
346
|
+
if (error) throw error;
|
|
317
347
|
if (resourceContext && p) resourceContext.push(p);
|
|
318
348
|
const resolved = sharedConfig.context.async && sharedConfig.context.resources[id].data;
|
|
319
349
|
if (!resolved) {
|
|
@@ -352,6 +382,11 @@ function createResource(fn, fetcher, options = {}) {
|
|
|
352
382
|
p = null;
|
|
353
383
|
notifySuspense(contexts);
|
|
354
384
|
return res;
|
|
385
|
+
}).catch(err => {
|
|
386
|
+
read.loading = false;
|
|
387
|
+
error = err;
|
|
388
|
+
p = null;
|
|
389
|
+
notifySuspense(contexts);
|
|
355
390
|
});
|
|
356
391
|
return;
|
|
357
392
|
}
|
|
@@ -414,13 +449,14 @@ function SuspenseList(props) {
|
|
|
414
449
|
return props.children;
|
|
415
450
|
}
|
|
416
451
|
function Suspense(props) {
|
|
452
|
+
let done;
|
|
417
453
|
const ctx = sharedConfig.context;
|
|
418
454
|
const id = ctx.id + ctx.count;
|
|
419
|
-
const done = ctx.async ? ctx.registerFragment(id) : () => {};
|
|
420
455
|
const o = Owner;
|
|
421
456
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
422
457
|
resources: new Map(),
|
|
423
458
|
completed: () => {
|
|
459
|
+
if (ctx.dataOnly) return done();
|
|
424
460
|
const res = runSuspense();
|
|
425
461
|
if (suspenseComplete(value)) {
|
|
426
462
|
done(resolveSSRNode(res));
|
|
@@ -441,12 +477,13 @@ function Suspense(props) {
|
|
|
441
477
|
});
|
|
442
478
|
}
|
|
443
479
|
const res = runSuspense();
|
|
444
|
-
if (suspenseComplete(value))
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
480
|
+
if (suspenseComplete(value)) return res;
|
|
481
|
+
onError(err => {
|
|
482
|
+
if (!done || !done(undefined, err)) throw err;
|
|
483
|
+
});
|
|
484
|
+
done = ctx.async ? ctx.registerFragment(id) : undefined;
|
|
485
|
+
if (ctx.streaming) {
|
|
486
|
+
if (!ctx.dataOnly) {
|
|
450
487
|
setHydrateContext(undefined);
|
|
451
488
|
const res = {
|
|
452
489
|
t: `<span id="pl${id}">${resolveSSRNode(props.fallback)}</span>`
|
|
@@ -454,6 +491,7 @@ function Suspense(props) {
|
|
|
454
491
|
setHydrateContext(ctx);
|
|
455
492
|
return res;
|
|
456
493
|
}
|
|
494
|
+
} else if (ctx.async) {
|
|
457
495
|
return {
|
|
458
496
|
t: `<![${id}]>`
|
|
459
497
|
};
|
package/dist/solid.cjs
CHANGED
|
@@ -1246,7 +1246,11 @@ function Match(props) {
|
|
|
1246
1246
|
return props;
|
|
1247
1247
|
}
|
|
1248
1248
|
function ErrorBoundary(props) {
|
|
1249
|
-
|
|
1249
|
+
let err = undefined;
|
|
1250
|
+
if (sharedConfig.context && sharedConfig.load) {
|
|
1251
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1252
|
+
}
|
|
1253
|
+
const [errored, setErrored] = createSignal(err);
|
|
1250
1254
|
let e;
|
|
1251
1255
|
return createMemo(() => {
|
|
1252
1256
|
if ((e = errored()) != null) {
|
|
@@ -1330,7 +1334,8 @@ function Suspense(props) {
|
|
|
1330
1334
|
showFallback,
|
|
1331
1335
|
ctx,
|
|
1332
1336
|
waitingHydration,
|
|
1333
|
-
flicker
|
|
1337
|
+
flicker,
|
|
1338
|
+
error;
|
|
1334
1339
|
const [inFallback, setFallback] = createSignal(false),
|
|
1335
1340
|
SuspenseContext = getSuspenseContext(),
|
|
1336
1341
|
store = {
|
|
@@ -1345,7 +1350,7 @@ function Suspense(props) {
|
|
|
1345
1350
|
resolved: false
|
|
1346
1351
|
},
|
|
1347
1352
|
owner = getOwner();
|
|
1348
|
-
if (sharedConfig.context
|
|
1353
|
+
if (sharedConfig.context) {
|
|
1349
1354
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1350
1355
|
const p = sharedConfig.load(key);
|
|
1351
1356
|
if (p) {
|
|
@@ -1353,7 +1358,8 @@ function Suspense(props) {
|
|
|
1353
1358
|
equals: false
|
|
1354
1359
|
});
|
|
1355
1360
|
flicker = s;
|
|
1356
|
-
p.then(
|
|
1361
|
+
p.then(err => {
|
|
1362
|
+
if (error = err) return set();
|
|
1357
1363
|
sharedConfig.gather(key);
|
|
1358
1364
|
waitingHydration = true;
|
|
1359
1365
|
setHydrateContext(ctx);
|
|
@@ -1371,6 +1377,7 @@ function Suspense(props) {
|
|
|
1371
1377
|
value: store,
|
|
1372
1378
|
get children() {
|
|
1373
1379
|
return createMemo(() => {
|
|
1380
|
+
if (error) throw error;
|
|
1374
1381
|
if (flicker) {
|
|
1375
1382
|
ctx = sharedConfig.context;
|
|
1376
1383
|
flicker();
|
package/dist/solid.js
CHANGED
|
@@ -1242,7 +1242,11 @@ function Match(props) {
|
|
|
1242
1242
|
return props;
|
|
1243
1243
|
}
|
|
1244
1244
|
function ErrorBoundary(props) {
|
|
1245
|
-
|
|
1245
|
+
let err = undefined;
|
|
1246
|
+
if (sharedConfig.context && sharedConfig.load) {
|
|
1247
|
+
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
|
|
1248
|
+
}
|
|
1249
|
+
const [errored, setErrored] = createSignal(err);
|
|
1246
1250
|
let e;
|
|
1247
1251
|
return createMemo(() => {
|
|
1248
1252
|
if ((e = errored()) != null) {
|
|
@@ -1326,7 +1330,8 @@ function Suspense(props) {
|
|
|
1326
1330
|
showFallback,
|
|
1327
1331
|
ctx,
|
|
1328
1332
|
waitingHydration,
|
|
1329
|
-
flicker
|
|
1333
|
+
flicker,
|
|
1334
|
+
error;
|
|
1330
1335
|
const [inFallback, setFallback] = createSignal(false),
|
|
1331
1336
|
SuspenseContext = getSuspenseContext(),
|
|
1332
1337
|
store = {
|
|
@@ -1341,7 +1346,7 @@ function Suspense(props) {
|
|
|
1341
1346
|
resolved: false
|
|
1342
1347
|
},
|
|
1343
1348
|
owner = getOwner();
|
|
1344
|
-
if (sharedConfig.context
|
|
1349
|
+
if (sharedConfig.context) {
|
|
1345
1350
|
const key = sharedConfig.context.id + sharedConfig.context.count;
|
|
1346
1351
|
const p = sharedConfig.load(key);
|
|
1347
1352
|
if (p) {
|
|
@@ -1349,7 +1354,8 @@ function Suspense(props) {
|
|
|
1349
1354
|
equals: false
|
|
1350
1355
|
});
|
|
1351
1356
|
flicker = s;
|
|
1352
|
-
p.then(
|
|
1357
|
+
p.then(err => {
|
|
1358
|
+
if (error = err) return set();
|
|
1353
1359
|
sharedConfig.gather(key);
|
|
1354
1360
|
waitingHydration = true;
|
|
1355
1361
|
setHydrateContext(ctx);
|
|
@@ -1367,6 +1373,7 @@ function Suspense(props) {
|
|
|
1367
1373
|
value: store,
|
|
1368
1374
|
get children() {
|
|
1369
1375
|
return createMemo(() => {
|
|
1376
|
+
if (error) throw error;
|
|
1370
1377
|
if (flicker) {
|
|
1371
1378
|
ctx = sharedConfig.context;
|
|
1372
1379
|
flicker();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.3.0-beta.
|
|
4
|
+
"version": "1.3.0-beta.3",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://solidjs.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/solidjs/solid"
|
|
@@ -36,10 +36,6 @@
|
|
|
36
36
|
],
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"development": {
|
|
40
|
-
"import": "./dist/dev.js",
|
|
41
|
-
"require": "./dist/dev.cjs"
|
|
42
|
-
},
|
|
43
39
|
"browser": {
|
|
44
40
|
"import": "./dist/solid.js",
|
|
45
41
|
"require": "./dist/solid.cjs"
|
|
@@ -48,15 +44,15 @@
|
|
|
48
44
|
"import": "./dist/server.js",
|
|
49
45
|
"require": "./dist/server.cjs"
|
|
50
46
|
},
|
|
47
|
+
"development": {
|
|
48
|
+
"import": "./dist/dev.js",
|
|
49
|
+
"require": "./dist/dev.cjs"
|
|
50
|
+
},
|
|
51
51
|
"import": "./dist/solid.js",
|
|
52
52
|
"require": "./dist/solid.cjs"
|
|
53
53
|
},
|
|
54
54
|
"./dist/*": "./dist/*",
|
|
55
55
|
"./store": {
|
|
56
|
-
"development": {
|
|
57
|
-
"import": "./store/dist/dev.js",
|
|
58
|
-
"require": "./store/dist/dev.cjs"
|
|
59
|
-
},
|
|
60
56
|
"browser": {
|
|
61
57
|
"import": "./store/dist/store.js",
|
|
62
58
|
"require": "./store/dist/store.cjs"
|
|
@@ -65,15 +61,15 @@
|
|
|
65
61
|
"import": "./store/dist/server.js",
|
|
66
62
|
"require": "./store/dist/server.cjs"
|
|
67
63
|
},
|
|
64
|
+
"development": {
|
|
65
|
+
"import": "./store/dist/dev.js",
|
|
66
|
+
"require": "./store/dist/dev.cjs"
|
|
67
|
+
},
|
|
68
68
|
"import": "./store/dist/store.js",
|
|
69
69
|
"require": "./store/dist/store.cjs"
|
|
70
70
|
},
|
|
71
71
|
"./store/dist/*": "./store/dist/*",
|
|
72
72
|
"./web": {
|
|
73
|
-
"development": {
|
|
74
|
-
"import": "./web/dist/dev.js",
|
|
75
|
-
"require": "./web/dist/dev.cjs"
|
|
76
|
-
},
|
|
77
73
|
"browser": {
|
|
78
74
|
"import": "./web/dist/web.js",
|
|
79
75
|
"require": "./web/dist/web.cjs"
|
|
@@ -82,6 +78,10 @@
|
|
|
82
78
|
"import": "./web/dist/server.js",
|
|
83
79
|
"require": "./web/dist/server.cjs"
|
|
84
80
|
},
|
|
81
|
+
"development": {
|
|
82
|
+
"import": "./web/dist/dev.js",
|
|
83
|
+
"require": "./web/dist/dev.cjs"
|
|
84
|
+
},
|
|
85
85
|
"import": "./web/dist/web.js",
|
|
86
86
|
"require": "./web/dist/web.cjs"
|
|
87
87
|
},
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
"compiler",
|
|
133
133
|
"performance"
|
|
134
134
|
],
|
|
135
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "cc2f8e5d0a8916ee1d4512de541268d8dcd45032"
|
|
136
136
|
}
|
|
@@ -56,9 +56,9 @@ declare type MatchProps<T> = {
|
|
|
56
56
|
};
|
|
57
57
|
export declare function Match<T>(props: MatchProps<T>): MatchProps<T>;
|
|
58
58
|
export declare function ErrorBoundary(props: {
|
|
59
|
-
fallback: string | ((err: any) => string);
|
|
59
|
+
fallback: string | ((err: any, reset: () => void) => string);
|
|
60
60
|
children: string;
|
|
61
|
-
}):
|
|
61
|
+
}): any;
|
|
62
62
|
export interface Resource<T> {
|
|
63
63
|
(): T | undefined;
|
|
64
64
|
loading: boolean;
|
|
@@ -91,12 +91,13 @@ export declare function useTransition(): [() => boolean, (fn: () => any) => void
|
|
|
91
91
|
declare type HydrationContext = {
|
|
92
92
|
id: string;
|
|
93
93
|
count: number;
|
|
94
|
-
writeResource?: (id: string, v: Promise<any>) => void;
|
|
94
|
+
writeResource?: (id: string, v: Promise<any> | any, error?: boolean) => void;
|
|
95
95
|
resources: Record<string, any>;
|
|
96
96
|
suspense: Record<string, SuspenseContextType>;
|
|
97
|
-
registerFragment: (v: string) => (v?: string) =>
|
|
97
|
+
registerFragment: (v: string) => (v?: string, err?: any) => boolean;
|
|
98
98
|
async?: boolean;
|
|
99
99
|
streaming?: boolean;
|
|
100
|
+
dataOnly?: boolean;
|
|
100
101
|
noHydrate: boolean;
|
|
101
102
|
};
|
|
102
103
|
export declare function SuspenseList(props: {
|
|
@@ -105,7 +106,7 @@ export declare function SuspenseList(props: {
|
|
|
105
106
|
tail?: "collapsed" | "hidden";
|
|
106
107
|
}): string;
|
|
107
108
|
export declare function Suspense(props: {
|
|
108
|
-
fallback
|
|
109
|
+
fallback?: string;
|
|
109
110
|
children: string;
|
|
110
111
|
}): any;
|
|
111
112
|
export {};
|
package/web/dist/dev.cjs
CHANGED
|
@@ -382,8 +382,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
382
382
|
return () => current;
|
|
383
383
|
}
|
|
384
384
|
if (solidJs.sharedConfig.context && current && current.length) {
|
|
385
|
-
for (let i; i < array.length; i++) {
|
|
386
|
-
if (array[i].parentNode) return array;
|
|
385
|
+
for (let i = 0; i < array.length; i++) {
|
|
386
|
+
if (array[i].parentNode) return current = array;
|
|
387
387
|
}
|
|
388
388
|
return current;
|
|
389
389
|
}
|
package/web/dist/dev.js
CHANGED
|
@@ -379,8 +379,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
379
379
|
return () => current;
|
|
380
380
|
}
|
|
381
381
|
if (sharedConfig.context && current && current.length) {
|
|
382
|
-
for (let i; i < array.length; i++) {
|
|
383
|
-
if (array[i].parentNode) return array;
|
|
382
|
+
for (let i = 0; i < array.length; i++) {
|
|
383
|
+
if (array[i].parentNode) return current = array;
|
|
384
384
|
}
|
|
385
385
|
return current;
|
|
386
386
|
}
|
package/web/dist/server.cjs
CHANGED
|
@@ -232,17 +232,23 @@ function stringifyString(str) {
|
|
|
232
232
|
return result;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
const REPLACE_SCRIPT = `function $df(e,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e)}`;
|
|
235
|
+
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
|
|
236
|
+
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
236
237
|
function renderToString(code, options = {}) {
|
|
238
|
+
let scripts = "";
|
|
237
239
|
solidJs.sharedConfig.context = {
|
|
238
240
|
id: "",
|
|
239
241
|
count: 0,
|
|
240
242
|
suspense: {},
|
|
241
243
|
assets: [],
|
|
242
|
-
nonce: options.nonce
|
|
244
|
+
nonce: options.nonce,
|
|
245
|
+
writeResource(id, p, error) {
|
|
246
|
+
if (error) scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
247
|
+
}
|
|
243
248
|
};
|
|
244
|
-
let html = resolveSSRNode(escape(code()));
|
|
245
|
-
|
|
249
|
+
let html = injectAssets(solidJs.sharedConfig.context.assets, resolveSSRNode(escape(code())));
|
|
250
|
+
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
251
|
+
return html;
|
|
246
252
|
}
|
|
247
253
|
function renderToStringAsync(code, options = {}) {
|
|
248
254
|
const {
|
|
@@ -259,23 +265,55 @@ function renderToStringAsync(code, options = {}) {
|
|
|
259
265
|
nonce
|
|
260
266
|
};
|
|
261
267
|
let scripts = "";
|
|
262
|
-
solidJs.sharedConfig.context.writeResource = (id, p) =>
|
|
268
|
+
solidJs.sharedConfig.context.writeResource = (id, p, error) => {
|
|
269
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
270
|
+
p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", null);`);
|
|
271
|
+
};
|
|
263
272
|
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
273
|
+
function asyncWrap(fn) {
|
|
274
|
+
return new Promise(resolve => {
|
|
275
|
+
const registry = new Set();
|
|
276
|
+
const cache = Object.create(null);
|
|
277
|
+
solidJs.sharedConfig.context.registerFragment = register;
|
|
278
|
+
const rendered = fn();
|
|
279
|
+
if (!registry.size) resolve(rendered);
|
|
280
|
+
function register(key) {
|
|
281
|
+
registry.add(key);
|
|
282
|
+
return (value = "", error) => {
|
|
283
|
+
cache[key] = value;
|
|
284
|
+
registry.delete(key);
|
|
285
|
+
if (error) return scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;
|
|
286
|
+
if (!registry.size) Promise.resolve().then(() => {
|
|
287
|
+
let source = resolveSSRNode(rendered);
|
|
288
|
+
let final = "";
|
|
289
|
+
let match;
|
|
290
|
+
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
291
|
+
final += source.substring(0, match.index);
|
|
292
|
+
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
293
|
+
}
|
|
294
|
+
resolve(final + source);
|
|
295
|
+
});
|
|
296
|
+
return true;
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
264
301
|
return Promise.race([asyncWrap(() => escape(code())), timeout]).then(res => {
|
|
265
302
|
let html = injectAssets(context.assets, resolveSSRNode(res));
|
|
266
303
|
if (scripts.length) html = injectScripts(html, scripts, nonce);
|
|
267
304
|
return html;
|
|
268
305
|
});
|
|
269
306
|
}
|
|
270
|
-
function renderToPipeableStream(code, options) {
|
|
307
|
+
function renderToPipeableStream(code, options = {}) {
|
|
271
308
|
const {
|
|
272
309
|
nonce,
|
|
273
310
|
onCompleteShell,
|
|
274
|
-
onCompleteAll
|
|
311
|
+
onCompleteAll,
|
|
312
|
+
dataOnly
|
|
275
313
|
} = options;
|
|
276
314
|
const tmp = [];
|
|
277
315
|
const tasks = [];
|
|
278
|
-
const registry = new
|
|
316
|
+
const registry = new Map();
|
|
279
317
|
const checkEnd = () => {
|
|
280
318
|
if (!registry.size && !completed) {
|
|
281
319
|
onCompleteAll && onCompleteAll(result);
|
|
@@ -284,7 +322,7 @@ function renderToPipeableStream(code, options) {
|
|
|
284
322
|
}
|
|
285
323
|
};
|
|
286
324
|
const writeInitialScript = () => {
|
|
287
|
-
if (tasks.length) {
|
|
325
|
+
if (tasks.length && !completed) {
|
|
288
326
|
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`);
|
|
289
327
|
tasks.length = 0;
|
|
290
328
|
}
|
|
@@ -304,37 +342,43 @@ function renderToPipeableStream(code, options) {
|
|
|
304
342
|
count: 0,
|
|
305
343
|
async: true,
|
|
306
344
|
streaming: true,
|
|
345
|
+
dataOnly,
|
|
307
346
|
resources: {},
|
|
308
347
|
suspense: {},
|
|
309
348
|
assets: [],
|
|
310
349
|
nonce,
|
|
311
|
-
writeResource(id, p) {
|
|
350
|
+
writeResource(id, p, error) {
|
|
312
351
|
if (!scheduled) {
|
|
313
352
|
Promise.resolve().then(writeInitialScript);
|
|
314
353
|
scheduled = true;
|
|
315
354
|
}
|
|
355
|
+
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
316
356
|
tasks.push(`_$HY.init("${id}")`);
|
|
317
357
|
p.then(d => {
|
|
318
|
-
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
358
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
359
|
+
}).catch(() => {
|
|
360
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null)</script>`);
|
|
319
361
|
});
|
|
320
362
|
},
|
|
321
363
|
registerFragment(key) {
|
|
322
|
-
registry.
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
scheduled = true;
|
|
328
|
-
}
|
|
329
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
364
|
+
registry.set(key, []);
|
|
365
|
+
if (!dataOnly) {
|
|
366
|
+
if (!scheduled) {
|
|
367
|
+
Promise.resolve().then(writeInitialScript);
|
|
368
|
+
scheduled = true;
|
|
330
369
|
}
|
|
331
|
-
|
|
332
|
-
|
|
370
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
371
|
+
}
|
|
372
|
+
return (value, error) => {
|
|
373
|
+
const keys = registry.get(key);
|
|
333
374
|
registry.delete(key);
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
375
|
+
if (waitForFragments(registry, key)) return;
|
|
376
|
+
if ((value !== undefined || error) && !completed) {
|
|
377
|
+
buffer.write(`<div hidden id="${key}">${value !== undefined ? value : " "}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}${keys.length ? keys.map(k => `_$HY.unset("${k}");`) : ""}$df("${key}"${error ? "," + serializeError(error) : ""})</script>`);
|
|
378
|
+
scriptFlushed = true;
|
|
379
|
+
}
|
|
337
380
|
checkEnd();
|
|
381
|
+
return true;
|
|
338
382
|
};
|
|
339
383
|
}
|
|
340
384
|
};
|
|
@@ -361,13 +405,14 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
361
405
|
onCompleteShell = ({
|
|
362
406
|
startWriting
|
|
363
407
|
}) => startWriting(),
|
|
364
|
-
onCompleteAll
|
|
408
|
+
onCompleteAll,
|
|
409
|
+
dataOnly
|
|
365
410
|
} = options;
|
|
366
411
|
const tmp = [];
|
|
367
412
|
const tasks = [];
|
|
368
413
|
const writer = writable.getWriter();
|
|
369
414
|
const encoder = new TextEncoder();
|
|
370
|
-
const registry = new
|
|
415
|
+
const registry = new Map();
|
|
371
416
|
const checkEnd = () => {
|
|
372
417
|
if (!registry.size && !completed) {
|
|
373
418
|
onCompleteAll && onCompleteAll(result);
|
|
@@ -409,37 +454,43 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
409
454
|
count: 0,
|
|
410
455
|
async: true,
|
|
411
456
|
streaming: true,
|
|
457
|
+
dataOnly,
|
|
412
458
|
resources: {},
|
|
413
459
|
suspense: {},
|
|
414
460
|
assets: [],
|
|
415
461
|
nonce,
|
|
416
|
-
writeResource(id, p) {
|
|
462
|
+
writeResource(id, p, error) {
|
|
417
463
|
if (!scheduled) {
|
|
418
464
|
Promise.resolve().then(writeInitialScript);
|
|
419
465
|
scheduled = true;
|
|
420
466
|
}
|
|
467
|
+
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
421
468
|
tasks.push(`_$HY.init("${id}")`);
|
|
422
469
|
p.then(d => {
|
|
423
|
-
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
|
|
470
|
+
!completed && buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
|
|
471
|
+
}).catch(() => {
|
|
472
|
+
!completed && buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null)</script>`));
|
|
424
473
|
});
|
|
425
474
|
},
|
|
426
475
|
registerFragment(key) {
|
|
427
|
-
registry.
|
|
428
|
-
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
scheduled = true;
|
|
433
|
-
}
|
|
434
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
476
|
+
registry.set(key, []);
|
|
477
|
+
if (!dataOnly) {
|
|
478
|
+
if (!scheduled) {
|
|
479
|
+
Promise.resolve().then(writeInitialScript);
|
|
480
|
+
scheduled = true;
|
|
435
481
|
}
|
|
436
|
-
|
|
437
|
-
|
|
482
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
483
|
+
}
|
|
484
|
+
return (value, error) => {
|
|
485
|
+
const keys = registry.get(key);
|
|
438
486
|
registry.delete(key);
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
|
|
487
|
+
if (waitForFragments(registry, key)) return;
|
|
488
|
+
if ((value !== undefined || error) && !completed) {
|
|
489
|
+
buffer.write(encoder.encode(`<div hidden id="${key}">${value !== undefined ? value : " "}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}${keys.length ? keys.map(k => `_$HY.unset("${k}");`) : ""}$df("${key}"${error ? "," + serializeError(error) : ""})</script>`));
|
|
490
|
+
scriptFlushed = true;
|
|
491
|
+
}
|
|
442
492
|
checkEnd();
|
|
493
|
+
return true;
|
|
443
494
|
};
|
|
444
495
|
}
|
|
445
496
|
};
|
|
@@ -612,7 +663,7 @@ function generateHydrationScript({
|
|
|
612
663
|
eventNames = ["click", "input"],
|
|
613
664
|
nonce
|
|
614
665
|
}) {
|
|
615
|
-
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 n=o.composedPath&&o.composedPath()[0]||o.target,s=t(n);s&&!e.completed.has(s)&&e.events.push([s,o])})))),e.init=(e,t)=>{o[e]=[new Promise((e=>t=e)),t]},e.set=(e,t,n)=>{if(!(n=o[e]))return o[e]=[t];n[1](t)},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet}))
|
|
666
|
+
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 n=o.composedPath&&o.composedPath()[0]||o.target,s=t(n);s&&!e.completed.has(s)&&e.events.push([s,o])})))),e.init=(e,t)=>{o[e]=[new Promise((e=>t=e)),t]},e.set=(e,t,n)=>{if(!(n=o[e]))return o[e]=[t];n[1](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>`;
|
|
616
667
|
}
|
|
617
668
|
function injectAssets(assets, html) {
|
|
618
669
|
for (let i = 0; i < assets.length; i++) {
|
|
@@ -628,32 +679,17 @@ function injectScripts(html, scripts, nonce) {
|
|
|
628
679
|
}
|
|
629
680
|
return html + tag;
|
|
630
681
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
function register(key) {
|
|
640
|
-
registry.add(key);
|
|
641
|
-
return value => {
|
|
642
|
-
if (value) cache[key] = value;
|
|
643
|
-
registry.delete(key);
|
|
644
|
-
if (!registry.size) Promise.resolve().then(() => {
|
|
645
|
-
let source = resolveSSRNode(rendered);
|
|
646
|
-
let final = "";
|
|
647
|
-
let match;
|
|
648
|
-
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
649
|
-
final += source.substring(0, match.index);
|
|
650
|
-
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
651
|
-
}
|
|
652
|
-
resolve(final + source);
|
|
653
|
-
});
|
|
654
|
-
};
|
|
682
|
+
function serializeError(error) {
|
|
683
|
+
return error.message ? `new Error(${devalue(error.message)})` : devalue(error);
|
|
684
|
+
}
|
|
685
|
+
function waitForFragments(registry, key) {
|
|
686
|
+
for (const k of [...registry.keys()].reverse()) {
|
|
687
|
+
if (key.startsWith(k)) {
|
|
688
|
+
registry.get(k).push(key);
|
|
689
|
+
return true;
|
|
655
690
|
}
|
|
656
|
-
}
|
|
691
|
+
}
|
|
692
|
+
return false;
|
|
657
693
|
}
|
|
658
694
|
|
|
659
695
|
const isServer = true;
|
package/web/dist/server.js
CHANGED
|
@@ -229,17 +229,23 @@ function stringifyString(str) {
|
|
|
229
229
|
return result;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
const REPLACE_SCRIPT = `function $df(e,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e)}`;
|
|
232
|
+
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
|
|
233
|
+
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
233
234
|
function renderToString(code, options = {}) {
|
|
235
|
+
let scripts = "";
|
|
234
236
|
sharedConfig.context = {
|
|
235
237
|
id: "",
|
|
236
238
|
count: 0,
|
|
237
239
|
suspense: {},
|
|
238
240
|
assets: [],
|
|
239
|
-
nonce: options.nonce
|
|
241
|
+
nonce: options.nonce,
|
|
242
|
+
writeResource(id, p, error) {
|
|
243
|
+
if (error) scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
244
|
+
}
|
|
240
245
|
};
|
|
241
|
-
let html = resolveSSRNode(escape(code()));
|
|
242
|
-
|
|
246
|
+
let html = injectAssets(sharedConfig.context.assets, resolveSSRNode(escape(code())));
|
|
247
|
+
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
248
|
+
return html;
|
|
243
249
|
}
|
|
244
250
|
function renderToStringAsync(code, options = {}) {
|
|
245
251
|
const {
|
|
@@ -256,23 +262,55 @@ function renderToStringAsync(code, options = {}) {
|
|
|
256
262
|
nonce
|
|
257
263
|
};
|
|
258
264
|
let scripts = "";
|
|
259
|
-
sharedConfig.context.writeResource = (id, p) =>
|
|
265
|
+
sharedConfig.context.writeResource = (id, p, error) => {
|
|
266
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
267
|
+
p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", null);`);
|
|
268
|
+
};
|
|
260
269
|
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
270
|
+
function asyncWrap(fn) {
|
|
271
|
+
return new Promise(resolve => {
|
|
272
|
+
const registry = new Set();
|
|
273
|
+
const cache = Object.create(null);
|
|
274
|
+
sharedConfig.context.registerFragment = register;
|
|
275
|
+
const rendered = fn();
|
|
276
|
+
if (!registry.size) resolve(rendered);
|
|
277
|
+
function register(key) {
|
|
278
|
+
registry.add(key);
|
|
279
|
+
return (value = "", error) => {
|
|
280
|
+
cache[key] = value;
|
|
281
|
+
registry.delete(key);
|
|
282
|
+
if (error) return scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;
|
|
283
|
+
if (!registry.size) Promise.resolve().then(() => {
|
|
284
|
+
let source = resolveSSRNode(rendered);
|
|
285
|
+
let final = "";
|
|
286
|
+
let match;
|
|
287
|
+
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
288
|
+
final += source.substring(0, match.index);
|
|
289
|
+
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
290
|
+
}
|
|
291
|
+
resolve(final + source);
|
|
292
|
+
});
|
|
293
|
+
return true;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
261
298
|
return Promise.race([asyncWrap(() => escape(code())), timeout]).then(res => {
|
|
262
299
|
let html = injectAssets(context.assets, resolveSSRNode(res));
|
|
263
300
|
if (scripts.length) html = injectScripts(html, scripts, nonce);
|
|
264
301
|
return html;
|
|
265
302
|
});
|
|
266
303
|
}
|
|
267
|
-
function renderToPipeableStream(code, options) {
|
|
304
|
+
function renderToPipeableStream(code, options = {}) {
|
|
268
305
|
const {
|
|
269
306
|
nonce,
|
|
270
307
|
onCompleteShell,
|
|
271
|
-
onCompleteAll
|
|
308
|
+
onCompleteAll,
|
|
309
|
+
dataOnly
|
|
272
310
|
} = options;
|
|
273
311
|
const tmp = [];
|
|
274
312
|
const tasks = [];
|
|
275
|
-
const registry = new
|
|
313
|
+
const registry = new Map();
|
|
276
314
|
const checkEnd = () => {
|
|
277
315
|
if (!registry.size && !completed) {
|
|
278
316
|
onCompleteAll && onCompleteAll(result);
|
|
@@ -281,7 +319,7 @@ function renderToPipeableStream(code, options) {
|
|
|
281
319
|
}
|
|
282
320
|
};
|
|
283
321
|
const writeInitialScript = () => {
|
|
284
|
-
if (tasks.length) {
|
|
322
|
+
if (tasks.length && !completed) {
|
|
285
323
|
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`);
|
|
286
324
|
tasks.length = 0;
|
|
287
325
|
}
|
|
@@ -301,37 +339,43 @@ function renderToPipeableStream(code, options) {
|
|
|
301
339
|
count: 0,
|
|
302
340
|
async: true,
|
|
303
341
|
streaming: true,
|
|
342
|
+
dataOnly,
|
|
304
343
|
resources: {},
|
|
305
344
|
suspense: {},
|
|
306
345
|
assets: [],
|
|
307
346
|
nonce,
|
|
308
|
-
writeResource(id, p) {
|
|
347
|
+
writeResource(id, p, error) {
|
|
309
348
|
if (!scheduled) {
|
|
310
349
|
Promise.resolve().then(writeInitialScript);
|
|
311
350
|
scheduled = true;
|
|
312
351
|
}
|
|
352
|
+
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
313
353
|
tasks.push(`_$HY.init("${id}")`);
|
|
314
354
|
p.then(d => {
|
|
315
|
-
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
355
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
356
|
+
}).catch(() => {
|
|
357
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null)</script>`);
|
|
316
358
|
});
|
|
317
359
|
},
|
|
318
360
|
registerFragment(key) {
|
|
319
|
-
registry.
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
scheduled = true;
|
|
325
|
-
}
|
|
326
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
361
|
+
registry.set(key, []);
|
|
362
|
+
if (!dataOnly) {
|
|
363
|
+
if (!scheduled) {
|
|
364
|
+
Promise.resolve().then(writeInitialScript);
|
|
365
|
+
scheduled = true;
|
|
327
366
|
}
|
|
328
|
-
|
|
329
|
-
|
|
367
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
368
|
+
}
|
|
369
|
+
return (value, error) => {
|
|
370
|
+
const keys = registry.get(key);
|
|
330
371
|
registry.delete(key);
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
372
|
+
if (waitForFragments(registry, key)) return;
|
|
373
|
+
if ((value !== undefined || error) && !completed) {
|
|
374
|
+
buffer.write(`<div hidden id="${key}">${value !== undefined ? value : " "}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}${keys.length ? keys.map(k => `_$HY.unset("${k}");`) : ""}$df("${key}"${error ? "," + serializeError(error) : ""})</script>`);
|
|
375
|
+
scriptFlushed = true;
|
|
376
|
+
}
|
|
334
377
|
checkEnd();
|
|
378
|
+
return true;
|
|
335
379
|
};
|
|
336
380
|
}
|
|
337
381
|
};
|
|
@@ -358,13 +402,14 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
358
402
|
onCompleteShell = ({
|
|
359
403
|
startWriting
|
|
360
404
|
}) => startWriting(),
|
|
361
|
-
onCompleteAll
|
|
405
|
+
onCompleteAll,
|
|
406
|
+
dataOnly
|
|
362
407
|
} = options;
|
|
363
408
|
const tmp = [];
|
|
364
409
|
const tasks = [];
|
|
365
410
|
const writer = writable.getWriter();
|
|
366
411
|
const encoder = new TextEncoder();
|
|
367
|
-
const registry = new
|
|
412
|
+
const registry = new Map();
|
|
368
413
|
const checkEnd = () => {
|
|
369
414
|
if (!registry.size && !completed) {
|
|
370
415
|
onCompleteAll && onCompleteAll(result);
|
|
@@ -406,37 +451,43 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
406
451
|
count: 0,
|
|
407
452
|
async: true,
|
|
408
453
|
streaming: true,
|
|
454
|
+
dataOnly,
|
|
409
455
|
resources: {},
|
|
410
456
|
suspense: {},
|
|
411
457
|
assets: [],
|
|
412
458
|
nonce,
|
|
413
|
-
writeResource(id, p) {
|
|
459
|
+
writeResource(id, p, error) {
|
|
414
460
|
if (!scheduled) {
|
|
415
461
|
Promise.resolve().then(writeInitialScript);
|
|
416
462
|
scheduled = true;
|
|
417
463
|
}
|
|
464
|
+
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
418
465
|
tasks.push(`_$HY.init("${id}")`);
|
|
419
466
|
p.then(d => {
|
|
420
|
-
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
|
|
467
|
+
!completed && buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
|
|
468
|
+
}).catch(() => {
|
|
469
|
+
!completed && buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null)</script>`));
|
|
421
470
|
});
|
|
422
471
|
},
|
|
423
472
|
registerFragment(key) {
|
|
424
|
-
registry.
|
|
425
|
-
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
scheduled = true;
|
|
430
|
-
}
|
|
431
|
-
tasks.push(`_$HY.init("${key}")`);
|
|
473
|
+
registry.set(key, []);
|
|
474
|
+
if (!dataOnly) {
|
|
475
|
+
if (!scheduled) {
|
|
476
|
+
Promise.resolve().then(writeInitialScript);
|
|
477
|
+
scheduled = true;
|
|
432
478
|
}
|
|
433
|
-
|
|
434
|
-
|
|
479
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
480
|
+
}
|
|
481
|
+
return (value, error) => {
|
|
482
|
+
const keys = registry.get(key);
|
|
435
483
|
registry.delete(key);
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
|
|
484
|
+
if (waitForFragments(registry, key)) return;
|
|
485
|
+
if ((value !== undefined || error) && !completed) {
|
|
486
|
+
buffer.write(encoder.encode(`<div hidden id="${key}">${value !== undefined ? value : " "}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}${keys.length ? keys.map(k => `_$HY.unset("${k}");`) : ""}$df("${key}"${error ? "," + serializeError(error) : ""})</script>`));
|
|
487
|
+
scriptFlushed = true;
|
|
488
|
+
}
|
|
439
489
|
checkEnd();
|
|
490
|
+
return true;
|
|
440
491
|
};
|
|
441
492
|
}
|
|
442
493
|
};
|
|
@@ -609,7 +660,7 @@ function generateHydrationScript({
|
|
|
609
660
|
eventNames = ["click", "input"],
|
|
610
661
|
nonce
|
|
611
662
|
}) {
|
|
612
|
-
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 n=o.composedPath&&o.composedPath()[0]||o.target,s=t(n);s&&!e.completed.has(s)&&e.events.push([s,o])})))),e.init=(e,t)=>{o[e]=[new Promise((e=>t=e)),t]},e.set=(e,t,n)=>{if(!(n=o[e]))return o[e]=[t];n[1](t)},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet}))
|
|
663
|
+
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 n=o.composedPath&&o.composedPath()[0]||o.target,s=t(n);s&&!e.completed.has(s)&&e.events.push([s,o])})))),e.init=(e,t)=>{o[e]=[new Promise((e=>t=e)),t]},e.set=(e,t,n)=>{if(!(n=o[e]))return o[e]=[t];n[1](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>`;
|
|
613
664
|
}
|
|
614
665
|
function injectAssets(assets, html) {
|
|
615
666
|
for (let i = 0; i < assets.length; i++) {
|
|
@@ -625,32 +676,17 @@ function injectScripts(html, scripts, nonce) {
|
|
|
625
676
|
}
|
|
626
677
|
return html + tag;
|
|
627
678
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
function register(key) {
|
|
637
|
-
registry.add(key);
|
|
638
|
-
return value => {
|
|
639
|
-
if (value) cache[key] = value;
|
|
640
|
-
registry.delete(key);
|
|
641
|
-
if (!registry.size) Promise.resolve().then(() => {
|
|
642
|
-
let source = resolveSSRNode(rendered);
|
|
643
|
-
let final = "";
|
|
644
|
-
let match;
|
|
645
|
-
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
646
|
-
final += source.substring(0, match.index);
|
|
647
|
-
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
648
|
-
}
|
|
649
|
-
resolve(final + source);
|
|
650
|
-
});
|
|
651
|
-
};
|
|
679
|
+
function serializeError(error) {
|
|
680
|
+
return error.message ? `new Error(${devalue(error.message)})` : devalue(error);
|
|
681
|
+
}
|
|
682
|
+
function waitForFragments(registry, key) {
|
|
683
|
+
for (const k of [...registry.keys()].reverse()) {
|
|
684
|
+
if (key.startsWith(k)) {
|
|
685
|
+
registry.get(k).push(key);
|
|
686
|
+
return true;
|
|
652
687
|
}
|
|
653
|
-
}
|
|
688
|
+
}
|
|
689
|
+
return false;
|
|
654
690
|
}
|
|
655
691
|
|
|
656
692
|
const isServer = true;
|
package/web/dist/web.cjs
CHANGED
|
@@ -381,8 +381,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
381
381
|
return () => current;
|
|
382
382
|
}
|
|
383
383
|
if (solidJs.sharedConfig.context && current && current.length) {
|
|
384
|
-
for (let i; i < array.length; i++) {
|
|
385
|
-
if (array[i].parentNode) return array;
|
|
384
|
+
for (let i = 0; i < array.length; i++) {
|
|
385
|
+
if (array[i].parentNode) return current = array;
|
|
386
386
|
}
|
|
387
387
|
return current;
|
|
388
388
|
}
|
package/web/dist/web.js
CHANGED
|
@@ -378,8 +378,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
378
378
|
return () => current;
|
|
379
379
|
}
|
|
380
380
|
if (sharedConfig.context && current && current.length) {
|
|
381
|
-
for (let i; i < array.length; i++) {
|
|
382
|
-
if (array[i].parentNode) return array;
|
|
381
|
+
for (let i = 0; i < array.length; i++) {
|
|
382
|
+
if (array[i].parentNode) return current = array;
|
|
383
383
|
}
|
|
384
384
|
return current;
|
|
385
385
|
}
|