solid-js 1.8.18 → 1.8.20
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 +34 -29
- package/dist/dev.js +47 -42
- package/dist/server.cjs +33 -11
- package/dist/server.js +34 -11
- package/dist/solid.cjs +34 -29
- package/dist/solid.js +44 -39
- package/package.json +3 -3
- package/types/jsx.d.ts +913 -862
- package/types/render/hydration.d.ts +2 -0
- package/types/server/rendering.d.ts +2 -0
- package/web/dist/dev.cjs +36 -21
- package/web/dist/dev.js +37 -24
- package/web/dist/server.cjs +4 -4
- package/web/dist/server.js +4 -4
- package/web/dist/web.cjs +34 -19
- package/web/dist/web.js +35 -22
package/dist/dev.cjs
CHANGED
|
@@ -118,15 +118,27 @@ function workLoop(hasTimeRemaining, initialTime) {
|
|
|
118
118
|
|
|
119
119
|
const sharedConfig = {
|
|
120
120
|
context: undefined,
|
|
121
|
-
registry: undefined
|
|
121
|
+
registry: undefined,
|
|
122
|
+
done: false,
|
|
123
|
+
getContextId() {
|
|
124
|
+
return getContextId(this.context.count);
|
|
125
|
+
},
|
|
126
|
+
getNextContextId() {
|
|
127
|
+
return getContextId(this.context.count++);
|
|
128
|
+
}
|
|
122
129
|
};
|
|
130
|
+
function getContextId(count) {
|
|
131
|
+
const num = String(count),
|
|
132
|
+
len = num.length - 1;
|
|
133
|
+
return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
|
|
134
|
+
}
|
|
123
135
|
function setHydrateContext(context) {
|
|
124
136
|
sharedConfig.context = context;
|
|
125
137
|
}
|
|
126
138
|
function nextHydrateContext() {
|
|
127
139
|
return {
|
|
128
140
|
...sharedConfig.context,
|
|
129
|
-
id:
|
|
141
|
+
id: sharedConfig.getNextContextId(),
|
|
130
142
|
count: 0
|
|
131
143
|
};
|
|
132
144
|
}
|
|
@@ -285,9 +297,8 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
285
297
|
}),
|
|
286
298
|
[state, setState] = createSignal(resolved ? "ready" : "unresolved");
|
|
287
299
|
if (sharedConfig.context) {
|
|
288
|
-
id =
|
|
289
|
-
|
|
290
|
-
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v;
|
|
300
|
+
id = sharedConfig.getNextContextId();
|
|
301
|
+
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id);
|
|
291
302
|
}
|
|
292
303
|
function loadEnd(p, v, error, key) {
|
|
293
304
|
if (pr === p) {
|
|
@@ -578,7 +589,8 @@ function createContext(defaultValue, options) {
|
|
|
578
589
|
};
|
|
579
590
|
}
|
|
580
591
|
function useContext(context) {
|
|
581
|
-
|
|
592
|
+
let value;
|
|
593
|
+
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined ? value : context.defaultValue;
|
|
582
594
|
}
|
|
583
595
|
function children(fn) {
|
|
584
596
|
const children = createMemo(fn);
|
|
@@ -1109,20 +1121,12 @@ function mapArray(list, mapFn, options = {}) {
|
|
|
1109
1121
|
onCleanup(() => dispose(disposers));
|
|
1110
1122
|
return () => {
|
|
1111
1123
|
let newItems = list() || [],
|
|
1124
|
+
newLen = newItems.length,
|
|
1112
1125
|
i,
|
|
1113
1126
|
j;
|
|
1114
1127
|
newItems[$TRACK];
|
|
1115
1128
|
return untrack(() => {
|
|
1116
|
-
let
|
|
1117
|
-
newIndices,
|
|
1118
|
-
newIndicesNext,
|
|
1119
|
-
temp,
|
|
1120
|
-
tempdisposers,
|
|
1121
|
-
tempIndexes,
|
|
1122
|
-
start,
|
|
1123
|
-
end,
|
|
1124
|
-
newEnd,
|
|
1125
|
-
item;
|
|
1129
|
+
let newIndices, newIndicesNext, temp, tempdisposers, tempIndexes, start, end, newEnd, item;
|
|
1126
1130
|
if (newLen === 0) {
|
|
1127
1131
|
if (len !== 0) {
|
|
1128
1132
|
dispose(disposers);
|
|
@@ -1214,10 +1218,11 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1214
1218
|
i;
|
|
1215
1219
|
onCleanup(() => dispose(disposers));
|
|
1216
1220
|
return () => {
|
|
1217
|
-
const newItems = list() || []
|
|
1221
|
+
const newItems = list() || [],
|
|
1222
|
+
newLen = newItems.length;
|
|
1218
1223
|
newItems[$TRACK];
|
|
1219
1224
|
return untrack(() => {
|
|
1220
|
-
if (
|
|
1225
|
+
if (newLen === 0) {
|
|
1221
1226
|
if (len !== 0) {
|
|
1222
1227
|
dispose(disposers);
|
|
1223
1228
|
disposers = [];
|
|
@@ -1243,7 +1248,7 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1243
1248
|
mapped = [];
|
|
1244
1249
|
len = 0;
|
|
1245
1250
|
}
|
|
1246
|
-
for (i = 0; i <
|
|
1251
|
+
for (i = 0; i < newLen; i++) {
|
|
1247
1252
|
if (i < items.length && items[i] !== newItems[i]) {
|
|
1248
1253
|
signals[i](() => newItems[i]);
|
|
1249
1254
|
} else if (i >= items.length) {
|
|
@@ -1253,7 +1258,7 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1253
1258
|
for (; i < items.length; i++) {
|
|
1254
1259
|
disposers[i]();
|
|
1255
1260
|
}
|
|
1256
|
-
len = signals.length = disposers.length =
|
|
1261
|
+
len = signals.length = disposers.length = newLen;
|
|
1257
1262
|
items = newItems.slice(0);
|
|
1258
1263
|
return mapped = mapped.slice(0, len);
|
|
1259
1264
|
});
|
|
@@ -1442,7 +1447,7 @@ function lazy(fn) {
|
|
|
1442
1447
|
sharedConfig.count || (sharedConfig.count = 0);
|
|
1443
1448
|
sharedConfig.count++;
|
|
1444
1449
|
(p || (p = fn())).then(mod => {
|
|
1445
|
-
setHydrateContext(ctx);
|
|
1450
|
+
!sharedConfig.done && setHydrateContext(ctx);
|
|
1446
1451
|
sharedConfig.count--;
|
|
1447
1452
|
set(() => mod.default);
|
|
1448
1453
|
setHydrateContext();
|
|
@@ -1453,17 +1458,17 @@ function lazy(fn) {
|
|
|
1453
1458
|
comp = s;
|
|
1454
1459
|
}
|
|
1455
1460
|
let Comp;
|
|
1456
|
-
return createMemo(() => (Comp = comp())
|
|
1461
|
+
return createMemo(() => (Comp = comp()) ? untrack(() => {
|
|
1457
1462
|
if (true) Object.assign(Comp, {
|
|
1458
1463
|
[$DEVCOMP]: true
|
|
1459
1464
|
});
|
|
1460
|
-
if (!ctx) return Comp(props);
|
|
1465
|
+
if (!ctx || sharedConfig.done) return Comp(props);
|
|
1461
1466
|
const c = sharedConfig.context;
|
|
1462
1467
|
setHydrateContext(ctx);
|
|
1463
1468
|
const r = Comp(props);
|
|
1464
1469
|
setHydrateContext(c);
|
|
1465
1470
|
return r;
|
|
1466
|
-
}));
|
|
1471
|
+
}) : "");
|
|
1467
1472
|
};
|
|
1468
1473
|
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
|
|
1469
1474
|
return wrap;
|
|
@@ -1471,7 +1476,7 @@ function lazy(fn) {
|
|
|
1471
1476
|
let counter = 0;
|
|
1472
1477
|
function createUniqueId() {
|
|
1473
1478
|
const ctx = sharedConfig.context;
|
|
1474
|
-
return ctx ?
|
|
1479
|
+
return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
|
|
1475
1480
|
}
|
|
1476
1481
|
|
|
1477
1482
|
const narrowedError = name => `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.` ;
|
|
@@ -1553,7 +1558,7 @@ function resetErrorBoundaries() {
|
|
|
1553
1558
|
}
|
|
1554
1559
|
function ErrorBoundary(props) {
|
|
1555
1560
|
let err;
|
|
1556
|
-
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.
|
|
1561
|
+
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.getContextId());
|
|
1557
1562
|
const [errored, setErrored] = createSignal(err, {
|
|
1558
1563
|
name: "errored"
|
|
1559
1564
|
} );
|
|
@@ -1574,7 +1579,7 @@ function ErrorBoundary(props) {
|
|
|
1574
1579
|
}
|
|
1575
1580
|
|
|
1576
1581
|
const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback;
|
|
1577
|
-
const SuspenseListContext = createContext();
|
|
1582
|
+
const SuspenseListContext = /* #__PURE__ */createContext();
|
|
1578
1583
|
function SuspenseList(props) {
|
|
1579
1584
|
let [wrapper, setWrapper] = createSignal(() => ({
|
|
1580
1585
|
inFallback: false
|
|
@@ -1671,7 +1676,7 @@ function Suspense(props) {
|
|
|
1671
1676
|
},
|
|
1672
1677
|
owner = getOwner();
|
|
1673
1678
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1674
|
-
const key = sharedConfig.
|
|
1679
|
+
const key = sharedConfig.getContextId();
|
|
1675
1680
|
let ref = sharedConfig.load(key);
|
|
1676
1681
|
if (ref) {
|
|
1677
1682
|
if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key);
|
|
@@ -1728,7 +1733,7 @@ function Suspense(props) {
|
|
|
1728
1733
|
dispose = disposer;
|
|
1729
1734
|
if (ctx) {
|
|
1730
1735
|
setHydrateContext({
|
|
1731
|
-
id: ctx.id + "
|
|
1736
|
+
id: ctx.id + "F",
|
|
1732
1737
|
count: 0
|
|
1733
1738
|
});
|
|
1734
1739
|
ctx = undefined;
|
package/dist/dev.js
CHANGED
|
@@ -118,15 +118,27 @@ function workLoop(hasTimeRemaining, initialTime) {
|
|
|
118
118
|
|
|
119
119
|
const sharedConfig = {
|
|
120
120
|
context: undefined,
|
|
121
|
-
registry: undefined
|
|
121
|
+
registry: undefined,
|
|
122
|
+
done: false,
|
|
123
|
+
getContextId() {
|
|
124
|
+
return getContextId(this.context.count);
|
|
125
|
+
},
|
|
126
|
+
getNextContextId() {
|
|
127
|
+
return getContextId(this.context.count++);
|
|
128
|
+
}
|
|
122
129
|
};
|
|
130
|
+
function getContextId(count) {
|
|
131
|
+
const num = String(count),
|
|
132
|
+
len = num.length - 1;
|
|
133
|
+
return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
|
|
134
|
+
}
|
|
123
135
|
function setHydrateContext(context) {
|
|
124
136
|
sharedConfig.context = context;
|
|
125
137
|
}
|
|
126
138
|
function nextHydrateContext() {
|
|
127
139
|
return {
|
|
128
140
|
...sharedConfig.context,
|
|
129
|
-
id:
|
|
141
|
+
id: sharedConfig.getNextContextId(),
|
|
130
142
|
count: 0
|
|
131
143
|
};
|
|
132
144
|
}
|
|
@@ -299,10 +311,9 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
299
311
|
}),
|
|
300
312
|
[state, setState] = createSignal(resolved ? "ready" : "unresolved");
|
|
301
313
|
if (sharedConfig.context) {
|
|
302
|
-
id =
|
|
303
|
-
let v;
|
|
314
|
+
id = sharedConfig.getNextContextId();
|
|
304
315
|
if (options.ssrLoadFrom === "initial") initP = options.initialValue;
|
|
305
|
-
else if (sharedConfig.load &&
|
|
316
|
+
else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id);
|
|
306
317
|
}
|
|
307
318
|
function loadEnd(p, v, error, key) {
|
|
308
319
|
if (pr === p) {
|
|
@@ -649,8 +660,9 @@ function createContext(defaultValue, options) {
|
|
|
649
660
|
};
|
|
650
661
|
}
|
|
651
662
|
function useContext(context) {
|
|
652
|
-
|
|
653
|
-
|
|
663
|
+
let value;
|
|
664
|
+
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined
|
|
665
|
+
? value
|
|
654
666
|
: context.defaultValue;
|
|
655
667
|
}
|
|
656
668
|
function children(fn) {
|
|
@@ -1210,20 +1222,12 @@ function mapArray(list, mapFn, options = {}) {
|
|
|
1210
1222
|
onCleanup(() => dispose(disposers));
|
|
1211
1223
|
return () => {
|
|
1212
1224
|
let newItems = list() || [],
|
|
1225
|
+
newLen = newItems.length,
|
|
1213
1226
|
i,
|
|
1214
1227
|
j;
|
|
1215
1228
|
newItems[$TRACK];
|
|
1216
1229
|
return untrack(() => {
|
|
1217
|
-
let
|
|
1218
|
-
newIndices,
|
|
1219
|
-
newIndicesNext,
|
|
1220
|
-
temp,
|
|
1221
|
-
tempdisposers,
|
|
1222
|
-
tempIndexes,
|
|
1223
|
-
start,
|
|
1224
|
-
end,
|
|
1225
|
-
newEnd,
|
|
1226
|
-
item;
|
|
1230
|
+
let newIndices, newIndicesNext, temp, tempdisposers, tempIndexes, start, end, newEnd, item;
|
|
1227
1231
|
if (newLen === 0) {
|
|
1228
1232
|
if (len !== 0) {
|
|
1229
1233
|
dispose(disposers);
|
|
@@ -1322,10 +1326,11 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1322
1326
|
i;
|
|
1323
1327
|
onCleanup(() => dispose(disposers));
|
|
1324
1328
|
return () => {
|
|
1325
|
-
const newItems = list() || []
|
|
1329
|
+
const newItems = list() || [],
|
|
1330
|
+
newLen = newItems.length;
|
|
1326
1331
|
newItems[$TRACK];
|
|
1327
1332
|
return untrack(() => {
|
|
1328
|
-
if (
|
|
1333
|
+
if (newLen === 0) {
|
|
1329
1334
|
if (len !== 0) {
|
|
1330
1335
|
dispose(disposers);
|
|
1331
1336
|
disposers = [];
|
|
@@ -1351,7 +1356,7 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1351
1356
|
mapped = [];
|
|
1352
1357
|
len = 0;
|
|
1353
1358
|
}
|
|
1354
|
-
for (i = 0; i <
|
|
1359
|
+
for (i = 0; i < newLen; i++) {
|
|
1355
1360
|
if (i < items.length && items[i] !== newItems[i]) {
|
|
1356
1361
|
signals[i](() => newItems[i]);
|
|
1357
1362
|
} else if (i >= items.length) {
|
|
@@ -1361,7 +1366,7 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1361
1366
|
for (; i < items.length; i++) {
|
|
1362
1367
|
disposers[i]();
|
|
1363
1368
|
}
|
|
1364
|
-
len = signals.length = disposers.length =
|
|
1369
|
+
len = signals.length = disposers.length = newLen;
|
|
1365
1370
|
items = newItems.slice(0);
|
|
1366
1371
|
return (mapped = mapped.slice(0, len));
|
|
1367
1372
|
});
|
|
@@ -1573,7 +1578,7 @@ function lazy(fn) {
|
|
|
1573
1578
|
sharedConfig.count || (sharedConfig.count = 0);
|
|
1574
1579
|
sharedConfig.count++;
|
|
1575
1580
|
(p || (p = fn())).then(mod => {
|
|
1576
|
-
setHydrateContext(ctx);
|
|
1581
|
+
!sharedConfig.done && setHydrateContext(ctx);
|
|
1577
1582
|
sharedConfig.count--;
|
|
1578
1583
|
set(() => mod.default);
|
|
1579
1584
|
setHydrateContext();
|
|
@@ -1584,21 +1589,21 @@ function lazy(fn) {
|
|
|
1584
1589
|
comp = s;
|
|
1585
1590
|
}
|
|
1586
1591
|
let Comp;
|
|
1587
|
-
return createMemo(
|
|
1588
|
-
()
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1592
|
+
return createMemo(() =>
|
|
1593
|
+
(Comp = comp())
|
|
1594
|
+
? untrack(() => {
|
|
1595
|
+
if (true)
|
|
1596
|
+
Object.assign(Comp, {
|
|
1597
|
+
[$DEVCOMP]: true
|
|
1598
|
+
});
|
|
1599
|
+
if (!ctx || sharedConfig.done) return Comp(props);
|
|
1600
|
+
const c = sharedConfig.context;
|
|
1601
|
+
setHydrateContext(ctx);
|
|
1602
|
+
const r = Comp(props);
|
|
1603
|
+
setHydrateContext(c);
|
|
1604
|
+
return r;
|
|
1605
|
+
})
|
|
1606
|
+
: ""
|
|
1602
1607
|
);
|
|
1603
1608
|
};
|
|
1604
1609
|
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
|
|
@@ -1607,7 +1612,7 @@ function lazy(fn) {
|
|
|
1607
1612
|
let counter = 0;
|
|
1608
1613
|
function createUniqueId() {
|
|
1609
1614
|
const ctx = sharedConfig.context;
|
|
1610
|
-
return ctx ?
|
|
1615
|
+
return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
|
|
1611
1616
|
}
|
|
1612
1617
|
|
|
1613
1618
|
const narrowedError = name =>
|
|
@@ -1727,7 +1732,7 @@ function resetErrorBoundaries() {
|
|
|
1727
1732
|
function ErrorBoundary(props) {
|
|
1728
1733
|
let err;
|
|
1729
1734
|
if (sharedConfig.context && sharedConfig.load)
|
|
1730
|
-
err = sharedConfig.load(sharedConfig.
|
|
1735
|
+
err = sharedConfig.load(sharedConfig.getContextId());
|
|
1731
1736
|
const [errored, setErrored] = createSignal(err, {
|
|
1732
1737
|
name: "errored"
|
|
1733
1738
|
});
|
|
@@ -1753,7 +1758,7 @@ function ErrorBoundary(props) {
|
|
|
1753
1758
|
|
|
1754
1759
|
const suspenseListEquals = (a, b) =>
|
|
1755
1760
|
a.showContent === b.showContent && a.showFallback === b.showFallback;
|
|
1756
|
-
const SuspenseListContext = createContext();
|
|
1761
|
+
const SuspenseListContext = /* #__PURE__ */ createContext();
|
|
1757
1762
|
function SuspenseList(props) {
|
|
1758
1763
|
let [wrapper, setWrapper] = createSignal(() => ({
|
|
1759
1764
|
inFallback: false
|
|
@@ -1850,7 +1855,7 @@ function Suspense(props) {
|
|
|
1850
1855
|
},
|
|
1851
1856
|
owner = getOwner();
|
|
1852
1857
|
if (sharedConfig.context && sharedConfig.load) {
|
|
1853
|
-
const key = sharedConfig.
|
|
1858
|
+
const key = sharedConfig.getContextId();
|
|
1854
1859
|
let ref = sharedConfig.load(key);
|
|
1855
1860
|
if (ref) {
|
|
1856
1861
|
if (typeof ref !== "object" || ref.status !== "success") p = ref;
|
|
@@ -1908,7 +1913,7 @@ function Suspense(props) {
|
|
|
1908
1913
|
dispose = disposer;
|
|
1909
1914
|
if (ctx) {
|
|
1910
1915
|
setHydrateContext({
|
|
1911
|
-
id: ctx.id + "
|
|
1916
|
+
id: ctx.id + "F",
|
|
1912
1917
|
count: 0
|
|
1913
1918
|
});
|
|
1914
1919
|
ctx = undefined;
|
package/dist/server.cjs
CHANGED
|
@@ -319,21 +319,34 @@ function resolveSSRNode(node) {
|
|
|
319
319
|
if (t === "function") return resolveSSRNode(node());
|
|
320
320
|
return String(node);
|
|
321
321
|
}
|
|
322
|
-
const sharedConfig = {
|
|
322
|
+
const sharedConfig = {
|
|
323
|
+
context: undefined,
|
|
324
|
+
getContextId() {
|
|
325
|
+
if (!this.context) throw new Error(`getContextId cannot be used under non-hydrating context`);
|
|
326
|
+
return getContextId(this.context.count);
|
|
327
|
+
},
|
|
328
|
+
getNextContextId() {
|
|
329
|
+
if (!this.context) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
330
|
+
return getContextId(this.context.count++);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
function getContextId(count) {
|
|
334
|
+
const num = String(count),
|
|
335
|
+
len = num.length - 1;
|
|
336
|
+
return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
|
|
337
|
+
}
|
|
323
338
|
function setHydrateContext(context) {
|
|
324
339
|
sharedConfig.context = context;
|
|
325
340
|
}
|
|
326
341
|
function nextHydrateContext() {
|
|
327
342
|
return sharedConfig.context ? {
|
|
328
343
|
...sharedConfig.context,
|
|
329
|
-
id:
|
|
344
|
+
id: sharedConfig.getNextContextId(),
|
|
330
345
|
count: 0
|
|
331
346
|
} : undefined;
|
|
332
347
|
}
|
|
333
348
|
function createUniqueId() {
|
|
334
|
-
|
|
335
|
-
if (!ctx) throw new Error(`createUniqueId cannot be used under non-hydrating context`);
|
|
336
|
-
return `${ctx.id}${ctx.count++}`;
|
|
349
|
+
return sharedConfig.getNextContextId();
|
|
337
350
|
}
|
|
338
351
|
function createComponent(Comp, props) {
|
|
339
352
|
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
|
|
@@ -429,7 +442,7 @@ function ErrorBoundary(props) {
|
|
|
429
442
|
clean,
|
|
430
443
|
sync = true;
|
|
431
444
|
const ctx = sharedConfig.context;
|
|
432
|
-
const id =
|
|
445
|
+
const id = sharedConfig.getContextId();
|
|
433
446
|
function displayFallback() {
|
|
434
447
|
cleanNode(clean);
|
|
435
448
|
ctx.serialize(id, error);
|
|
@@ -455,6 +468,7 @@ function ErrorBoundary(props) {
|
|
|
455
468
|
};
|
|
456
469
|
}
|
|
457
470
|
const SuspenseContext = createContext();
|
|
471
|
+
let resourceContext = null;
|
|
458
472
|
function createResource(source, fetcher, options = {}) {
|
|
459
473
|
if (arguments.length === 2) {
|
|
460
474
|
if (typeof fetcher === "object") {
|
|
@@ -467,7 +481,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
467
481
|
source = true;
|
|
468
482
|
}
|
|
469
483
|
const contexts = new Set();
|
|
470
|
-
const id = sharedConfig.
|
|
484
|
+
const id = sharedConfig.getNextContextId();
|
|
471
485
|
let resource = {};
|
|
472
486
|
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
|
|
473
487
|
let p;
|
|
@@ -482,6 +496,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
482
496
|
const read = () => {
|
|
483
497
|
if (error) throw error;
|
|
484
498
|
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
499
|
+
if (!resolved && resourceContext) resourceContext.push(id);
|
|
485
500
|
if (!resolved && read.loading) {
|
|
486
501
|
const ctx = useContext(SuspenseContext);
|
|
487
502
|
if (ctx) {
|
|
@@ -506,7 +521,14 @@ function createResource(source, fetcher, options = {}) {
|
|
|
506
521
|
value = ctx.resources[id].data;
|
|
507
522
|
return;
|
|
508
523
|
}
|
|
509
|
-
|
|
524
|
+
let lookup;
|
|
525
|
+
try {
|
|
526
|
+
resourceContext = [];
|
|
527
|
+
lookup = typeof source === "function" ? source() : source;
|
|
528
|
+
if (resourceContext.length) return;
|
|
529
|
+
} finally {
|
|
530
|
+
resourceContext = null;
|
|
531
|
+
}
|
|
510
532
|
if (!p) {
|
|
511
533
|
if (lookup == null || lookup === false) return;
|
|
512
534
|
p = fetcher(lookup, {
|
|
@@ -612,7 +634,7 @@ function SuspenseList(props) {
|
|
|
612
634
|
function Suspense(props) {
|
|
613
635
|
let done;
|
|
614
636
|
const ctx = sharedConfig.context;
|
|
615
|
-
const id =
|
|
637
|
+
const id = sharedConfig.getContextId();
|
|
616
638
|
const o = createOwner();
|
|
617
639
|
const value = ctx.suspense[id] || (ctx.suspense[id] = {
|
|
618
640
|
resources: new Map(),
|
|
@@ -654,7 +676,7 @@ function Suspense(props) {
|
|
|
654
676
|
setHydrateContext({
|
|
655
677
|
...ctx,
|
|
656
678
|
count: 0,
|
|
657
|
-
id: ctx.id + "
|
|
679
|
+
id: ctx.id + "0F",
|
|
658
680
|
noHydrate: true
|
|
659
681
|
});
|
|
660
682
|
const res = {
|
|
@@ -666,7 +688,7 @@ function Suspense(props) {
|
|
|
666
688
|
setHydrateContext({
|
|
667
689
|
...ctx,
|
|
668
690
|
count: 0,
|
|
669
|
-
id: ctx.id + "
|
|
691
|
+
id: ctx.id + "0F"
|
|
670
692
|
});
|
|
671
693
|
ctx.serialize(id, "$$f");
|
|
672
694
|
return props.fallback;
|
package/dist/server.js
CHANGED
|
@@ -328,7 +328,23 @@ function resolveSSRNode(node) {
|
|
|
328
328
|
if (t === "function") return resolveSSRNode(node());
|
|
329
329
|
return String(node);
|
|
330
330
|
}
|
|
331
|
-
const sharedConfig = {
|
|
331
|
+
const sharedConfig = {
|
|
332
|
+
context: undefined,
|
|
333
|
+
getContextId() {
|
|
334
|
+
if (!this.context) throw new Error(`getContextId cannot be used under non-hydrating context`);
|
|
335
|
+
return getContextId(this.context.count);
|
|
336
|
+
},
|
|
337
|
+
getNextContextId() {
|
|
338
|
+
if (!this.context)
|
|
339
|
+
throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
340
|
+
return getContextId(this.context.count++);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
function getContextId(count) {
|
|
344
|
+
const num = String(count),
|
|
345
|
+
len = num.length - 1;
|
|
346
|
+
return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
|
|
347
|
+
}
|
|
332
348
|
function setHydrateContext(context) {
|
|
333
349
|
sharedConfig.context = context;
|
|
334
350
|
}
|
|
@@ -336,15 +352,13 @@ function nextHydrateContext() {
|
|
|
336
352
|
return sharedConfig.context
|
|
337
353
|
? {
|
|
338
354
|
...sharedConfig.context,
|
|
339
|
-
id:
|
|
355
|
+
id: sharedConfig.getNextContextId(),
|
|
340
356
|
count: 0
|
|
341
357
|
}
|
|
342
358
|
: undefined;
|
|
343
359
|
}
|
|
344
360
|
function createUniqueId() {
|
|
345
|
-
|
|
346
|
-
if (!ctx) throw new Error(`createUniqueId cannot be used under non-hydrating context`);
|
|
347
|
-
return `${ctx.id}${ctx.count++}`;
|
|
361
|
+
return sharedConfig.getNextContextId();
|
|
348
362
|
}
|
|
349
363
|
function createComponent(Comp, props) {
|
|
350
364
|
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
|
|
@@ -444,7 +458,7 @@ function ErrorBoundary(props) {
|
|
|
444
458
|
clean,
|
|
445
459
|
sync = true;
|
|
446
460
|
const ctx = sharedConfig.context;
|
|
447
|
-
const id =
|
|
461
|
+
const id = sharedConfig.getContextId();
|
|
448
462
|
function displayFallback() {
|
|
449
463
|
cleanNode(clean);
|
|
450
464
|
ctx.serialize(id, error);
|
|
@@ -473,6 +487,7 @@ function ErrorBoundary(props) {
|
|
|
473
487
|
};
|
|
474
488
|
}
|
|
475
489
|
const SuspenseContext = createContext();
|
|
490
|
+
let resourceContext = null;
|
|
476
491
|
function createResource(source, fetcher, options = {}) {
|
|
477
492
|
if (arguments.length === 2) {
|
|
478
493
|
if (typeof fetcher === "object") {
|
|
@@ -485,7 +500,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
485
500
|
source = true;
|
|
486
501
|
}
|
|
487
502
|
const contexts = new Set();
|
|
488
|
-
const id = sharedConfig.
|
|
503
|
+
const id = sharedConfig.getNextContextId();
|
|
489
504
|
let resource = {};
|
|
490
505
|
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
|
|
491
506
|
let p;
|
|
@@ -504,6 +519,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
504
519
|
options.ssrLoadFrom !== "initial" &&
|
|
505
520
|
sharedConfig.context.async &&
|
|
506
521
|
"data" in sharedConfig.context.resources[id];
|
|
522
|
+
if (!resolved && resourceContext) resourceContext.push(id);
|
|
507
523
|
if (!resolved && read.loading) {
|
|
508
524
|
const ctx = useContext(SuspenseContext);
|
|
509
525
|
if (ctx) {
|
|
@@ -528,7 +544,14 @@ function createResource(source, fetcher, options = {}) {
|
|
|
528
544
|
value = ctx.resources[id].data;
|
|
529
545
|
return;
|
|
530
546
|
}
|
|
531
|
-
|
|
547
|
+
let lookup;
|
|
548
|
+
try {
|
|
549
|
+
resourceContext = [];
|
|
550
|
+
lookup = typeof source === "function" ? source() : source;
|
|
551
|
+
if (resourceContext.length) return;
|
|
552
|
+
} finally {
|
|
553
|
+
resourceContext = null;
|
|
554
|
+
}
|
|
532
555
|
if (!p) {
|
|
533
556
|
if (lookup == null || lookup === false) return;
|
|
534
557
|
p = fetcher(lookup, {
|
|
@@ -645,7 +668,7 @@ function SuspenseList(props) {
|
|
|
645
668
|
function Suspense(props) {
|
|
646
669
|
let done;
|
|
647
670
|
const ctx = sharedConfig.context;
|
|
648
|
-
const id =
|
|
671
|
+
const id = sharedConfig.getContextId();
|
|
649
672
|
const o = createOwner();
|
|
650
673
|
const value =
|
|
651
674
|
ctx.suspense[id] ||
|
|
@@ -691,7 +714,7 @@ function Suspense(props) {
|
|
|
691
714
|
setHydrateContext({
|
|
692
715
|
...ctx,
|
|
693
716
|
count: 0,
|
|
694
|
-
id: ctx.id + "
|
|
717
|
+
id: ctx.id + "0F",
|
|
695
718
|
noHydrate: true
|
|
696
719
|
});
|
|
697
720
|
const res = {
|
|
@@ -703,7 +726,7 @@ function Suspense(props) {
|
|
|
703
726
|
setHydrateContext({
|
|
704
727
|
...ctx,
|
|
705
728
|
count: 0,
|
|
706
|
-
id: ctx.id + "
|
|
729
|
+
id: ctx.id + "0F"
|
|
707
730
|
});
|
|
708
731
|
ctx.serialize(id, "$$f");
|
|
709
732
|
return props.fallback;
|