solid-js 1.5.0-beta.4 → 1.5.0-beta.7
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 +2 -5
- package/dist/dev.js +2 -5
- package/dist/server.cjs +7 -10
- package/dist/server.js +7 -10
- package/dist/solid.cjs +2 -5
- package/dist/solid.js +2 -5
- package/jsx-runtime.d.ts +1 -1
- package/package.json +8 -1
- package/types/index.d.ts +1 -1
- package/types/jsx.d.ts +1 -1
- package/types/reactive/signal.d.ts +2 -7
- package/types/server/reactive.d.ts +1 -0
- package/types/server/rendering.d.ts +5 -4
- package/web/dist/server.cjs +8 -4
- package/web/dist/server.js +8 -4
- package/web/types/client.d.ts +1 -1
- package/web/types/server.d.ts +1 -1
package/dist/dev.cjs
CHANGED
|
@@ -264,7 +264,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
264
264
|
resolved = ("initialValue" in options),
|
|
265
265
|
dynamic = typeof source === "function" && createMemo(source);
|
|
266
266
|
const contexts = new Set(),
|
|
267
|
-
[value, setValue] =
|
|
267
|
+
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
268
268
|
[track, trigger] = createSignal(undefined, {
|
|
269
269
|
equals: false
|
|
270
270
|
}),
|
|
@@ -272,7 +272,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
272
272
|
if (sharedConfig.context) {
|
|
273
273
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
274
274
|
let v;
|
|
275
|
-
if (options.
|
|
275
|
+
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
|
|
276
276
|
}
|
|
277
277
|
function loadEnd(p, v, success, key) {
|
|
278
278
|
if (pr === p) {
|
|
@@ -352,9 +352,6 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
352
352
|
return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
|
|
353
353
|
}
|
|
354
354
|
Object.defineProperties(read, {
|
|
355
|
-
value: {
|
|
356
|
-
get: () => value()
|
|
357
|
-
},
|
|
358
355
|
state: {
|
|
359
356
|
get: () => state()
|
|
360
357
|
},
|
package/dist/dev.js
CHANGED
|
@@ -260,7 +260,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
260
260
|
resolved = ("initialValue" in options),
|
|
261
261
|
dynamic = typeof source === "function" && createMemo(source);
|
|
262
262
|
const contexts = new Set(),
|
|
263
|
-
[value, setValue] =
|
|
263
|
+
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
264
264
|
[track, trigger] = createSignal(undefined, {
|
|
265
265
|
equals: false
|
|
266
266
|
}),
|
|
@@ -268,7 +268,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
268
268
|
if (sharedConfig.context) {
|
|
269
269
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
270
270
|
let v;
|
|
271
|
-
if (options.
|
|
271
|
+
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
|
|
272
272
|
}
|
|
273
273
|
function loadEnd(p, v, success, key) {
|
|
274
274
|
if (pr === p) {
|
|
@@ -348,9 +348,6 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
348
348
|
return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
|
|
349
349
|
}
|
|
350
350
|
Object.defineProperties(read, {
|
|
351
|
-
value: {
|
|
352
|
-
get: () => value()
|
|
353
|
-
},
|
|
354
351
|
state: {
|
|
355
352
|
get: () => state()
|
|
356
353
|
},
|
package/dist/server.cjs
CHANGED
|
@@ -396,10 +396,10 @@ function createResource(source, fetcher, options = {}) {
|
|
|
396
396
|
const contexts = new Set();
|
|
397
397
|
const id = sharedConfig.context.id + sharedConfig.context.count++;
|
|
398
398
|
let resource = {};
|
|
399
|
-
let value = options.initialValue;
|
|
399
|
+
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
|
|
400
400
|
let p;
|
|
401
401
|
let error;
|
|
402
|
-
if (sharedConfig.context.async &&
|
|
402
|
+
if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
|
|
403
403
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
404
404
|
if (resource.ref) {
|
|
405
405
|
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
|
|
@@ -409,7 +409,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
409
409
|
const read = () => {
|
|
410
410
|
if (error) throw error;
|
|
411
411
|
if (resourceContext && p) resourceContext.push(p);
|
|
412
|
-
const resolved =
|
|
412
|
+
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
413
413
|
if (!resolved && read.loading) {
|
|
414
414
|
const ctx = useContext(SuspenseContext);
|
|
415
415
|
if (ctx) {
|
|
@@ -422,12 +422,9 @@ function createResource(source, fetcher, options = {}) {
|
|
|
422
422
|
read.loading = false;
|
|
423
423
|
read.error = undefined;
|
|
424
424
|
read.state = "initialValue" in options ? "resolved" : "unresolved";
|
|
425
|
-
Object.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
},
|
|
429
|
-
latest: {
|
|
430
|
-
get: () => read()
|
|
425
|
+
Object.defineProperty(read, "latest", {
|
|
426
|
+
get() {
|
|
427
|
+
return read();
|
|
431
428
|
}
|
|
432
429
|
});
|
|
433
430
|
function load() {
|
|
@@ -475,7 +472,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
475
472
|
p = null;
|
|
476
473
|
return ctx.resources[id].data;
|
|
477
474
|
}
|
|
478
|
-
if (
|
|
475
|
+
if (options.ssrLoadFrom !== "initial") load();
|
|
479
476
|
return resource.ref = [read, {
|
|
480
477
|
refetch: load,
|
|
481
478
|
mutate: v => value = v
|
package/dist/server.js
CHANGED
|
@@ -392,10 +392,10 @@ function createResource(source, fetcher, options = {}) {
|
|
|
392
392
|
const contexts = new Set();
|
|
393
393
|
const id = sharedConfig.context.id + sharedConfig.context.count++;
|
|
394
394
|
let resource = {};
|
|
395
|
-
let value = options.initialValue;
|
|
395
|
+
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
|
|
396
396
|
let p;
|
|
397
397
|
let error;
|
|
398
|
-
if (sharedConfig.context.async &&
|
|
398
|
+
if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
|
|
399
399
|
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
400
400
|
if (resource.ref) {
|
|
401
401
|
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
|
|
@@ -405,7 +405,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
405
405
|
const read = () => {
|
|
406
406
|
if (error) throw error;
|
|
407
407
|
if (resourceContext && p) resourceContext.push(p);
|
|
408
|
-
const resolved =
|
|
408
|
+
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
409
409
|
if (!resolved && read.loading) {
|
|
410
410
|
const ctx = useContext(SuspenseContext);
|
|
411
411
|
if (ctx) {
|
|
@@ -418,12 +418,9 @@ function createResource(source, fetcher, options = {}) {
|
|
|
418
418
|
read.loading = false;
|
|
419
419
|
read.error = undefined;
|
|
420
420
|
read.state = "initialValue" in options ? "resolved" : "unresolved";
|
|
421
|
-
Object.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
},
|
|
425
|
-
latest: {
|
|
426
|
-
get: () => read()
|
|
421
|
+
Object.defineProperty(read, "latest", {
|
|
422
|
+
get() {
|
|
423
|
+
return read();
|
|
427
424
|
}
|
|
428
425
|
});
|
|
429
426
|
function load() {
|
|
@@ -471,7 +468,7 @@ function createResource(source, fetcher, options = {}) {
|
|
|
471
468
|
p = null;
|
|
472
469
|
return ctx.resources[id].data;
|
|
473
470
|
}
|
|
474
|
-
if (
|
|
471
|
+
if (options.ssrLoadFrom !== "initial") load();
|
|
475
472
|
return resource.ref = [read, {
|
|
476
473
|
refetch: load,
|
|
477
474
|
mutate: v => value = v
|
package/dist/solid.cjs
CHANGED
|
@@ -256,7 +256,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
256
256
|
resolved = ("initialValue" in options),
|
|
257
257
|
dynamic = typeof source === "function" && createMemo(source);
|
|
258
258
|
const contexts = new Set(),
|
|
259
|
-
[value, setValue] =
|
|
259
|
+
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
260
260
|
[track, trigger] = createSignal(undefined, {
|
|
261
261
|
equals: false
|
|
262
262
|
}),
|
|
@@ -264,7 +264,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
264
264
|
if (sharedConfig.context) {
|
|
265
265
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
266
266
|
let v;
|
|
267
|
-
if (options.
|
|
267
|
+
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
|
|
268
268
|
}
|
|
269
269
|
function loadEnd(p, v, success, key) {
|
|
270
270
|
if (pr === p) {
|
|
@@ -344,9 +344,6 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
344
344
|
return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
|
|
345
345
|
}
|
|
346
346
|
Object.defineProperties(read, {
|
|
347
|
-
value: {
|
|
348
|
-
get: () => value()
|
|
349
|
-
},
|
|
350
347
|
state: {
|
|
351
348
|
get: () => state()
|
|
352
349
|
},
|
package/dist/solid.js
CHANGED
|
@@ -252,7 +252,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
252
252
|
resolved = ("initialValue" in options),
|
|
253
253
|
dynamic = typeof source === "function" && createMemo(source);
|
|
254
254
|
const contexts = new Set(),
|
|
255
|
-
[value, setValue] =
|
|
255
|
+
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
256
256
|
[track, trigger] = createSignal(undefined, {
|
|
257
257
|
equals: false
|
|
258
258
|
}),
|
|
@@ -260,7 +260,7 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
260
260
|
if (sharedConfig.context) {
|
|
261
261
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
262
262
|
let v;
|
|
263
|
-
if (options.
|
|
263
|
+
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0];
|
|
264
264
|
}
|
|
265
265
|
function loadEnd(p, v, success, key) {
|
|
266
266
|
if (pr === p) {
|
|
@@ -340,9 +340,6 @@ function createResource(pSource, pFetcher, pOptions) {
|
|
|
340
340
|
return p.then(v => loadEnd(p, v, true, lookup), e => loadEnd(p, e, false));
|
|
341
341
|
}
|
|
342
342
|
Object.defineProperties(read, {
|
|
343
|
-
value: {
|
|
344
|
-
get: () => value()
|
|
345
|
-
},
|
|
346
343
|
state: {
|
|
347
344
|
get: () => state()
|
|
348
345
|
},
|
package/jsx-runtime.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./types/jsx"
|
|
1
|
+
export * from "./types/jsx";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.5.0-beta.
|
|
4
|
+
"version": "1.5.0-beta.7",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
"require": "./dist/solid.cjs"
|
|
74
74
|
},
|
|
75
75
|
"./dist/*": "./dist/*",
|
|
76
|
+
"./jsx-runtime": {
|
|
77
|
+
"types": "./types/jsx.d.ts",
|
|
78
|
+
"default": "./dist/solid.js"
|
|
79
|
+
},
|
|
76
80
|
"./store": {
|
|
77
81
|
"browser": {
|
|
78
82
|
"development": {
|
|
@@ -193,6 +197,9 @@
|
|
|
193
197
|
"compiler",
|
|
194
198
|
"performance"
|
|
195
199
|
],
|
|
200
|
+
"dependencies": {
|
|
201
|
+
"csstype": "^3.1.0"
|
|
202
|
+
},
|
|
196
203
|
"scripts": {
|
|
197
204
|
"build": "npm-run-all -nl build:*",
|
|
198
205
|
"build:clean": "rimraf dist/ coverage/ store/dist/ web/dist/ h/dist/ h/jsx-runtime/dist html/dist/",
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createReaction, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $DEVCOMP, $PROXY, $TRACK } from "./reactive/signal.js";
|
|
2
|
-
export type { Accessor, Setter, Signal, Resource, ResourceOptions, ResourceReturn, ResourceFetcher, ResourceFetcherInfo, ChildrenReturn, Context, ReturnTypes, Owner, InitializedResource, InitializedResourceOptions, InitializedResourceReturn } from "./reactive/signal.js";
|
|
2
|
+
export type { Accessor, Setter, Signal, Resource, ResourceActions, ResourceSource, ResourceOptions, ResourceReturn, ResourceFetcher, ResourceFetcherInfo, ChildrenReturn, Context, ReturnTypes, Owner, InitializedResource, InitializedResourceOptions, InitializedResourceReturn } from "./reactive/signal.js";
|
|
3
3
|
export * from "./reactive/observable.js";
|
|
4
4
|
export * from "./reactive/scheduler.js";
|
|
5
5
|
export * from "./reactive/array.js";
|
package/types/jsx.d.ts
CHANGED
|
@@ -197,7 +197,6 @@ export interface MemoOptions<T> extends EffectOptions {
|
|
|
197
197
|
export declare function createMemo<Next extends Prev, Prev = Next>(fn: EffectFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
|
|
198
198
|
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(fn: EffectFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
|
|
199
199
|
interface Unresolved {
|
|
200
|
-
value: undefined;
|
|
201
200
|
state: "unresolved";
|
|
202
201
|
loading: false;
|
|
203
202
|
error: undefined;
|
|
@@ -205,7 +204,6 @@ interface Unresolved {
|
|
|
205
204
|
(): undefined;
|
|
206
205
|
}
|
|
207
206
|
interface Pending {
|
|
208
|
-
value: undefined;
|
|
209
207
|
state: "pending";
|
|
210
208
|
loading: true;
|
|
211
209
|
error: undefined;
|
|
@@ -213,7 +211,6 @@ interface Pending {
|
|
|
213
211
|
(): undefined;
|
|
214
212
|
}
|
|
215
213
|
interface Ready<T> {
|
|
216
|
-
value: T;
|
|
217
214
|
state: "ready";
|
|
218
215
|
loading: false;
|
|
219
216
|
error: undefined;
|
|
@@ -221,7 +218,6 @@ interface Ready<T> {
|
|
|
221
218
|
(): T;
|
|
222
219
|
}
|
|
223
220
|
interface Refreshing<T> {
|
|
224
|
-
value: T;
|
|
225
221
|
state: "refreshing";
|
|
226
222
|
loading: true;
|
|
227
223
|
error: undefined;
|
|
@@ -229,7 +225,6 @@ interface Refreshing<T> {
|
|
|
229
225
|
(): T;
|
|
230
226
|
}
|
|
231
227
|
interface Errored {
|
|
232
|
-
value: never;
|
|
233
228
|
state: "errored";
|
|
234
229
|
loading: false;
|
|
235
230
|
error: any;
|
|
@@ -252,8 +247,8 @@ export declare type ResourceOptions<T, S = unknown> = {
|
|
|
252
247
|
initialValue?: T;
|
|
253
248
|
name?: string;
|
|
254
249
|
deferStream?: boolean;
|
|
255
|
-
|
|
256
|
-
|
|
250
|
+
ssrLoadFrom?: "initial" | "server";
|
|
251
|
+
storage?: (init: T | undefined) => [Accessor<T | undefined>, Setter<T | undefined>];
|
|
257
252
|
onHydrated?: (k: S | undefined, info: {
|
|
258
253
|
value: T | undefined;
|
|
259
254
|
}) => void;
|
|
@@ -4,6 +4,7 @@ export declare const $DEVCOMP: unique symbol;
|
|
|
4
4
|
export declare const DEV: {};
|
|
5
5
|
export declare type Accessor<T> = () => T;
|
|
6
6
|
export declare type Setter<T> = undefined extends T ? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U;
|
|
7
|
+
export declare type Signal<T> = [get: Accessor<T>, set: Setter<T>];
|
|
7
8
|
export declare const BRANCH: unique symbol;
|
|
8
9
|
export declare function castError(err: any): string | Error;
|
|
9
10
|
export declare let Owner: Owner | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Setter } from "./reactive.js";
|
|
1
|
+
import { Setter, Signal } from "./reactive.js";
|
|
2
2
|
import type { JSX } from "../jsx.js";
|
|
3
3
|
export declare type Component<P = {}> = (props: P) => JSX.Element;
|
|
4
4
|
export declare type VoidProps<P = {}> = P & {
|
|
@@ -72,7 +72,6 @@ export declare function ErrorBoundary(props: {
|
|
|
72
72
|
};
|
|
73
73
|
export interface Resource<T> {
|
|
74
74
|
(): T | undefined;
|
|
75
|
-
value: T | undefined;
|
|
76
75
|
state: "unresolved" | "pending" | "ready" | "refreshing" | "errored";
|
|
77
76
|
loading: boolean;
|
|
78
77
|
error: any;
|
|
@@ -101,13 +100,15 @@ export declare type ResourceOptions<T> = undefined extends T ? {
|
|
|
101
100
|
initialValue?: T;
|
|
102
101
|
name?: string;
|
|
103
102
|
deferStream?: boolean;
|
|
104
|
-
|
|
103
|
+
ssrLoadFrom?: "initial" | "server";
|
|
104
|
+
storage?: () => Signal<T | undefined>;
|
|
105
105
|
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
|
|
106
106
|
} : {
|
|
107
107
|
initialValue: T;
|
|
108
108
|
name?: string;
|
|
109
109
|
deferStream?: boolean;
|
|
110
|
-
|
|
110
|
+
ssrLoadFrom?: "initial" | "server";
|
|
111
|
+
storage?: (v?: T) => Signal<T | undefined>;
|
|
111
112
|
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
|
|
112
113
|
};
|
|
113
114
|
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
|
package/web/dist/server.cjs
CHANGED
|
@@ -266,7 +266,8 @@ function toRefParam(index) {
|
|
|
266
266
|
const REPLACE_SCRIPT = `function $df(e,t,d,l){d=document.getElementById(e),(l=document.getElementById("pl-"+e))&&l.replaceWith(...d.childNodes),d.remove(),_$HY.set(e,t)}`;
|
|
267
267
|
function renderToString(code, options = {}) {
|
|
268
268
|
let scripts = "";
|
|
269
|
-
|
|
269
|
+
let context;
|
|
270
|
+
solidJs.sharedConfig.context = context = {
|
|
270
271
|
id: options.renderId || "",
|
|
271
272
|
count: 0,
|
|
272
273
|
suspense: {},
|
|
@@ -277,7 +278,9 @@ function renderToString(code, options = {}) {
|
|
|
277
278
|
scripts += `_$HY.set("${id}", ${stringify(p)});`;
|
|
278
279
|
}
|
|
279
280
|
};
|
|
280
|
-
let html =
|
|
281
|
+
let html = resolveSSRNode(escape(code()));
|
|
282
|
+
solidJs.sharedConfig.context = undefined;
|
|
283
|
+
html = injectAssets(context.assets, html);
|
|
281
284
|
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
282
285
|
return html;
|
|
283
286
|
}
|
|
@@ -397,6 +400,7 @@ function renderToStream(code, options = {}) {
|
|
|
397
400
|
};
|
|
398
401
|
let html = resolveSSRNode(escape(code()));
|
|
399
402
|
function doShell() {
|
|
403
|
+
solidJs.sharedConfig.context = undefined;
|
|
400
404
|
html = injectAssets(context.assets, html);
|
|
401
405
|
for (const key in context.resources) {
|
|
402
406
|
if (!("data" in context.resources[key] || context.resources[key].ref[0].error)) pushTask(`_$HY.init("${key}")`);
|
|
@@ -634,7 +638,7 @@ function injectAssets(assets, html) {
|
|
|
634
638
|
if (!assets || !assets.length) return html;
|
|
635
639
|
let out = "";
|
|
636
640
|
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
637
|
-
return html.replace(
|
|
641
|
+
return html.replace(`</head>`, out + `</head>`);
|
|
638
642
|
}
|
|
639
643
|
function injectScripts(html, scripts, nonce) {
|
|
640
644
|
const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
|
|
@@ -725,7 +729,7 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
725
729
|
}
|
|
726
730
|
function ssrSpread(props, isSVG, skipChildren) {
|
|
727
731
|
let result = "";
|
|
728
|
-
if (props == null) return
|
|
732
|
+
if (props == null) return result;
|
|
729
733
|
if (typeof props === "function") props = props();
|
|
730
734
|
const keys = Object.keys(props);
|
|
731
735
|
let classResolved;
|
package/web/dist/server.js
CHANGED
|
@@ -263,7 +263,8 @@ function toRefParam(index) {
|
|
|
263
263
|
const REPLACE_SCRIPT = `function $df(e,t,d,l){d=document.getElementById(e),(l=document.getElementById("pl-"+e))&&l.replaceWith(...d.childNodes),d.remove(),_$HY.set(e,t)}`;
|
|
264
264
|
function renderToString(code, options = {}) {
|
|
265
265
|
let scripts = "";
|
|
266
|
-
|
|
266
|
+
let context;
|
|
267
|
+
sharedConfig.context = context = {
|
|
267
268
|
id: options.renderId || "",
|
|
268
269
|
count: 0,
|
|
269
270
|
suspense: {},
|
|
@@ -274,7 +275,9 @@ function renderToString(code, options = {}) {
|
|
|
274
275
|
scripts += `_$HY.set("${id}", ${stringify(p)});`;
|
|
275
276
|
}
|
|
276
277
|
};
|
|
277
|
-
let html =
|
|
278
|
+
let html = resolveSSRNode(escape(code()));
|
|
279
|
+
sharedConfig.context = undefined;
|
|
280
|
+
html = injectAssets(context.assets, html);
|
|
278
281
|
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
279
282
|
return html;
|
|
280
283
|
}
|
|
@@ -394,6 +397,7 @@ function renderToStream(code, options = {}) {
|
|
|
394
397
|
};
|
|
395
398
|
let html = resolveSSRNode(escape(code()));
|
|
396
399
|
function doShell() {
|
|
400
|
+
sharedConfig.context = undefined;
|
|
397
401
|
html = injectAssets(context.assets, html);
|
|
398
402
|
for (const key in context.resources) {
|
|
399
403
|
if (!("data" in context.resources[key] || context.resources[key].ref[0].error)) pushTask(`_$HY.init("${key}")`);
|
|
@@ -631,7 +635,7 @@ function injectAssets(assets, html) {
|
|
|
631
635
|
if (!assets || !assets.length) return html;
|
|
632
636
|
let out = "";
|
|
633
637
|
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
634
|
-
return html.replace(
|
|
638
|
+
return html.replace(`</head>`, out + `</head>`);
|
|
635
639
|
}
|
|
636
640
|
function injectScripts(html, scripts, nonce) {
|
|
637
641
|
const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
|
|
@@ -722,7 +726,7 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
722
726
|
}
|
|
723
727
|
function ssrSpread(props, isSVG, skipChildren) {
|
|
724
728
|
let result = "";
|
|
725
|
-
if (props == null) return
|
|
729
|
+
if (props == null) return result;
|
|
726
730
|
if (typeof props === "function") props = props();
|
|
727
731
|
const keys = Object.keys(props);
|
|
728
732
|
let classResolved;
|
package/web/types/client.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export function getHydrationKey(): string;
|
|
|
62
62
|
export function getNextElement(template?: HTMLTemplateElement): Element;
|
|
63
63
|
export function getNextMatch(start: Node, elementName: string): Element;
|
|
64
64
|
export function getNextMarker(start: Node): [Node, Array<Node>];
|
|
65
|
-
export function
|
|
65
|
+
export function useAssets(fn: () => string): void;
|
|
66
66
|
export function getAssets(): string;
|
|
67
67
|
export function Assets(props: { children?: JSX.Element }): JSX.Element;
|
|
68
68
|
export function HydrationScript(): JSX.Element;
|
package/web/types/server.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export function ssrAttribute(key: string, value: any, isBoolean: boolean): strin
|
|
|
37
37
|
export function ssrHydrationKey(): string;
|
|
38
38
|
export function resolveSSRNode(node: any): string;
|
|
39
39
|
export function escape(html: string): string;
|
|
40
|
-
export function
|
|
40
|
+
export function useAssets(fn: () => string): void;
|
|
41
41
|
export function getAssets(): string;
|
|
42
42
|
export function getHydrationKey(): string;
|
|
43
43
|
export function effect<T>(fn: (prev?: T) => T, init?: T): void;
|