solid-js 2.0.0-experimental.14 → 2.0.0-experimental.16
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 +502 -57
- package/dist/dev.js +484 -33
- package/dist/server.cjs +419 -77
- package/dist/server.js +408 -79
- package/dist/solid.cjs +486 -54
- package/dist/solid.js +468 -30
- package/package.json +2 -2
- package/types/client/component.d.ts +1 -1
- package/types/client/hydration.d.ts +43 -2
- package/types/index.d.ts +3 -3
- package/types/jsx.d.ts +5 -28
- package/types/server/component.d.ts +6 -2
- package/types/server/core.d.ts +3 -2
- package/types/server/index.d.ts +2 -2
- package/types/server/shared.d.ts +22 -1
- package/types/server/signals.d.ts +11 -5
package/dist/server.cjs
CHANGED
|
@@ -25,12 +25,24 @@ function getObserver() {
|
|
|
25
25
|
}
|
|
26
26
|
function createSignal(first, second, third) {
|
|
27
27
|
if (typeof first === "function") {
|
|
28
|
+
const ssrSource = third?.ssrSource;
|
|
29
|
+
if (ssrSource === "initial" || ssrSource === "client") {
|
|
30
|
+
signals.createOwner();
|
|
31
|
+
let value = second;
|
|
32
|
+
return [() => value, v => {
|
|
33
|
+
return value = typeof v === "function" ? v(value) : v;
|
|
34
|
+
}];
|
|
35
|
+
}
|
|
36
|
+
const memoOpts = third?.deferStream || ssrSource ? {
|
|
37
|
+
deferStream: third?.deferStream,
|
|
38
|
+
ssrSource
|
|
39
|
+
} : undefined;
|
|
28
40
|
const memo = createMemo(p => {
|
|
29
41
|
let value = first(p ? p[0]() : second);
|
|
30
42
|
return [() => value, v => {
|
|
31
43
|
return value = typeof v === "function" ? v(value) : v;
|
|
32
44
|
}];
|
|
33
|
-
});
|
|
45
|
+
}, undefined, memoOpts);
|
|
34
46
|
return [() => memo()[0](), v => memo()[1](v)];
|
|
35
47
|
}
|
|
36
48
|
return [() => first, v => {
|
|
@@ -45,14 +57,19 @@ function createMemo(compute, value, options) {
|
|
|
45
57
|
value: value,
|
|
46
58
|
compute: compute,
|
|
47
59
|
error: undefined,
|
|
48
|
-
computed: false
|
|
60
|
+
computed: false,
|
|
61
|
+
disposed: false
|
|
49
62
|
};
|
|
63
|
+
signals.runWithOwner(owner, () => signals.onCleanup(() => {
|
|
64
|
+
comp.disposed = true;
|
|
65
|
+
}));
|
|
50
66
|
function update() {
|
|
67
|
+
if (comp.disposed) return;
|
|
51
68
|
try {
|
|
52
69
|
comp.error = undefined;
|
|
53
70
|
const result = signals.runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
54
71
|
comp.computed = true;
|
|
55
|
-
processResult(comp, result, owner, ctx);
|
|
72
|
+
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource);
|
|
56
73
|
} catch (err) {
|
|
57
74
|
if (err instanceof signals.NotReadyError) {
|
|
58
75
|
err.source?.then(() => update());
|
|
@@ -61,7 +78,10 @@ function createMemo(compute, value, options) {
|
|
|
61
78
|
comp.computed = true;
|
|
62
79
|
}
|
|
63
80
|
}
|
|
64
|
-
|
|
81
|
+
const ssrSource = options?.ssrSource;
|
|
82
|
+
if (ssrSource === "initial" || ssrSource === "client") {
|
|
83
|
+
comp.computed = true;
|
|
84
|
+
} else if (!options?.lazy) {
|
|
65
85
|
update();
|
|
66
86
|
}
|
|
67
87
|
return () => {
|
|
@@ -74,16 +94,79 @@ function createMemo(compute, value, options) {
|
|
|
74
94
|
return comp.value;
|
|
75
95
|
};
|
|
76
96
|
}
|
|
77
|
-
function
|
|
97
|
+
function createDeepProxy(target, patches, basePath = []) {
|
|
98
|
+
const childProxies = new Map();
|
|
99
|
+
const handler = {
|
|
100
|
+
get(obj, key, receiver) {
|
|
101
|
+
if (Array.isArray(obj)) {
|
|
102
|
+
if (key === "shift") {
|
|
103
|
+
return function () {
|
|
104
|
+
if (obj.length === 0) return undefined;
|
|
105
|
+
const removed = obj[0];
|
|
106
|
+
Array.prototype.shift.call(obj);
|
|
107
|
+
childProxies.clear();
|
|
108
|
+
patches.push([[...basePath, 0]]);
|
|
109
|
+
return removed;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (key === "unshift") {
|
|
113
|
+
return function (...items) {
|
|
114
|
+
const result = Array.prototype.unshift.apply(obj, items);
|
|
115
|
+
childProxies.clear();
|
|
116
|
+
for (let i = 0; i < items.length; i++) {
|
|
117
|
+
patches.push([[...basePath, i], items[i], 1]);
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (key === "splice") {
|
|
123
|
+
return function (start, deleteCount, ...items) {
|
|
124
|
+
const len = obj.length;
|
|
125
|
+
const s = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
126
|
+
const d = deleteCount === undefined ? len - s : Math.min(Math.max(deleteCount, 0), len - s);
|
|
127
|
+
const removed = Array.prototype.splice.apply(obj, [s, d, ...items]);
|
|
128
|
+
childProxies.clear();
|
|
129
|
+
for (let i = 0; i < d; i++) patches.push([[...basePath, s]]);
|
|
130
|
+
for (let i = 0; i < items.length; i++) patches.push([[...basePath, s + i], items[i], 1]);
|
|
131
|
+
return removed;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const value = Reflect.get(obj, key, receiver);
|
|
136
|
+
if (value !== null && typeof value === "object" && typeof key !== "symbol") {
|
|
137
|
+
if (!childProxies.has(key)) {
|
|
138
|
+
childProxies.set(key, createDeepProxy(value, patches, [...basePath, key]));
|
|
139
|
+
}
|
|
140
|
+
return childProxies.get(key);
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
},
|
|
144
|
+
set(obj, key, value) {
|
|
145
|
+
childProxies.delete(key);
|
|
146
|
+
patches.push([[...basePath, key], value]);
|
|
147
|
+
return Reflect.set(obj, key, value);
|
|
148
|
+
},
|
|
149
|
+
deleteProperty(obj, key) {
|
|
150
|
+
childProxies.delete(key);
|
|
151
|
+
patches.push([[...basePath, key]]);
|
|
152
|
+
return Reflect.deleteProperty(obj, key);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return new Proxy(target, handler);
|
|
156
|
+
}
|
|
157
|
+
function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
158
|
+
if (comp.disposed) return;
|
|
78
159
|
const id = owner.id;
|
|
79
160
|
const uninitialized = comp.value === undefined;
|
|
80
161
|
if (result instanceof Promise) {
|
|
81
162
|
result.then(v => {
|
|
82
163
|
result.s = 1;
|
|
83
|
-
result.v =
|
|
164
|
+
result.v = v;
|
|
165
|
+
if (comp.disposed) return;
|
|
166
|
+
comp.value = v;
|
|
84
167
|
comp.error = undefined;
|
|
85
|
-
});
|
|
86
|
-
if (ctx?.serialize && id) ctx.serialize(id, result);
|
|
168
|
+
}, () => {});
|
|
169
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, result, deferStream);
|
|
87
170
|
if (uninitialized) {
|
|
88
171
|
comp.error = new signals.NotReadyError(result);
|
|
89
172
|
}
|
|
@@ -92,37 +175,87 @@ function processResult(comp, result, owner, ctx) {
|
|
|
92
175
|
const iterator = result?.[Symbol.asyncIterator];
|
|
93
176
|
if (typeof iterator === "function") {
|
|
94
177
|
const iter = iterator.call(result);
|
|
95
|
-
|
|
96
|
-
promise
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
178
|
+
if (ssrSource === "hybrid") {
|
|
179
|
+
const promise = iter.next().then(v => {
|
|
180
|
+
promise.s = 1;
|
|
181
|
+
promise.v = v.value;
|
|
182
|
+
if (comp.disposed) return;
|
|
183
|
+
comp.value = v.value;
|
|
184
|
+
comp.error = undefined;
|
|
185
|
+
}, () => {});
|
|
186
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, promise, deferStream);
|
|
187
|
+
if (uninitialized) {
|
|
188
|
+
comp.error = new signals.NotReadyError(promise);
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const firstNext = iter.next();
|
|
192
|
+
const firstReady = firstNext.then(r => {
|
|
193
|
+
if (comp.disposed) return;
|
|
194
|
+
if (!r.done) {
|
|
195
|
+
comp.value = r.value;
|
|
196
|
+
comp.error = undefined;
|
|
197
|
+
}
|
|
198
|
+
}, () => {});
|
|
199
|
+
let servedFirst = false;
|
|
200
|
+
const tapped = {
|
|
201
|
+
[Symbol.asyncIterator]: () => ({
|
|
202
|
+
next() {
|
|
203
|
+
if (!servedFirst) {
|
|
204
|
+
servedFirst = true;
|
|
205
|
+
return firstNext.then(r => {
|
|
206
|
+
if (!r.done && !comp.disposed) comp.value = r.value;
|
|
207
|
+
return r;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return iter.next().then(r => r);
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, tapped, deferStream);
|
|
215
|
+
if (uninitialized) {
|
|
216
|
+
comp.error = new signals.NotReadyError(firstReady);
|
|
217
|
+
}
|
|
103
218
|
}
|
|
104
219
|
return;
|
|
105
220
|
}
|
|
106
221
|
comp.value = result;
|
|
107
222
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
223
|
+
function serverEffect(compute, effectFn, value, options) {
|
|
224
|
+
const ssrSource = options?.ssrSource;
|
|
225
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
226
|
+
signals.createOwner();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const ctx = sharedConfig.context;
|
|
113
230
|
const owner = signals.createOwner();
|
|
231
|
+
const comp = {
|
|
232
|
+
owner,
|
|
233
|
+
value: value,
|
|
234
|
+
compute: compute,
|
|
235
|
+
error: undefined,
|
|
236
|
+
computed: true,
|
|
237
|
+
disposed: false
|
|
238
|
+
};
|
|
239
|
+
if (ssrSource) {
|
|
240
|
+
signals.runWithOwner(owner, () => signals.onCleanup(() => {
|
|
241
|
+
comp.disposed = true;
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
114
244
|
try {
|
|
115
|
-
const result = signals.runWithOwner(owner, () => runWithObserver(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
computed: true
|
|
121
|
-
}, () => compute(value)));
|
|
122
|
-
effectFn(result, value);
|
|
245
|
+
const result = signals.runWithOwner(owner, () => runWithObserver(comp, () => compute(value)));
|
|
246
|
+
if (ssrSource) {
|
|
247
|
+
processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
|
|
248
|
+
}
|
|
249
|
+
effectFn?.(ssrSource ? comp.value ?? result : result, value);
|
|
123
250
|
} catch (err) {
|
|
124
251
|
}
|
|
125
252
|
}
|
|
253
|
+
function createEffect(compute, effect, value, options) {
|
|
254
|
+
serverEffect(compute, undefined, value, options);
|
|
255
|
+
}
|
|
256
|
+
function createRenderEffect(compute, effectFn, value, options) {
|
|
257
|
+
serverEffect(compute, effectFn, value, options);
|
|
258
|
+
}
|
|
126
259
|
function createTrackedEffect(compute, options) {
|
|
127
260
|
const o = signals.getOwner();
|
|
128
261
|
if (o?.id != null) signals.getNextChildId(o);
|
|
@@ -133,7 +266,7 @@ function createReaction(effectFn, options) {
|
|
|
133
266
|
};
|
|
134
267
|
}
|
|
135
268
|
function createOptimistic(first, second, third) {
|
|
136
|
-
return createSignal(first, second);
|
|
269
|
+
return createSignal(first, second, third);
|
|
137
270
|
}
|
|
138
271
|
function setProperty(state, property, value) {
|
|
139
272
|
if (state[property] === value) return;
|
|
@@ -141,16 +274,145 @@ function setProperty(state, property, value) {
|
|
|
141
274
|
delete state[property];
|
|
142
275
|
} else state[property] = value;
|
|
143
276
|
}
|
|
144
|
-
function createStore(
|
|
145
|
-
|
|
146
|
-
|
|
277
|
+
function createStore(first, second) {
|
|
278
|
+
if (typeof first === "function") {
|
|
279
|
+
const store = createProjection(first, second ?? {});
|
|
280
|
+
return [store, fn => fn(store)];
|
|
147
281
|
}
|
|
148
|
-
|
|
282
|
+
const state = first;
|
|
283
|
+
return [state, fn => fn(state)];
|
|
149
284
|
}
|
|
150
285
|
const createOptimisticStore = createStore;
|
|
151
|
-
function
|
|
286
|
+
function createPendingProxy(state, source) {
|
|
287
|
+
let pending = true;
|
|
288
|
+
let readTarget = state;
|
|
289
|
+
const proxy = new Proxy(state, {
|
|
290
|
+
get(obj, key, receiver) {
|
|
291
|
+
if (pending && typeof key !== "symbol") {
|
|
292
|
+
throw new signals.NotReadyError(source);
|
|
293
|
+
}
|
|
294
|
+
return Reflect.get(readTarget, key);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
return [proxy, frozen => {
|
|
298
|
+
if (frozen) readTarget = frozen;
|
|
299
|
+
pending = false;
|
|
300
|
+
}];
|
|
301
|
+
}
|
|
302
|
+
function createProjection(fn, initialValue = {}, options) {
|
|
303
|
+
const ctx = sharedConfig.context;
|
|
304
|
+
const owner = signals.createOwner();
|
|
152
305
|
const [state] = createStore(initialValue);
|
|
153
|
-
|
|
306
|
+
if (options?.ssrSource === "initial" || options?.ssrSource === "client") {
|
|
307
|
+
return state;
|
|
308
|
+
}
|
|
309
|
+
let disposed = false;
|
|
310
|
+
signals.runWithOwner(owner, () => signals.onCleanup(() => {
|
|
311
|
+
disposed = true;
|
|
312
|
+
}));
|
|
313
|
+
const ssrSource = options?.ssrSource;
|
|
314
|
+
const useProxy = ssrSource !== "hybrid";
|
|
315
|
+
const patches = [];
|
|
316
|
+
const draft = useProxy ? createDeepProxy(state, patches) : state;
|
|
317
|
+
const result = signals.runWithOwner(owner, () => fn(draft));
|
|
318
|
+
const iteratorFn = result?.[Symbol.asyncIterator];
|
|
319
|
+
if (typeof iteratorFn === "function") {
|
|
320
|
+
const iter = iteratorFn.call(result);
|
|
321
|
+
if (ssrSource === "hybrid") {
|
|
322
|
+
const promise = iter.next().then(r => {
|
|
323
|
+
promise.s = 1;
|
|
324
|
+
if (disposed) {
|
|
325
|
+
promise.v = state;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (r.value !== undefined && r.value !== state) {
|
|
329
|
+
Object.assign(state, r.value);
|
|
330
|
+
}
|
|
331
|
+
promise.v = state;
|
|
332
|
+
markReady();
|
|
333
|
+
}, () => {});
|
|
334
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, promise, options?.deferStream);
|
|
335
|
+
const [pending, markReady] = createPendingProxy(state, promise);
|
|
336
|
+
return pending;
|
|
337
|
+
} else {
|
|
338
|
+
const firstNext = iter.next();
|
|
339
|
+
const firstReady = firstNext.then(r => {
|
|
340
|
+
if (disposed) return;
|
|
341
|
+
patches.length = 0;
|
|
342
|
+
if (!r.done) {
|
|
343
|
+
if (r.value !== undefined && r.value !== draft) {
|
|
344
|
+
Object.assign(state, r.value);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
markReady(JSON.parse(JSON.stringify(state)));
|
|
348
|
+
}, () => {
|
|
349
|
+
markReady();
|
|
350
|
+
});
|
|
351
|
+
let servedFirst = false;
|
|
352
|
+
const tapped = {
|
|
353
|
+
[Symbol.asyncIterator]: () => ({
|
|
354
|
+
next() {
|
|
355
|
+
if (!servedFirst) {
|
|
356
|
+
servedFirst = true;
|
|
357
|
+
return firstNext.then(r => {
|
|
358
|
+
if (!r.done && !disposed) return {
|
|
359
|
+
done: false,
|
|
360
|
+
value: state
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
done: r.done,
|
|
364
|
+
value: undefined
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return iter.next().then(r => {
|
|
369
|
+
if (disposed) return {
|
|
370
|
+
done: true,
|
|
371
|
+
value: undefined
|
|
372
|
+
};
|
|
373
|
+
const flushed = patches.splice(0);
|
|
374
|
+
if (!r.done) {
|
|
375
|
+
if (r.value !== undefined && r.value !== draft) {
|
|
376
|
+
Object.assign(state, r.value);
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
done: false,
|
|
380
|
+
value: flushed
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
done: true,
|
|
385
|
+
value: undefined
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
};
|
|
391
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, tapped, options?.deferStream);
|
|
392
|
+
const [pending, markReady] = createPendingProxy(state, firstReady);
|
|
393
|
+
return pending;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (result instanceof Promise) {
|
|
397
|
+
const promise = result.then(v => {
|
|
398
|
+
promise.s = 1;
|
|
399
|
+
if (disposed) {
|
|
400
|
+
promise.v = state;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (v !== undefined && v !== state) {
|
|
404
|
+
Object.assign(state, v);
|
|
405
|
+
}
|
|
406
|
+
promise.v = state;
|
|
407
|
+
markReady();
|
|
408
|
+
}, () => {});
|
|
409
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, promise, options?.deferStream);
|
|
410
|
+
const [pending, markReady] = createPendingProxy(state, promise);
|
|
411
|
+
return pending;
|
|
412
|
+
}
|
|
413
|
+
if (result !== undefined && result !== state && result !== draft) {
|
|
414
|
+
Object.assign(state, result);
|
|
415
|
+
}
|
|
154
416
|
return state;
|
|
155
417
|
}
|
|
156
418
|
function reconcile(value) {
|
|
@@ -189,12 +451,23 @@ function mapArray(list, mapFn, options = {}) {
|
|
|
189
451
|
};
|
|
190
452
|
}
|
|
191
453
|
function repeat(count, mapFn, options = {}) {
|
|
454
|
+
const owner = signals.createOwner();
|
|
192
455
|
const len = count();
|
|
193
456
|
const offset = options.from?.() || 0;
|
|
194
457
|
let s = [];
|
|
195
458
|
if (len) {
|
|
196
|
-
|
|
197
|
-
|
|
459
|
+
signals.runWithOwner(owner, () => {
|
|
460
|
+
for (let i = 0; i < len; i++) {
|
|
461
|
+
const itemOwner = signals.createOwner();
|
|
462
|
+
s.push(signals.runWithOwner(itemOwner, () => mapFn(i + offset)));
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
} else if (options.fallback) {
|
|
466
|
+
s = [signals.runWithOwner(owner, () => {
|
|
467
|
+
const fo = signals.createOwner();
|
|
468
|
+
return signals.runWithOwner(fo, () => options.fallback());
|
|
469
|
+
})];
|
|
470
|
+
}
|
|
198
471
|
return () => s;
|
|
199
472
|
}
|
|
200
473
|
const ErrorContext = {
|
|
@@ -202,15 +475,21 @@ const ErrorContext = {
|
|
|
202
475
|
defaultValue: null
|
|
203
476
|
};
|
|
204
477
|
function createErrorBoundary(fn, fallback) {
|
|
478
|
+
const ctx = sharedConfig.context;
|
|
205
479
|
const owner = signals.createOwner();
|
|
480
|
+
const parent = signals.getOwner();
|
|
481
|
+
if (parent?.id != null) signals.getNextChildId(parent);
|
|
482
|
+
owner.id = owner.id + "0";
|
|
206
483
|
return signals.runWithOwner(owner, () => {
|
|
207
484
|
let result;
|
|
208
485
|
signals.setContext(ErrorContext, err => {
|
|
486
|
+
if (ctx && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, err);
|
|
209
487
|
result = fallback(err, () => {});
|
|
210
488
|
});
|
|
211
489
|
try {
|
|
212
490
|
result = fn();
|
|
213
491
|
} catch (err) {
|
|
492
|
+
if (ctx && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, err);
|
|
214
493
|
result = fallback(err, () => {});
|
|
215
494
|
}
|
|
216
495
|
return () => result;
|
|
@@ -245,7 +524,7 @@ function isPending(fn, fallback) {
|
|
|
245
524
|
throw err;
|
|
246
525
|
}
|
|
247
526
|
}
|
|
248
|
-
function
|
|
527
|
+
function latest(fn) {
|
|
249
528
|
return fn();
|
|
250
529
|
}
|
|
251
530
|
function isRefreshing() {
|
|
@@ -279,29 +558,29 @@ function useContext(context) {
|
|
|
279
558
|
return signals.getContext(context);
|
|
280
559
|
}
|
|
281
560
|
function children(fn) {
|
|
282
|
-
const
|
|
283
|
-
|
|
561
|
+
const c = createMemo(fn, undefined, {
|
|
562
|
+
lazy: true
|
|
563
|
+
});
|
|
564
|
+
const memo = createMemo(() => signals.flatten(c()), undefined, {
|
|
565
|
+
lazy: true
|
|
566
|
+
});
|
|
284
567
|
memo.toArray = () => {
|
|
285
|
-
const
|
|
286
|
-
return Array.isArray(
|
|
568
|
+
const v = memo();
|
|
569
|
+
return Array.isArray(v) ? v : v != null ? [v] : [];
|
|
287
570
|
};
|
|
288
571
|
return memo;
|
|
289
572
|
}
|
|
290
573
|
function ssrRunInScope(fn) {
|
|
291
|
-
|
|
292
|
-
const o = signals.createOwner();
|
|
293
|
-
return fn.map(f => signals.runWithOwner.bind(null, o, f));
|
|
294
|
-
}
|
|
295
|
-
return signals.runWithOwner.bind(null, signals.createOwner(), fn);
|
|
574
|
+
return fn;
|
|
296
575
|
}
|
|
297
576
|
|
|
298
577
|
function enableHydration() {}
|
|
299
578
|
function createComponent(Comp, props) {
|
|
300
579
|
return Comp(props || {});
|
|
301
580
|
}
|
|
302
|
-
function lazy(fn) {
|
|
581
|
+
function lazy(fn, moduleUrl) {
|
|
303
582
|
let p;
|
|
304
|
-
let load =
|
|
583
|
+
let load = () => {
|
|
305
584
|
if (!p) {
|
|
306
585
|
p = fn();
|
|
307
586
|
p.then(mod => {
|
|
@@ -311,15 +590,30 @@ function lazy(fn) {
|
|
|
311
590
|
return p;
|
|
312
591
|
};
|
|
313
592
|
const wrap = props => {
|
|
314
|
-
|
|
593
|
+
if (!moduleUrl) {
|
|
594
|
+
throw new Error("lazy() used in SSR without a moduleUrl. " + "All lazy() components require a moduleUrl for correct hydration. " + "This is typically injected by the bundler plugin.");
|
|
595
|
+
}
|
|
596
|
+
if (!sharedConfig.context?.resolveAssets) {
|
|
597
|
+
throw new Error(`lazy() called with moduleUrl "${moduleUrl}" but no asset manifest is set. ` + "Pass a manifest option to renderToStream/renderToString.");
|
|
598
|
+
}
|
|
315
599
|
load();
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
|
|
600
|
+
const ctx = sharedConfig.context;
|
|
601
|
+
if (!ctx?.registerAsset || !ctx.resolveAssets) return;
|
|
602
|
+
const assets = ctx.resolveAssets(moduleUrl);
|
|
603
|
+
if (assets) {
|
|
604
|
+
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
605
|
+
for (let i = 0; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
|
|
606
|
+
ctx.registerModule?.(moduleUrl, assets.js[0]);
|
|
607
|
+
}
|
|
608
|
+
if (ctx?.async) {
|
|
609
|
+
ctx.block(p.then(() => {
|
|
319
610
|
p.s = "success";
|
|
320
611
|
}));
|
|
321
612
|
}
|
|
322
|
-
|
|
613
|
+
return createMemo(() => {
|
|
614
|
+
if (!p.v) throw new signals.NotReadyError(p);
|
|
615
|
+
return p.v(props);
|
|
616
|
+
});
|
|
323
617
|
};
|
|
324
618
|
wrap.preload = load;
|
|
325
619
|
return wrap;
|
|
@@ -345,20 +639,27 @@ function Repeat(props) {
|
|
|
345
639
|
return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
|
|
346
640
|
}
|
|
347
641
|
function Show(props) {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
return child(() => when);
|
|
353
|
-
}
|
|
354
|
-
return child;
|
|
642
|
+
const o = signals.getOwner();
|
|
643
|
+
if (o?.id != null) {
|
|
644
|
+
signals.getNextChildId(o);
|
|
645
|
+
if (!props.keyed) signals.getNextChildId(o);
|
|
355
646
|
}
|
|
356
|
-
return
|
|
647
|
+
return createMemo(() => {
|
|
648
|
+
const when = props.when;
|
|
649
|
+
if (when) {
|
|
650
|
+
const child = props.children;
|
|
651
|
+
if (typeof child === "function" && child.length > 0) {
|
|
652
|
+
return child(() => when);
|
|
653
|
+
}
|
|
654
|
+
return child;
|
|
655
|
+
}
|
|
656
|
+
return props.fallback;
|
|
657
|
+
});
|
|
357
658
|
}
|
|
358
659
|
function Switch(props) {
|
|
359
660
|
const chs = children(() => props.children);
|
|
360
661
|
const o = signals.getOwner();
|
|
361
|
-
if (o) signals.getNextChildId(o);
|
|
662
|
+
if (o?.id != null) signals.getNextChildId(o);
|
|
362
663
|
return createMemo(() => {
|
|
363
664
|
let conds = chs();
|
|
364
665
|
if (!Array.isArray(conds)) conds = [conds];
|
|
@@ -402,18 +703,35 @@ function Loading(props) {
|
|
|
402
703
|
const id = o.id;
|
|
403
704
|
o.id = id + "00";
|
|
404
705
|
let runPromise;
|
|
706
|
+
let serializeBuffer = [];
|
|
707
|
+
const origSerialize = ctx.serialize;
|
|
405
708
|
function runInitially() {
|
|
406
709
|
o.dispose(false);
|
|
407
|
-
|
|
710
|
+
serializeBuffer = [];
|
|
711
|
+
ctx.serialize = (id, p, deferStream) => {
|
|
712
|
+
serializeBuffer.push([id, p, deferStream]);
|
|
713
|
+
};
|
|
714
|
+
const prevBoundary = ctx._currentBoundaryId;
|
|
715
|
+
ctx._currentBoundaryId = id;
|
|
716
|
+
const result = signals.runWithOwner(o, () => {
|
|
408
717
|
try {
|
|
409
|
-
return ctx.resolve(
|
|
718
|
+
return ctx.resolve(props.children);
|
|
410
719
|
} catch (err) {
|
|
411
720
|
runPromise = ssrHandleError(err);
|
|
412
721
|
}
|
|
413
722
|
});
|
|
723
|
+
ctx._currentBoundaryId = prevBoundary;
|
|
724
|
+
ctx.serialize = origSerialize;
|
|
725
|
+
return result;
|
|
414
726
|
}
|
|
415
727
|
let ret = runInitially();
|
|
416
|
-
if (!(runPromise || ret?.p?.length))
|
|
728
|
+
if (!(runPromise || ret?.p?.length)) {
|
|
729
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
730
|
+
serializeBuffer = [];
|
|
731
|
+
const modules = ctx.getBoundaryModules?.(id);
|
|
732
|
+
if (modules) ctx.serialize(id + "_assets", modules);
|
|
733
|
+
return ret;
|
|
734
|
+
}
|
|
417
735
|
const fallbackOwner = signals.createOwner({
|
|
418
736
|
id
|
|
419
737
|
});
|
|
@@ -421,19 +739,30 @@ function Loading(props) {
|
|
|
421
739
|
if (ctx.async) {
|
|
422
740
|
const done = ctx.registerFragment(id);
|
|
423
741
|
(async () => {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
742
|
+
try {
|
|
743
|
+
while (runPromise) {
|
|
744
|
+
o.dispose(false);
|
|
745
|
+
await runPromise;
|
|
746
|
+
runPromise = undefined;
|
|
747
|
+
ret = runInitially();
|
|
748
|
+
}
|
|
749
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
750
|
+
serializeBuffer = [];
|
|
751
|
+
while (ret.p.length) {
|
|
752
|
+
await Promise.all(ret.p);
|
|
753
|
+
ret = signals.runWithOwner(o, () => ctx.ssr(ret.t, ...ret.h));
|
|
754
|
+
}
|
|
755
|
+
done(ret.t[0]);
|
|
756
|
+
} catch (err) {
|
|
757
|
+
done(undefined, err);
|
|
432
758
|
}
|
|
433
|
-
done(ret.t[0]);
|
|
434
759
|
})();
|
|
435
760
|
return signals.runWithOwner(fallbackOwner, () => ctx.ssr([`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`], ctx.escape(props.fallback)));
|
|
436
761
|
}
|
|
762
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
763
|
+
serializeBuffer = [];
|
|
764
|
+
const modules = ctx.getBoundaryModules?.(id);
|
|
765
|
+
if (modules) ctx.serialize(id + "_assets", modules);
|
|
437
766
|
ctx.serialize(id, "$$f");
|
|
438
767
|
return signals.runWithOwner(fallbackOwner, () => props.fallback);
|
|
439
768
|
}
|
|
@@ -452,6 +781,10 @@ Object.defineProperty(exports, "NotReadyError", {
|
|
|
452
781
|
enumerable: true,
|
|
453
782
|
get: function () { return signals.NotReadyError; }
|
|
454
783
|
});
|
|
784
|
+
Object.defineProperty(exports, "createOwner", {
|
|
785
|
+
enumerable: true,
|
|
786
|
+
get: function () { return signals.createOwner; }
|
|
787
|
+
});
|
|
455
788
|
Object.defineProperty(exports, "createRoot", {
|
|
456
789
|
enumerable: true,
|
|
457
790
|
get: function () { return signals.createRoot; }
|
|
@@ -460,6 +793,10 @@ Object.defineProperty(exports, "flatten", {
|
|
|
460
793
|
enumerable: true,
|
|
461
794
|
get: function () { return signals.flatten; }
|
|
462
795
|
});
|
|
796
|
+
Object.defineProperty(exports, "getNextChildId", {
|
|
797
|
+
enumerable: true,
|
|
798
|
+
get: function () { return signals.getNextChildId; }
|
|
799
|
+
});
|
|
463
800
|
Object.defineProperty(exports, "getOwner", {
|
|
464
801
|
enumerable: true,
|
|
465
802
|
get: function () { return signals.getOwner; }
|
|
@@ -492,6 +829,10 @@ Object.defineProperty(exports, "snapshot", {
|
|
|
492
829
|
enumerable: true,
|
|
493
830
|
get: function () { return signals.snapshot; }
|
|
494
831
|
});
|
|
832
|
+
Object.defineProperty(exports, "storePath", {
|
|
833
|
+
enumerable: true,
|
|
834
|
+
get: function () { return signals.storePath; }
|
|
835
|
+
});
|
|
495
836
|
exports.$DEVCOMP = $DEVCOMP;
|
|
496
837
|
exports.DEV = DEV;
|
|
497
838
|
exports.Errored = Errored;
|
|
@@ -505,6 +846,7 @@ exports.action = action;
|
|
|
505
846
|
exports.children = children;
|
|
506
847
|
exports.createComponent = createComponent;
|
|
507
848
|
exports.createContext = createContext;
|
|
849
|
+
exports.createDeepProxy = createDeepProxy;
|
|
508
850
|
exports.createEffect = createEffect;
|
|
509
851
|
exports.createMemo = createMemo;
|
|
510
852
|
exports.createOptimistic = createOptimistic;
|
|
@@ -522,10 +864,10 @@ exports.flush = flush;
|
|
|
522
864
|
exports.getObserver = getObserver;
|
|
523
865
|
exports.isPending = isPending;
|
|
524
866
|
exports.isRefreshing = isRefreshing;
|
|
867
|
+
exports.latest = latest;
|
|
525
868
|
exports.lazy = lazy;
|
|
526
869
|
exports.mapArray = mapArray;
|
|
527
870
|
exports.onSettled = onSettled;
|
|
528
|
-
exports.pending = pending;
|
|
529
871
|
exports.reconcile = reconcile;
|
|
530
872
|
exports.refresh = refresh;
|
|
531
873
|
exports.repeat = repeat;
|