Skip to content

Commit 0753ed9

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-4444
2 parents eea75cf + 71a6a75 commit 0753ed9

14 files changed

Lines changed: 706 additions & 62 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
`AssetManifest` admits a manifest that sets `_base` (#4502). It was `Record<string, Entry> & { _base?: string }`, and since `_base` also falls under the string index signature it had to be an entry too, so a manifest literal with `_base: "/"` did not type-check. The index signature now carries entries, metadata strings (`_base`, and any an integration stamps, such as the vite plugin's `_entry`) and `undefined`, so a read by key is an entry once narrowed (`typeof entry === "object"`). The server renderer narrows the same way: a metadata key enumerated while registering entry assets, or asked for by `resolveAssets`, is skipped instead of throwing.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Server-rendered `<link rel="modulepreload">` hints for modules outside the entry's static import closure (lazy and route chunks, and modules registered later through `registerAsset("module")`, streamed hints included) now carry `fetchpriority="low"`, so they yield bandwidth to the modules hydration waits on. The entry's static imports and modulepreload links written through the head API keep their default priority. `renderToString` and `renderToStream` take `lowPriorityPreloads: false` to turn the hint off. In an rc.15 app (Tailwind, five entry imports, four route chunks) patched the same way, Chrome under Lighthouse's devtools throttling hydrated about 310 ms sooner with an unchanged first paint.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
A memo between a render effect and an async memo in flight is born held with the mount that first reads it (#4504, D-2, D-22, D-27). With an input that reads `latest()`/`isPending()`, the memo carried that verdict posture by what it read (D-25), and its pass in a plain mount mid-flight stamped the posture from the read of the pending async memo even though the read threw: at the landing the memo re-ran as a verdict reader and was served the async memo's committed value, so the held reader showed the old answer at the landing and the new one only at the commit (`r:2`, then `r:4`). A read of a pending node now hands on no posture to a pass that is not a verdict reader already: the reader waits for the re-ask's answer and shows it once (`r:4`), as when it reads the async memo directly. A memo that was already a verdict reader on screen keeps its posture.

‎packages/signals/src/core/core.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,18 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
21022102
// it probed inline: it reads held values as the screen and shows the
21032103
// verdict now. Not an effect: a render effect is a frame reader
21042104
// already, and a user effect's posture is its own reads'.
2105+
// A read of a pending node hands on no posture to a pass that is
2106+
// not a verdict reader already (#4504): such a read throws — it read
2107+
// no value, and a node whose flight is up is the hold's work, not a
2108+
// verdict reader (D-25, #3884). Stamped, the pass's next run — the
2109+
// hold's re-run at the landing of a memo whose plain mount read
2110+
// held its reader (D-2, D-27) — was served the screen beside the
2111+
// answer its reader waited for (F-2, D-22). A verdict reader keeps
2112+
// the posture it is served the screen with (`observeFlight`).
21052113
// (A verdict memo exists only with the verdict engine installed.)
21062114
if (observeFlightHook && !(c as any)._type)
2107-
(c as Computed<any>)._flags |= owner._config & CONFIG_VERDICT;
2115+
(c as Computed<any>)._flags |=
2116+
owner._config & CONFIG_VERDICT & (owner._statusFlags & STATUS_PENDING ? c._config : -1);
21082117
}
21092118
}
21102119
if (__TEST__)
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
/**
2+
* #4504: a memo between a render effect and an async memo in flight, read for
3+
* the first time by a mount made mid-flight.
4+
*
5+
* `m0` is the async memo's input; `m1 = createMemo(async () => m0())` takes
6+
* 100 ms. A plain write re-asks `m1` while nothing reads it, and 20 ms into
7+
* the flight a render effect mounts and reads `mb`, a memo over `m1`
8+
* (`() => m1()`, `() => m1() * 10`) that nothing has read before.
9+
*
10+
* With `m0 = createMemo(() => latest(s) + s())` (a verdict reader: it called
11+
* `latest`) `m1` and `mb` carried that posture by what they read (D-25: a
12+
* memo's posture is what it reads). The mount's pass of `mb` read `m1`
13+
* plainly — `mb` was pending, so the pass is not a verdict reader (D-25,
14+
* #3884) — and threw, so the reader held the mount (D-2, F-2). But the read
15+
* of the pending `m1` still stamped the posture on `mb` for its next pass,
16+
* so at the landing `mb` re-ran as a verdict reader and was served `m1`'s
17+
* committed value (the screen): `r:2` published at the landing, then `r:4`
18+
* at the commit — a held reader shown a value older than the one it waited
19+
* for (F-2, F-1).
20+
*
21+
* Ruled: a plain read in a mount is not display-ahead (D-27); the reader of
22+
* a derivation with no value to show for the re-ask is born held (D-2) and
23+
* shows the re-ask's answer (D-22, F-9) — the screen of the direct read
24+
* (`r:4`) and of a plain input. A pending read yields no value, so it hands
25+
* on no posture (D-25: a node whose flight is up is the hold's work, not a
26+
* verdict reader). A memo that is a verdict reader already keeps its
27+
* posture when it is served the screen of a flight: a prior on-screen
28+
* reader of `mb` sees what it saw before this fix.
29+
*/
30+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
31+
import {
32+
createEffect,
33+
createMemo,
34+
createRenderEffect,
35+
createRoot,
36+
createSignal,
37+
flush,
38+
isPending,
39+
latest,
40+
resetErrorHalt
41+
} from "../src/index.js";
42+
43+
beforeEach(() => vi.useFakeTimers());
44+
afterEach(() => {
45+
vi.useRealTimers();
46+
resetErrorHalt();
47+
});
48+
49+
const sleep = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
50+
const tick = async (ms: number) => {
51+
await vi.advanceTimersByTimeAsync(ms);
52+
flush();
53+
};
54+
55+
type Input = "verdict" | "plain";
56+
type Between = "identity" | "times10" | "chain";
57+
type Made = "before" | "mid-flight";
58+
type Prior = "none" | "render effect" | "user effect";
59+
60+
const between: Record<Between, (m1: () => number) => () => number> = {
61+
identity: m1 => createMemo(() => m1()),
62+
times10: m1 => createMemo(() => m1() * 10),
63+
chain: m1 => {
64+
const inner = createMemo(() => m1() * 10);
65+
return createMemo(() => inner() + 1);
66+
}
67+
};
68+
69+
async function run(input: Input, shape: Between, made: Made, prior: Prior) {
70+
const log: string[] = [];
71+
const [s, setS] = createSignal(1);
72+
const [on, setOn] = createSignal(prior === "render effect");
73+
let m1!: () => number;
74+
let mb!: () => number;
75+
createRoot(() => {
76+
const m0 = createMemo(() => (input === "plain" ? s() * 2 : latest(s) + s()));
77+
m1 = createMemo(async () => {
78+
const v = m0();
79+
await sleep(100);
80+
return v;
81+
});
82+
if (made === "before") mb = between[shape](m1);
83+
});
84+
if (prior === "user effect")
85+
createRoot(() =>
86+
createEffect(
87+
() => mb(),
88+
() => {}
89+
)
90+
);
91+
createRoot(() =>
92+
createRenderEffect(
93+
() => (on() ? `r:${mb()}` : "r:off"),
94+
v => void log.push(v)
95+
)
96+
);
97+
flush();
98+
await tick(150);
99+
setS(2);
100+
flush();
101+
await tick(20);
102+
if (made === "mid-flight") createRoot(() => (mb = between[shape](m1)));
103+
setOn(true);
104+
flush();
105+
log.push("--mounted");
106+
await tick(300);
107+
return log;
108+
}
109+
110+
const screen = (shape: Between, v: number) =>
111+
`r:${shape === "identity" ? v : shape === "times10" ? v * 10 : v * 10 + 1}`;
112+
113+
describe("#4504: a memo over a re-asked async memo, first read by a mount mid-flight", () => {
114+
it("control: the mount reading the async memo directly is held and shows the re-ask's answer", async () => {
115+
const log: string[] = [];
116+
const [s, setS] = createSignal(1);
117+
const [on, setOn] = createSignal(false);
118+
createRoot(() => {
119+
const m0 = createMemo(() => latest(s) + s());
120+
const m1 = createMemo(async () => {
121+
const v = m0();
122+
await sleep(100);
123+
return v;
124+
});
125+
createRenderEffect(
126+
() => (on() ? `r:${m1()}` : "r:off"),
127+
v => void log.push(v)
128+
);
129+
});
130+
flush();
131+
await tick(150);
132+
setS(2);
133+
flush();
134+
await tick(20);
135+
setOn(true);
136+
flush();
137+
log.push("--mounted");
138+
await tick(300);
139+
expect(log).toEqual(["r:off", "--mounted", "r:4"]);
140+
});
141+
142+
for (const input of ["verdict", "plain"] as const)
143+
for (const shape of ["identity", "times10", "chain"] as const)
144+
for (const made of ["before", "mid-flight"] as const)
145+
it(`${input} input, ${shape} memo made ${made === "before" ? "before the re-ask" : "mid-flight"}: the reader is born held and shows the re-ask's answer`, async () => {
146+
expect(await run(input, shape, made, "none")).toEqual([
147+
"r:off",
148+
"--mounted",
149+
screen(shape, 4)
150+
]);
151+
});
152+
153+
// #4474's equivalence: a reader that holds nothing does not change the
154+
// screen (laziness is never observable, D-22).
155+
for (const input of ["verdict", "plain"] as const)
156+
it(`${input} input, a prior user effect reading the memo: the same screen as with no reader`, async () => {
157+
expect(await run(input, "times10", "before", "user effect")).toEqual([
158+
"r:off",
159+
"--mounted",
160+
"r:40"
161+
]);
162+
});
163+
164+
// Unchanged by #4504: the memo already had a value and an on-screen reader
165+
// when the write re-asked the async memo. With the verdict input that
166+
// reader shows the screen of the flight (D-25: the memo is a verdict
167+
// reader by what it reads), the verdict lane's reveal of `latest(s) + s()`
168+
// over the held write (`3`, D-26), then the commit.
169+
it("verdict input, the memo already on screen before the re-ask: unchanged", async () => {
170+
expect(await run("verdict", "times10", "before", "render effect")).toEqual([
171+
"r:20",
172+
"--mounted",
173+
"r:30",
174+
"r:40"
175+
]);
176+
expect(await run("verdict", "identity", "before", "render effect")).toEqual([
177+
"r:2",
178+
"--mounted",
179+
"r:3",
180+
"r:4"
181+
]);
182+
});
183+
it("plain input, the memo already on screen before the re-ask: unchanged", async () => {
184+
expect(await run("plain", "times10", "before", "render effect")).toEqual([
185+
"r:20",
186+
"--mounted",
187+
"r:40"
188+
]);
189+
});
190+
191+
// D-22 / D-23: the memo has produced a value (the async memo's landed
192+
// answer, through it) and is pending on the re-ask, at any depth — read
193+
// unowned after the plain mount, and by a verdict leaf mounted mid-flight.
194+
for (const input of ["verdict", "plain"] as const)
195+
for (const mount of ["plain reader", "verdict leaf"] as const)
196+
it(`${input} input, ${mount} mounted mid-flight: latest/isPending of the memo`, async () => {
197+
const log: string[] = [];
198+
const [s, setS] = createSignal(1);
199+
const [on, setOn] = createSignal(false);
200+
let mb!: () => number;
201+
createRoot(() => {
202+
const m0 = createMemo(() => (input === "plain" ? s() * 2 : latest(s) + s()));
203+
const m1 = createMemo(async () => {
204+
const v = m0();
205+
await sleep(100);
206+
return v;
207+
});
208+
mb = createMemo(() => m1() * 10);
209+
createRenderEffect(
210+
() =>
211+
!on()
212+
? "off"
213+
: mount === "plain reader"
214+
? `r:${mb()}`
215+
: `l:${latest(mb)} p:${isPending(mb)}`,
216+
v => void log.push(v)
217+
);
218+
});
219+
flush();
220+
await tick(150);
221+
setS(2);
222+
flush();
223+
await tick(20);
224+
setOn(true);
225+
flush();
226+
log.push("--mounted");
227+
expect([latest(mb), isPending(mb)]).toEqual([20, true]);
228+
await tick(300);
229+
expect([latest(mb), isPending(mb)]).toEqual([40, false]);
230+
expect(log).toEqual(
231+
mount === "plain reader"
232+
? ["off", "--mounted", "r:40"]
233+
: ["off", "l:20 p:true", "--mounted", "l:40 p:false"]
234+
);
235+
});
236+
});

