solid-js 2.0.0-experimental.13 → 2.0.0-experimental.15
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 +506 -78
- package/dist/dev.js +509 -64
- package/dist/server.cjs +827 -0
- package/dist/server.js +732 -0
- package/dist/solid.cjs +492 -77
- package/dist/solid.js +495 -63
- package/package.json +4 -4
- package/types/client/component.d.ts +1 -2
- package/types/client/flow.d.ts +1 -5
- package/types/client/hydration.d.ts +36 -0
- package/types/index.d.ts +3 -4
- package/types/server/component.d.ts +66 -0
- package/types/server/core.d.ts +43 -0
- package/types/server/flow.d.ts +60 -0
- package/types/server/hydration.d.ts +21 -0
- package/types/server/index.d.ts +12 -1
- package/types/server/shared.d.ts +45 -0
- package/types/server/signals.d.ts +60 -0
- package/types/utilities.d.ts +0 -36
package/dist/solid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getContext, createMemo, flatten, createRoot, setContext,
|
|
2
|
-
export { $PROXY, $TRACK, action, createEffect,
|
|
1
|
+
import { getContext, createMemo as createMemo$1, flatten, createRoot, setContext, createLoadBoundary, getOwner, onCleanup, isDisposed, runWithOwner, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, untrack, mapArray, repeat } from '@solidjs/signals';
|
|
2
|
+
export { $PROXY, $TRACK, NotReadyError, action, createEffect, createReaction, createRenderEffect, createRoot, createTrackedEffect, deep, flatten, flush, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, mapArray, merge, omit, onCleanup, onSettled, pending, reconcile, refresh, repeat, resolve, runWithOwner, snapshot, untrack } from '@solidjs/signals';
|
|
3
3
|
|
|
4
4
|
const $DEVCOMP = Symbol(0);
|
|
5
5
|
function createContext(defaultValue, options) {
|
|
@@ -18,8 +18,8 @@ function useContext(context) {
|
|
|
18
18
|
return getContext(context);
|
|
19
19
|
}
|
|
20
20
|
function children(fn) {
|
|
21
|
-
const children = createMemo(fn);
|
|
22
|
-
const memo = createMemo(() => flatten(children()));
|
|
21
|
+
const children = createMemo$1(fn);
|
|
22
|
+
const memo = createMemo$1(() => flatten(children()));
|
|
23
23
|
memo.toArray = () => {
|
|
24
24
|
const c = memo();
|
|
25
25
|
return Array.isArray(c) ? c : c != null ? [c] : [];
|
|
@@ -27,27 +27,6 @@ function children(fn) {
|
|
|
27
27
|
return memo;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function tryCatch(fn) {
|
|
31
|
-
try {
|
|
32
|
-
const v = fn();
|
|
33
|
-
if (v instanceof Promise) {
|
|
34
|
-
return v.then(v => [undefined, v], e => {
|
|
35
|
-
if (e instanceof NotReadyError) throw e;
|
|
36
|
-
return [e];
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return [undefined, v];
|
|
40
|
-
} catch (e) {
|
|
41
|
-
if (e instanceof NotReadyError) throw e;
|
|
42
|
-
return [e];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function reducer(source, reducerFn) {
|
|
46
|
-
return [source[0], action => {
|
|
47
|
-
source[1](s => reducerFn(s, action));
|
|
48
|
-
}];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
30
|
const sharedConfig = {
|
|
52
31
|
hydrating: false,
|
|
53
32
|
registry: undefined,
|
|
@@ -58,52 +37,498 @@ const sharedConfig = {
|
|
|
58
37
|
return getNextChildId(o);
|
|
59
38
|
}
|
|
60
39
|
};
|
|
40
|
+
let _hydrationEndCallbacks = null;
|
|
41
|
+
let _pendingBoundaries = 0;
|
|
42
|
+
let _hydrationDone = false;
|
|
43
|
+
let _snapshotRootOwner = null;
|
|
44
|
+
function markTopLevelSnapshotScope() {
|
|
45
|
+
if (_snapshotRootOwner) return;
|
|
46
|
+
let owner = getOwner();
|
|
47
|
+
if (!owner) return;
|
|
48
|
+
while (owner._parent) owner = owner._parent;
|
|
49
|
+
markSnapshotScope(owner);
|
|
50
|
+
_snapshotRootOwner = owner;
|
|
51
|
+
}
|
|
52
|
+
function drainHydrationCallbacks() {
|
|
53
|
+
if (_hydrationDone) return;
|
|
54
|
+
_hydrationDone = true;
|
|
55
|
+
_doneValue = true;
|
|
56
|
+
clearSnapshots();
|
|
57
|
+
setSnapshotCapture(false);
|
|
58
|
+
flush();
|
|
59
|
+
const cbs = _hydrationEndCallbacks;
|
|
60
|
+
_hydrationEndCallbacks = null;
|
|
61
|
+
if (cbs) for (const cb of cbs) cb();
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
if (globalThis._$HY) globalThis._$HY.done = true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function checkHydrationComplete() {
|
|
67
|
+
if (_pendingBoundaries === 0) drainHydrationCallbacks();
|
|
68
|
+
}
|
|
69
|
+
let _hydratingValue = false;
|
|
70
|
+
let _doneValue = false;
|
|
71
|
+
let _createMemo;
|
|
72
|
+
let _createSignal;
|
|
73
|
+
let _createErrorBoundary;
|
|
74
|
+
let _createOptimistic;
|
|
75
|
+
let _createProjection;
|
|
76
|
+
let _createStore;
|
|
77
|
+
let _createOptimisticStore;
|
|
78
|
+
class MockPromise {
|
|
79
|
+
static all() {
|
|
80
|
+
return new MockPromise();
|
|
81
|
+
}
|
|
82
|
+
static allSettled() {
|
|
83
|
+
return new MockPromise();
|
|
84
|
+
}
|
|
85
|
+
static any() {
|
|
86
|
+
return new MockPromise();
|
|
87
|
+
}
|
|
88
|
+
static race() {
|
|
89
|
+
return new MockPromise();
|
|
90
|
+
}
|
|
91
|
+
static reject() {
|
|
92
|
+
return new MockPromise();
|
|
93
|
+
}
|
|
94
|
+
static resolve() {
|
|
95
|
+
return new MockPromise();
|
|
96
|
+
}
|
|
97
|
+
catch() {
|
|
98
|
+
return new MockPromise();
|
|
99
|
+
}
|
|
100
|
+
then() {
|
|
101
|
+
return new MockPromise();
|
|
102
|
+
}
|
|
103
|
+
finally() {
|
|
104
|
+
return new MockPromise();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function subFetch(fn, prev) {
|
|
108
|
+
const ogFetch = fetch;
|
|
109
|
+
const ogPromise = Promise;
|
|
110
|
+
try {
|
|
111
|
+
window.fetch = () => new MockPromise();
|
|
112
|
+
Promise = MockPromise;
|
|
113
|
+
const result = fn(prev);
|
|
114
|
+
if (result && typeof result[Symbol.asyncIterator] === "function") {
|
|
115
|
+
result[Symbol.asyncIterator]().next();
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
} finally {
|
|
119
|
+
window.fetch = ogFetch;
|
|
120
|
+
Promise = ogPromise;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function consumeFirstSync(ai) {
|
|
124
|
+
const iter = ai[Symbol.asyncIterator]();
|
|
125
|
+
const r = iter.next();
|
|
126
|
+
const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
|
|
127
|
+
return [value, iter];
|
|
128
|
+
}
|
|
129
|
+
function applyPatches(target, patches) {
|
|
130
|
+
for (const patch of patches) {
|
|
131
|
+
const path = patch[0];
|
|
132
|
+
let current = target;
|
|
133
|
+
for (let i = 0; i < path.length - 1; i++) current = current[path[i]];
|
|
134
|
+
const key = path[path.length - 1];
|
|
135
|
+
if (patch.length === 1) {
|
|
136
|
+
Array.isArray(current) ? current.splice(key, 1) : delete current[key];
|
|
137
|
+
} else if (patch.length === 3) {
|
|
138
|
+
current.splice(key, 0, patch[1]);
|
|
139
|
+
} else {
|
|
140
|
+
current[key] = patch[1];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function scheduleIteratorConsumption(iter, apply) {
|
|
145
|
+
const consume = () => {
|
|
146
|
+
while (true) {
|
|
147
|
+
const n = iter.next();
|
|
148
|
+
if (n instanceof Promise) {
|
|
149
|
+
n.then(r => {
|
|
150
|
+
if (r.done) return;
|
|
151
|
+
apply(r.value);
|
|
152
|
+
consume();
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (n.done) break;
|
|
157
|
+
apply(n.value);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
consume();
|
|
161
|
+
}
|
|
162
|
+
function isAsyncIterable(v) {
|
|
163
|
+
return v != null && typeof v[Symbol.asyncIterator] === "function";
|
|
164
|
+
}
|
|
165
|
+
function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
|
|
166
|
+
const parent = getOwner();
|
|
167
|
+
const expectedId = peekNextChildId(parent);
|
|
168
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
169
|
+
const initP = sharedConfig.load(expectedId);
|
|
170
|
+
if (!isAsyncIterable(initP)) return null;
|
|
171
|
+
const [firstValue, iter] = consumeFirstSync(initP);
|
|
172
|
+
const [get, set] = createSignal$1(firstValue);
|
|
173
|
+
const result = coreFn(() => get(), firstValue, options);
|
|
174
|
+
scheduleIteratorConsumption(iter, v => {
|
|
175
|
+
set(() => v);
|
|
176
|
+
flush();
|
|
177
|
+
});
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
|
|
181
|
+
const parent = getOwner();
|
|
182
|
+
const expectedId = peekNextChildId(parent);
|
|
183
|
+
if (!sharedConfig.has(expectedId)) return null;
|
|
184
|
+
const initP = sharedConfig.load(expectedId);
|
|
185
|
+
if (!isAsyncIterable(initP)) return null;
|
|
186
|
+
const [firstState, iter] = consumeFirstSync(initP);
|
|
187
|
+
const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
|
|
188
|
+
scheduleIteratorConsumption(iter, patches => {
|
|
189
|
+
setStore(d => {
|
|
190
|
+
applyPatches(d, patches);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
return [store, setStore];
|
|
194
|
+
}
|
|
195
|
+
function hydratedCreateMemo(compute, value, options) {
|
|
196
|
+
if (!sharedConfig.hydrating) return createMemo$1(compute, value, options);
|
|
197
|
+
markTopLevelSnapshotScope();
|
|
198
|
+
const ssrSource = options?.ssrSource;
|
|
199
|
+
if (ssrSource === "client") {
|
|
200
|
+
const [hydrated, setHydrated] = createSignal$1(false);
|
|
201
|
+
const memo = createMemo$1(prev => {
|
|
202
|
+
if (!hydrated()) return prev ?? value;
|
|
203
|
+
return compute(prev);
|
|
204
|
+
}, value, options);
|
|
205
|
+
setHydrated(true);
|
|
206
|
+
return memo;
|
|
207
|
+
}
|
|
208
|
+
if (ssrSource === "initial") {
|
|
209
|
+
return createMemo$1(prev => {
|
|
210
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
211
|
+
subFetch(compute, prev);
|
|
212
|
+
return prev ?? value;
|
|
213
|
+
}, value, options);
|
|
214
|
+
}
|
|
215
|
+
const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, value, options);
|
|
216
|
+
if (aiResult !== null) return aiResult;
|
|
217
|
+
return createMemo$1(prev => {
|
|
218
|
+
const o = getOwner();
|
|
219
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
220
|
+
let initP;
|
|
221
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
222
|
+
const init = initP?.v ?? initP;
|
|
223
|
+
return init != null ? (subFetch(compute, prev), init) : compute(prev);
|
|
224
|
+
}, value, options);
|
|
225
|
+
}
|
|
226
|
+
function hydratedCreateSignal(fn, second, third) {
|
|
227
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second, third);
|
|
228
|
+
markTopLevelSnapshotScope();
|
|
229
|
+
const ssrSource = third?.ssrSource;
|
|
230
|
+
if (ssrSource === "client") {
|
|
231
|
+
const [hydrated, setHydrated] = createSignal$1(false);
|
|
232
|
+
const sig = createSignal$1(prev => {
|
|
233
|
+
if (!hydrated()) return prev ?? second;
|
|
234
|
+
return fn(prev);
|
|
235
|
+
}, second, third);
|
|
236
|
+
setHydrated(true);
|
|
237
|
+
return sig;
|
|
238
|
+
}
|
|
239
|
+
if (ssrSource === "initial") {
|
|
240
|
+
return createSignal$1(prev => {
|
|
241
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
242
|
+
subFetch(fn, prev);
|
|
243
|
+
return prev ?? second;
|
|
244
|
+
}, second, third);
|
|
245
|
+
}
|
|
246
|
+
const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second, third);
|
|
247
|
+
if (aiResult !== null) return aiResult;
|
|
248
|
+
return createSignal$1(prev => {
|
|
249
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
250
|
+
const o = getOwner();
|
|
251
|
+
let initP;
|
|
252
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
253
|
+
const init = initP?.v ?? initP;
|
|
254
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
255
|
+
}, second, third);
|
|
256
|
+
}
|
|
257
|
+
function hydratedCreateErrorBoundary(fn, fallback) {
|
|
258
|
+
if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
|
|
259
|
+
markTopLevelSnapshotScope();
|
|
260
|
+
const parent = getOwner();
|
|
261
|
+
const expectedId = peekNextChildId(parent);
|
|
262
|
+
if (sharedConfig.has(expectedId)) {
|
|
263
|
+
const err = sharedConfig.load(expectedId);
|
|
264
|
+
if (err !== undefined) {
|
|
265
|
+
let hydrated = true;
|
|
266
|
+
return createErrorBoundary$1(() => {
|
|
267
|
+
if (hydrated) {
|
|
268
|
+
hydrated = false;
|
|
269
|
+
throw err;
|
|
270
|
+
}
|
|
271
|
+
return fn();
|
|
272
|
+
}, fallback);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return createErrorBoundary$1(fn, fallback);
|
|
276
|
+
}
|
|
277
|
+
function hydratedCreateOptimistic(fn, second, third) {
|
|
278
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second, third);
|
|
279
|
+
markTopLevelSnapshotScope();
|
|
280
|
+
const ssrSource = third?.ssrSource;
|
|
281
|
+
if (ssrSource === "client") {
|
|
282
|
+
const [hydrated, setHydrated] = createSignal$1(false);
|
|
283
|
+
const sig = createOptimistic$1(prev => {
|
|
284
|
+
if (!hydrated()) return prev ?? second;
|
|
285
|
+
return fn(prev);
|
|
286
|
+
}, second, third);
|
|
287
|
+
setHydrated(true);
|
|
288
|
+
return sig;
|
|
289
|
+
}
|
|
290
|
+
if (ssrSource === "initial") {
|
|
291
|
+
return createOptimistic$1(prev => {
|
|
292
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
293
|
+
subFetch(fn, prev);
|
|
294
|
+
return prev ?? second;
|
|
295
|
+
}, second, third);
|
|
296
|
+
}
|
|
297
|
+
const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second, third);
|
|
298
|
+
if (aiResult !== null) return aiResult;
|
|
299
|
+
return createOptimistic$1(prev => {
|
|
300
|
+
const o = getOwner();
|
|
301
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
302
|
+
let initP;
|
|
303
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
304
|
+
const init = initP?.v ?? initP;
|
|
305
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
306
|
+
}, second, third);
|
|
307
|
+
}
|
|
308
|
+
function wrapStoreFn(fn, ssrSource) {
|
|
309
|
+
if (ssrSource === "initial") {
|
|
310
|
+
return draft => {
|
|
311
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
312
|
+
subFetch(fn, draft);
|
|
313
|
+
return undefined;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return draft => {
|
|
317
|
+
const o = getOwner();
|
|
318
|
+
if (!sharedConfig.hydrating) return fn(draft);
|
|
319
|
+
let initP;
|
|
320
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
321
|
+
const init = initP?.v ?? initP;
|
|
322
|
+
return init != null ? (subFetch(fn, draft), init) : fn(draft);
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function hydratedCreateStore(first, second, third) {
|
|
326
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
|
|
327
|
+
markTopLevelSnapshotScope();
|
|
328
|
+
const ssrSource = third?.ssrSource;
|
|
329
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
330
|
+
return createStore$1(second ?? {}, undefined, third);
|
|
331
|
+
}
|
|
332
|
+
const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
|
|
333
|
+
if (aiResult !== null) return aiResult;
|
|
334
|
+
return createStore$1(wrapStoreFn(first, ssrSource), second, third);
|
|
335
|
+
}
|
|
336
|
+
function hydratedCreateOptimisticStore(first, second, third) {
|
|
337
|
+
if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
|
|
338
|
+
markTopLevelSnapshotScope();
|
|
339
|
+
const ssrSource = third?.ssrSource;
|
|
340
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
341
|
+
return createOptimisticStore$1(second ?? {}, undefined, third);
|
|
342
|
+
}
|
|
343
|
+
const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
|
|
344
|
+
if (aiResult !== null) return aiResult;
|
|
345
|
+
return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
|
|
346
|
+
}
|
|
347
|
+
function hydratedCreateProjection(fn, initialValue, options) {
|
|
348
|
+
if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
|
|
349
|
+
markTopLevelSnapshotScope();
|
|
350
|
+
const ssrSource = options?.ssrSource;
|
|
351
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
352
|
+
return createProjection$1(draft => draft, initialValue, options);
|
|
353
|
+
}
|
|
354
|
+
const aiResult = hydrateStoreFromAsyncIterable(createStore$1, initialValue, options);
|
|
355
|
+
if (aiResult !== null) return aiResult[0];
|
|
356
|
+
return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
|
|
357
|
+
}
|
|
358
|
+
function enableHydration() {
|
|
359
|
+
_createMemo = hydratedCreateMemo;
|
|
360
|
+
_createSignal = hydratedCreateSignal;
|
|
361
|
+
_createErrorBoundary = hydratedCreateErrorBoundary;
|
|
362
|
+
_createOptimistic = hydratedCreateOptimistic;
|
|
363
|
+
_createProjection = hydratedCreateProjection;
|
|
364
|
+
_createStore = hydratedCreateStore;
|
|
365
|
+
_createOptimisticStore = hydratedCreateOptimisticStore;
|
|
366
|
+
_hydratingValue = sharedConfig.hydrating;
|
|
367
|
+
_doneValue = sharedConfig.done;
|
|
368
|
+
Object.defineProperty(sharedConfig, "hydrating", {
|
|
369
|
+
get() {
|
|
370
|
+
return _hydratingValue;
|
|
371
|
+
},
|
|
372
|
+
set(v) {
|
|
373
|
+
const was = _hydratingValue;
|
|
374
|
+
_hydratingValue = v;
|
|
375
|
+
if (!was && v) {
|
|
376
|
+
_hydrationDone = false;
|
|
377
|
+
_doneValue = false;
|
|
378
|
+
_pendingBoundaries = 0;
|
|
379
|
+
setSnapshotCapture(true);
|
|
380
|
+
_snapshotRootOwner = null;
|
|
381
|
+
} else if (was && !v) {
|
|
382
|
+
if (_snapshotRootOwner) {
|
|
383
|
+
releaseSnapshotScope(_snapshotRootOwner);
|
|
384
|
+
_snapshotRootOwner = null;
|
|
385
|
+
}
|
|
386
|
+
checkHydrationComplete();
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
configurable: true,
|
|
390
|
+
enumerable: true
|
|
391
|
+
});
|
|
392
|
+
Object.defineProperty(sharedConfig, "done", {
|
|
393
|
+
get() {
|
|
394
|
+
return _doneValue;
|
|
395
|
+
},
|
|
396
|
+
set(v) {
|
|
397
|
+
_doneValue = v;
|
|
398
|
+
if (v) drainHydrationCallbacks();
|
|
399
|
+
},
|
|
400
|
+
configurable: true,
|
|
401
|
+
enumerable: true
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
const createMemo = (...args) => (_createMemo || createMemo$1)(...args);
|
|
405
|
+
const createSignal = (...args) => (_createSignal || createSignal$1)(...args);
|
|
406
|
+
const createErrorBoundary = (...args) => (_createErrorBoundary || createErrorBoundary$1)(...args);
|
|
407
|
+
const createOptimistic = (...args) => (_createOptimistic || createOptimistic$1)(...args);
|
|
408
|
+
const createProjection = (...args) => (_createProjection || createProjection$1)(...args);
|
|
409
|
+
const createStore = (...args) => (_createStore || createStore$1)(...args);
|
|
410
|
+
const createOptimisticStore = (...args) => (_createOptimisticStore || createOptimisticStore$1)(...args);
|
|
411
|
+
function loadModuleAssets(mapping) {
|
|
412
|
+
const hy = globalThis._$HY;
|
|
413
|
+
if (!hy) return;
|
|
414
|
+
if (!hy.modules) hy.modules = {};
|
|
415
|
+
if (!hy.loading) hy.loading = {};
|
|
416
|
+
const pending = [];
|
|
417
|
+
for (const moduleUrl in mapping) {
|
|
418
|
+
if (hy.modules[moduleUrl]) continue;
|
|
419
|
+
const entryUrl = mapping[moduleUrl];
|
|
420
|
+
if (!hy.loading[moduleUrl]) {
|
|
421
|
+
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
|
|
422
|
+
hy.modules[moduleUrl] = mod;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
pending.push(hy.loading[moduleUrl]);
|
|
426
|
+
}
|
|
427
|
+
return pending.length ? Promise.all(pending).then(() => {}) : undefined;
|
|
428
|
+
}
|
|
429
|
+
function createBoundaryTrigger() {
|
|
430
|
+
setSnapshotCapture(false);
|
|
431
|
+
const [s, set] = createSignal$1(undefined, {
|
|
432
|
+
equals: false
|
|
433
|
+
});
|
|
434
|
+
s();
|
|
435
|
+
setSnapshotCapture(true);
|
|
436
|
+
return set;
|
|
437
|
+
}
|
|
438
|
+
function resumeBoundaryHydration(o, id, set) {
|
|
439
|
+
_pendingBoundaries--;
|
|
440
|
+
if (isDisposed(o)) {
|
|
441
|
+
checkHydrationComplete();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
sharedConfig.gather(id);
|
|
445
|
+
_hydratingValue = true;
|
|
446
|
+
markSnapshotScope(o);
|
|
447
|
+
_snapshotRootOwner = o;
|
|
448
|
+
set();
|
|
449
|
+
flush();
|
|
450
|
+
_snapshotRootOwner = null;
|
|
451
|
+
_hydratingValue = false;
|
|
452
|
+
releaseSnapshotScope(o);
|
|
453
|
+
flush();
|
|
454
|
+
checkHydrationComplete();
|
|
455
|
+
}
|
|
61
456
|
function Loading(props) {
|
|
62
457
|
if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
|
|
63
|
-
return createMemo(() => {
|
|
458
|
+
return createMemo$1(() => {
|
|
64
459
|
const o = getOwner();
|
|
65
460
|
const id = o.id;
|
|
461
|
+
let assetPromise;
|
|
462
|
+
if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
|
|
463
|
+
const mapping = sharedConfig.load(id + "_assets");
|
|
464
|
+
if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
|
|
465
|
+
}
|
|
66
466
|
if (sharedConfig.hydrating && sharedConfig.has(id)) {
|
|
67
467
|
let ref = sharedConfig.load(id);
|
|
68
468
|
let p;
|
|
69
469
|
if (ref) {
|
|
70
|
-
if (typeof ref !== "object" || ref.s !==
|
|
470
|
+
if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
|
|
71
471
|
}
|
|
72
472
|
if (p) {
|
|
73
|
-
|
|
74
|
-
|
|
473
|
+
_pendingBoundaries++;
|
|
474
|
+
onCleanup(() => {
|
|
475
|
+
if (!isDisposed(o)) return;
|
|
476
|
+
sharedConfig.cleanupFragment?.(id);
|
|
75
477
|
});
|
|
76
|
-
|
|
478
|
+
const set = createBoundaryTrigger();
|
|
77
479
|
if (p !== "$$f") {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
480
|
+
const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
|
|
481
|
+
waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
|
|
482
|
+
_pendingBoundaries--;
|
|
483
|
+
checkHydrationComplete();
|
|
484
|
+
runWithOwner(o, () => {
|
|
485
|
+
throw err;
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
} else {
|
|
489
|
+
const afterAssets = () => {
|
|
490
|
+
_pendingBoundaries--;
|
|
81
491
|
set();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}));
|
|
87
|
-
} else queueMicrotask(set);
|
|
492
|
+
checkHydrationComplete();
|
|
493
|
+
};
|
|
494
|
+
if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
|
|
495
|
+
}
|
|
88
496
|
return props.fallback;
|
|
89
497
|
}
|
|
90
498
|
}
|
|
499
|
+
if (assetPromise) {
|
|
500
|
+
_pendingBoundaries++;
|
|
501
|
+
const set = createBoundaryTrigger();
|
|
502
|
+
assetPromise.then(() => resumeBoundaryHydration(o, id, set));
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
91
505
|
return createLoadBoundary(() => props.children, () => props.fallback);
|
|
92
506
|
});
|
|
93
507
|
}
|
|
94
508
|
|
|
95
|
-
function enableHydration() {
|
|
96
|
-
}
|
|
97
509
|
function createComponent(Comp, props) {
|
|
98
510
|
return untrack(() => Comp(props || {}));
|
|
99
511
|
}
|
|
100
|
-
function lazy(fn) {
|
|
512
|
+
function lazy(fn, moduleUrl) {
|
|
101
513
|
let comp;
|
|
102
514
|
let p;
|
|
103
515
|
const wrap = props => {
|
|
104
|
-
|
|
516
|
+
if (sharedConfig.hydrating && moduleUrl) {
|
|
517
|
+
const cached = globalThis._$HY?.modules?.[moduleUrl];
|
|
518
|
+
if (!cached) {
|
|
519
|
+
throw new Error(`lazy() module "${moduleUrl}" was not preloaded before hydration. ` + "Ensure it is inside a Loading boundary.");
|
|
520
|
+
}
|
|
521
|
+
comp = () => cached.default;
|
|
522
|
+
}
|
|
523
|
+
if (!comp) {
|
|
524
|
+
p || (p = fn());
|
|
525
|
+
p.then(mod => {
|
|
526
|
+
comp = () => mod.default;
|
|
527
|
+
});
|
|
528
|
+
comp = createMemo$1(() => p.then(mod => mod.default));
|
|
529
|
+
}
|
|
105
530
|
let Comp;
|
|
106
|
-
return createMemo(() => (Comp = comp()) ? untrack(() => {
|
|
531
|
+
return createMemo$1(() => (Comp = comp()) ? untrack(() => {
|
|
107
532
|
return Comp(props);
|
|
108
533
|
}) : "");
|
|
109
534
|
};
|
|
@@ -134,50 +559,60 @@ function Repeat(props) {
|
|
|
134
559
|
}
|
|
135
560
|
function Show(props) {
|
|
136
561
|
const keyed = props.keyed;
|
|
137
|
-
const conditionValue = createMemo(() => props.when, undefined, undefined);
|
|
138
|
-
const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
|
|
562
|
+
const conditionValue = createMemo$1(() => props.when, undefined, undefined);
|
|
563
|
+
const condition = keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
|
|
139
564
|
equals: (a, b) => !a === !b
|
|
140
565
|
});
|
|
141
|
-
return createMemo(() => {
|
|
566
|
+
return createMemo$1(() => {
|
|
142
567
|
const c = condition();
|
|
143
568
|
if (c) {
|
|
144
569
|
const child = props.children;
|
|
145
570
|
const fn = typeof child === "function" && child.length > 0;
|
|
146
|
-
return fn ? untrack(() =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
571
|
+
return fn ? untrack(() => {
|
|
572
|
+
try {
|
|
573
|
+
return child(() => {
|
|
574
|
+
if (!untrack(condition)) throw narrowedError("Show");
|
|
575
|
+
return conditionValue();
|
|
576
|
+
});
|
|
577
|
+
} finally {
|
|
578
|
+
}
|
|
579
|
+
}) : child;
|
|
150
580
|
}
|
|
151
581
|
return props.fallback;
|
|
152
582
|
}, undefined, undefined);
|
|
153
583
|
}
|
|
154
584
|
function Switch(props) {
|
|
155
585
|
const chs = children(() => props.children);
|
|
156
|
-
const switchFunc = createMemo(() => {
|
|
586
|
+
const switchFunc = createMemo$1(() => {
|
|
157
587
|
const mps = chs.toArray();
|
|
158
588
|
let func = () => undefined;
|
|
159
589
|
for (let i = 0; i < mps.length; i++) {
|
|
160
590
|
const index = i;
|
|
161
591
|
const mp = mps[i];
|
|
162
592
|
const prevFunc = func;
|
|
163
|
-
const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
|
|
164
|
-
const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
|
|
593
|
+
const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined, undefined);
|
|
594
|
+
const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
|
|
165
595
|
equals: (a, b) => !a === !b
|
|
166
596
|
});
|
|
167
597
|
func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
|
|
168
598
|
}
|
|
169
599
|
return func;
|
|
170
600
|
});
|
|
171
|
-
return createMemo(() => {
|
|
601
|
+
return createMemo$1(() => {
|
|
172
602
|
const sel = switchFunc()();
|
|
173
603
|
if (!sel) return props.fallback;
|
|
174
604
|
const [index, conditionValue, mp] = sel;
|
|
175
605
|
const child = mp.children;
|
|
176
606
|
const fn = typeof child === "function" && child.length > 0;
|
|
177
|
-
return fn ? untrack(() =>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
607
|
+
return fn ? untrack(() => {
|
|
608
|
+
try {
|
|
609
|
+
return child(() => {
|
|
610
|
+
if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
|
|
611
|
+
return conditionValue();
|
|
612
|
+
});
|
|
613
|
+
} finally {
|
|
614
|
+
}
|
|
615
|
+
}) : child;
|
|
181
616
|
}, undefined, undefined);
|
|
182
617
|
}
|
|
183
618
|
function Match(props) {
|
|
@@ -189,12 +624,9 @@ function Errored(props) {
|
|
|
189
624
|
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
190
625
|
});
|
|
191
626
|
}
|
|
192
|
-
function Boundary(props) {
|
|
193
|
-
return createBoundary(() => props.children, () => props.mode);
|
|
194
|
-
}
|
|
195
627
|
|
|
196
628
|
function ssrHandleError() {}
|
|
197
629
|
function ssrRunInScope() {}
|
|
198
630
|
const DEV = undefined;
|
|
199
631
|
|
|
200
|
-
export { $DEVCOMP,
|
|
632
|
+
export { $DEVCOMP, DEV, Errored, For, Loading, Match, Repeat, Show, Switch, children, createComponent, createContext, createMemo, createOptimistic, createOptimisticStore, createProjection, createSignal, createStore, createUniqueId, enableHydration, lazy, sharedConfig, ssrHandleError, ssrRunInScope, useContext };
|
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": "2.0.0-experimental.
|
|
4
|
+
"version": "2.0.0-experimental.15",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"performance"
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@solidjs/signals": "^0.
|
|
82
|
+
"@solidjs/signals": "^0.10.8",
|
|
83
83
|
"csstype": "^3.1.0",
|
|
84
|
-
"seroval": "~1.
|
|
85
|
-
"seroval-plugins": "~1.
|
|
84
|
+
"seroval": "~1.5.0",
|
|
85
|
+
"seroval-plugins": "~1.5.0"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "npm-run-all -nl build:*",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSX } from "../jsx.js";
|
|
2
|
-
export declare function enableHydration(): void;
|
|
3
2
|
/**
|
|
4
3
|
* A general `Component` has no implicit `children` prop. If desired, you can
|
|
5
4
|
* specify one as in `Component<{name: String, children: JSX.Element}>`.
|
|
@@ -67,7 +66,7 @@ export type Ref<T> = T | ((val: T) => void);
|
|
|
67
66
|
export declare function createComponent<T extends Record<string, any>>(Comp: Component<T>, props: T): JSX.Element;
|
|
68
67
|
export declare function lazy<T extends Component<any>>(fn: () => Promise<{
|
|
69
68
|
default: T;
|
|
70
|
-
}
|
|
69
|
+
}>, moduleUrl?: string): T & {
|
|
71
70
|
preload: () => Promise<{
|
|
72
71
|
default: T;
|
|
73
72
|
}>;
|