‎packages/signals/tests/unread-derive-midflight-mount-4491.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,13 @@ describe("readers the hold does not reach (#4491)", () => {
173173
* writes nothing on the derive: it marks the derive's next pass (`fam.w`),
174174
* a read that finds no flight up clears the mark, and the posture stays the
175175
* pass's own reads (core `recompute`). A later flight of `m1`, the reader on
176-
* screen, then runs as it does for a store read from the start, and as the
177-
* memo form: the same screen, the same posture — whether the landing changed
178-
* the leaf (the derive re-ran) or equalled it (it did not).
176+
* screen, then shows what a store read from the start and the memo form
177+
* show — whether the landing changed the leaf (the derive re-ran) or equalled
178+
* it (it did not). After an equal landing the flight wakes the held derive
179+
* pending, and that pass reads the pending `m1` plainly: a read of a pending
180+
* node hands no posture to a pass that is the hold's work (#4504; D-25), as
181+
* a memo between `m1` and the reader posts none. The posture during the
182+
* flight is internal; the screen is the rule (D-30).
179183
*/
180184
describe("the derive's posture after the held mount (#4491)", () => {
181185
async function later(form: "memo" | "storeKey", mountMidFlight: boolean, equal: boolean) {
@@ -230,7 +234,7 @@ describe("the derive's posture after the held mount (#4491)", () => {
230234
for (const equal of [false, true])
231235
test(`a later flight after ${equal ? "an equal" : "a changed"} landing`, async () => {
232236
const held = await later("storeKey", true, equal);
233-
expect(held).toEqual(await later("storeKey", false, equal));
237+
expect(screen(held)).toEqual(screen(await later("storeKey", false, equal)));
234238
expect(screen(held)).toEqual(screen(await later("memo", true, equal)));
235239
expect(held).toContain("--landed verdict=true pending=false");
236240
});

‎packages/web/src/server-mock.ts‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,26 @@ export type PreloadLink = PreloadLinkAttributes &
8787
* (unknown fields pass through untyped), but any bundler integration can
8888
* produce it. Only these fields are ever read: `preloads` is Solid's
8989
* extension slot for explicit typed links the integration selects.
90+
*
91+
* Keys are module ids, except `_`-prefixed metadata strings: `_base` (the
92+
* public base joined with every `file`), plus any an integration stamps,
93+
* such as the vite plugin's `_entry`. The index signature carries both
94+
* (solidjs/solid#4502), so a read by key is an entry only once narrowed,
95+
* e.g. `typeof entry === "object"`.
9096
*/
91-
export type AssetManifest = Record<
92-
string,
93-
{
94-
file: string;
95-
css?: string[];
96-
isEntry?: boolean;
97-
imports?: string[];
98-
preloads?: PreloadLink[];
99-
}
100-
> & { _base?: string };
97+
export type AssetManifest = {
98+
[key: string]:
99+
| {
100+
file: string;
101+
css?: string[];
102+
isEntry?: boolean;
103+
imports?: string[];
104+
preloads?: PreloadLink[];
105+
}
106+
| string
107+
| undefined;
108+
_base?: string;
109+
};
101110

102111
/** Inline style content, e.g. dev CSS collected from a bundler's module graph. */
103112
export type InlineStyleAsset = {
@@ -170,6 +179,13 @@ export function renderToString<T>(
170179
noScripts?: boolean;
171180
plugins?: any[];
172181
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
182+
/**
183+
* Server modulepreload hints for modules outside the entry's static import
184+
* closure (lazy and route chunks) carry `fetchpriority="low"` so they do not
185+
* compete with the modules hydration waits on. `false` emits them at default
186+
* priority.
187+
*/
188+
lowPriorityPreloads?: boolean;
173189
/** This render's server error hook, ahead of `configureServerErrors`' (see the server entry). */
174190
onError?: ServerErrorHook;
175191
/**
@@ -221,6 +237,13 @@ export function renderToStream<T>(
221237
noScripts?: boolean;
222238
plugins?: any[];
223239
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
240+
/**
241+
* Server modulepreload hints for modules outside the entry's static import
242+
* closure (lazy and route chunks) carry `fetchpriority="low"` so they do not
243+
* compete with the modules hydration waits on. `false` emits them at default
244+
* priority.
245+
*/
246+
lowPriorityPreloads?: boolean;
224247
onCompleteShell?: (info: { write: (v: string) => void }) => void;
225248
onCompleteAll?: (info: { write: (v: string) => void }) => void;
226249
/** This render's server error hook, ahead of `configureServerErrors`' (see the server entry). */

0 commit comments

Comments
 (0)