Skip to content

Commit 7837471

Browse files
committed
Merge remote-tracking branch 'origin/next' into fix/f6-boundary-frame-reader
2 parents 896a85e + a52615c commit 7837471

16 files changed

Lines changed: 556 additions & 18 deletions

File tree

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 derived store that returns rows from its own draft no longer recurses forever when its source refreshes: the projection draft wrapper resolves to its store proxy wherever the result carries it, so a retained row keeps its identity and stays readable, and an equivalent refresh doesn't re-notify its readers.

‎packages/signals/src/store/projection.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type { Computed, Signal } from "../core/types.js";
3333
import type { Refreshable } from "../core/index.js";
3434
import { reconcileState } from "./reconcile.js";
3535
import { nameStore, runDirect, storeSetter, wrap } from "./store.js";
36-
import type { StoreFamily, StoreTarget } from "./target.js";
36+
import { setLookup, type StoreFamily, type StoreTarget } from "./target.js";
3737
import {
3838
$TARGET,
3939
markRawIngest,
@@ -116,7 +116,12 @@ function wrapDraft(
116116
Reflect.defineProperty(inner, prop, desc);
117117
})
118118
};
119-
return new Proxy(Array.isArray(inner) ? [] : {}, traps);
119+
const px = new Proxy(Array.isArray(inner) ? [] : {}, traps);
120+
// The wrapper stands for its store proxy wherever the derive's result
121+
// carries it (`wrap`, `unwrapValue`, reconcile's slot matching).
122+
const t: StoreTarget | undefined = inner[$TARGET];
123+
if (t !== undefined) setLookup(px, t);
124+
return px;
120125
}
121126

122127
function cloneState<T extends object>(v: T, shallow: boolean): T {

‎packages/signals/src/store/store.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import {
9696
isOwned,
9797
lookupTarget,
9898
markDescendants,
99+
setLookup,
99100
storeLookup,
100101
storeOwners,
101102
type StoreFamily,
@@ -242,7 +243,7 @@ function createTarget(
242243
t.ovl = false;
243244
t.del = null;
244245
t.px = new Proxy(t, traps);
245-
(fam?.map ?? storeLookup).set(value, t);
246+
setLookup(value, t);
246247
if (__TEST__ && ingestedRaw && !isOwned(value)) ingestedRaw.add(value);
247248
return t;
248249
}
@@ -268,11 +269,14 @@ export function wrap<T extends Record<PropertyKey, any>>(
268269
return createTarget(value, parent, parentKey, fam).px;
269270
}
270271

271-
/** Unwrap our own proxies to their current backing; leave everything else. */
272+
/** Unwrap our own proxies to their current backing; leave everything else.
273+
* A projection draft wrapper is registered as its target's alias
274+
* (projection.ts `wrapDraft`) — adopted as a backing, it would forward to
275+
* itself (#3767). */
272276
export function unwrapValue(v: any): any {
273277
if (v == null || typeof v !== "object") return v;
274278
const t: StoreTarget | undefined = v[$TARGET];
275-
if (t !== undefined && t.px === v && t.v !== undefined) {
279+
if (t !== undefined && (t.px === v || lookupTarget(v, t.fam) === t) && t.v !== undefined) {
276280
// A draft escaping into other storage must be a REAL container that
277281
// becomes this target's committed backing at fold (the shared-raw
278282
// contract) — a prototype overlay is neither.
@@ -833,7 +837,7 @@ export function adoptPB(
833837
target.wk = null; // adoption supersedes staged trap writes
834838
const owner: StoreTarget | undefined = (incoming as any)[$OWNER];
835839
if (owner !== undefined && owner.fam === target.fam) (incoming as any)[$OWNER] = target;
836-
else (target.fam?.map ?? storeLookup).set(incoming, target);
840+
else setLookup(incoming, target);
837841
if (__TEST__ && ingestedRaw && !isOwned(incoming)) ingestedRaw.add(incoming);
838842
if (notify && base !== incoming) notifyFold(target, base, incoming);
839843
}

‎packages/signals/src/store/target.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export const $OWNER: unique symbol = Symbol(__DEV__ ? "STORE_OWNER" : 0);
139139
* map so one raw can wrap once per family (§7b). */
140140
export const storeLookup = new WeakMap<object, StoreTarget>();
141141

142+
export function setLookup(raw: object, t: StoreTarget): void {
143+
(t.fam?.map ?? storeLookup).set(raw, t);
144+
}
145+
142146
export function isOwned(raw: object): boolean {
143147
return (raw as any)[$OWNER] !== undefined;
144148
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* #3767 — a writable derived store whose derive returns one of its own draft
3+
* rows (`draft.filter(...)`) overflowed the stack once its source refreshed.
4+
* The row read through the draft is a draft WRAPPER (a proxy over a fake
5+
* target forwarding to the store proxy, projection.ts `wrapDraft`), not the
6+
* store's own proxy; reconcile took it for a foreign value and adopted it as
7+
* the row's backing, so the row's backing forwarded to the row itself.
8+
*/
9+
import { describe, expect, it } from "vitest";
10+
import {
11+
createRenderEffect,
12+
createRoot,
13+
createSignal,
14+
createStore,
15+
flush
16+
} from "../../src/index.js";
17+
18+
type Row = { id: number; title: string; failed?: boolean };
19+
20+
describe("#3767 a derive retaining its own draft row", () => {
21+
it("keeps the row readable after the source refreshes", () => {
22+
const [source, setSource] = createSignal<Row[]>([{ id: 1, title: "server" }]);
23+
let rows!: Row[];
24+
let setRows!: (fn: (draft: Row[]) => Row[] | void) => void;
25+
const dispose = createRoot(d => {
26+
[rows, setRows] = createStore<Row[]>(
27+
draft => [...source(), ...draft.filter(row => row.failed)],
28+
[]
29+
);
30+
return d;
31+
});
32+
flush();
33+
expect(rows.map(r => r.id)).toEqual([1]);
34+
35+
setRows(draft => {
36+
draft.push({ id: 2, title: "local", failed: true });
37+
});
38+
flush();
39+
expect(rows.map(r => r.id)).toEqual([1, 2]);
40+
const local = rows[1];
41+
42+
setSource([{ id: 1, title: "server" }]);
43+
flush();
44+
expect(rows.map(r => r.id)).toEqual([1, 2]);
45+
expect(Object.keys(rows[1])).toEqual(["id", "title", "failed"]);
46+
expect({ ...rows[1] }).toEqual({ id: 2, title: "local", failed: true });
47+
expect(rows[1]).toBe(local);
48+
49+
setSource([{ id: 1, title: "server 2" }]);
50+
flush();
51+
expect(rows.map(r => r.title)).toEqual(["server 2", "local"]);
52+
expect(rows[1]).toBe(local);
53+
54+
// The retained row is still the store's row: a write through the setter
55+
// lands, and the next derive keeps it.
56+
setRows(draft => {
57+
draft[1].title = "edited";
58+
});
59+
flush();
60+
expect(rows[1].title).toBe("edited");
61+
setSource([{ id: 1, title: "server 3" }]);
62+
flush();
63+
expect(rows.map(r => r.title)).toEqual(["server 3", "edited"]);
64+
expect(rows[1]).toBe(local);
65+
dispose();
66+
});
67+
68+
it("re-renders a reader of the retained row", () => {
69+
const [source, setSource] = createSignal<Row[]>([{ id: 1, title: "server" }]);
70+
let rows!: Row[];
71+
let setRows!: (fn: (draft: Row[]) => Row[] | void) => void;
72+
const seen: string[][] = [];
73+
const dispose = createRoot(d => {
74+
[rows, setRows] = createStore<Row[]>(
75+
draft => [...source(), ...draft.filter(row => row.failed)],
76+
[]
77+
);
78+
createRenderEffect(
79+
() => rows.map(r => r.title),
80+
titles => {
81+
seen.push(titles);
82+
}
83+
);
84+
return d;
85+
});
86+
flush();
87+
setRows(draft => {
88+
draft.push({ id: 2, title: "local", failed: true });
89+
});
90+
flush();
91+
setSource([{ id: 1, title: "server" }]);
92+
flush();
93+
setRows(draft => {
94+
draft[1].title = "edited";
95+
});
96+
flush();
97+
expect(seen).toEqual([["server"], ["server", "local"], ["server", "edited"]]);
98+
dispose();
99+
});
100+
101+
it("retains a nested draft record of an object store", () => {
102+
type State = { server: string; local?: { note: string } };
103+
const [source, setSource] = createSignal("a");
104+
let state!: State;
105+
let setState!: (fn: (draft: State) => State | void) => void;
106+
const dispose = createRoot(d => {
107+
[state, setState] = createStore<State>(draft => ({ server: source(), local: draft.local }), {
108+
server: ""
109+
});
110+
return d;
111+
});
112+
flush();
113+
setState(draft => {
114+
draft.local = { note: "kept" };
115+
});
116+
flush();
117+
const local = state.local;
118+
setSource("b");
119+
flush();
120+
expect(state.server).toBe("b");
121+
expect({ ...state.local }).toEqual({ note: "kept" });
122+
expect(state.local).toBe(local);
123+
setSource("c");
124+
flush();
125+
expect({ ...state.local }).toEqual({ note: "kept" });
126+
dispose();
127+
});
128+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createRoot, createSignal, createStore, flush, snapshot } from "../../src/index.js";
2+
3+
type Row = { id: string; failed?: boolean };
4+
5+
it("retains a draft row after a derived store adopts an equivalent source", () => {
6+
const { rows, setRows, setSource, dispose } = createRoot(dispose => {
7+
const [source, setSource] = createSignal<Row[]>([{ id: "remote" }]);
8+
const [rows, setRows] = createStore<Row[]>(
9+
draft => [...source(), ...draft.filter(row => row.failed)],
10+
[]
11+
);
12+
return { rows, setRows, setSource, dispose };
13+
});
14+
15+
expect(rows.map(row => row.id)).toEqual(["remote"]);
16+
17+
setRows(draft => {
18+
draft.push({ id: "local", failed: true });
19+
});
20+
flush();
21+
expect(rows.map(row => row.id)).toEqual(["remote", "local"]);
22+
const local = rows[1];
23+
24+
setSource([{ id: "remote" }]);
25+
flush();
26+
27+
expect(rows.map(row => row.id)).toEqual(["remote", "local"]);
28+
expect(rows[1]).toBe(local);
29+
expect(Object.keys(rows[1])).toEqual(["id", "failed"]);
30+
expect(rows[1].failed).toBe(true);
31+
expect(snapshot(rows)).toEqual([{ id: "remote" }, { id: "local", failed: true }]);
32+
33+
setRows(draft => {
34+
draft[1].failed = false;
35+
});
36+
flush();
37+
expect(rows[1].failed).toBe(false);
38+
39+
setSource([{ id: "remote" }]);
40+
flush();
41+
expect(rows.map(row => row.id)).toEqual(["remote"]);
42+
43+
dispose();
44+
});

‎scripts/size/README.md‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
Tree-shaken import-cost tracking: `scenarios.js` defines scenario entries
44
(signals floor, +createStore, +isPending/latest, the render+one-signal simple
55
app, a representative CSR app, a hydrating pair — with and without store
6-
primitives — that keeps the store engine pay-for-use under `hydrate()`, the
7-
frames client as a package, two server-component PAGES: base and live, and
8-
two server-entry floors: `getRequestEvent`/`isServer` and `renderToString`)
9-
with hard brotli limits on the eager entry chunk. CI fails when a scenario
10-
exceeds its limit — that means tree-shaking regressed, or a deliberate feature
11-
landed and the limit should be bumped in the same PR with a reason.
6+
primitives — that keeps the store engine pay-for-use under `hydrate()`, three
7+
compiled-template scenarios — a compiled floor and a JSX todo app in CSR and
8+
hydrating form — the frames client as a package, two server-component PAGES:
9+
base and live, and two server-entry floors: `getRequestEvent`/`isServer` and
10+
`renderToString`) with hard brotli limits on the eager entry chunk. CI fails
11+
when a scenario exceeds its limit — that means tree-shaking regressed, or a
12+
deliberate feature landed and the limit should be bumped in the same PR with
13+
a reason.
1214

1315
## Bundler
1416

@@ -32,6 +34,25 @@ switch re-based every cap (Rolldown lands 4–9% lower on the same artifacts;
3234
the table is in the switch PR and each scenario's ledger note in
3335
`scenarios.js`). Ledger deltas must not be read across that line.
3436

37+
## Compiled scenarios
38+
39+
The hand-written `app:` fixtures call the runtime directly and never compile
40+
a template, so the DOM attribute runtime (`spread`, `className`, `style`,
41+
`setAttribute`, `addEvent`, `delegateEvents`) and the hydratable walk
42+
helpers were never on the gate. A scenario with `compile` is JSX under
43+
`fixtures/` — `fixtures/compiled/` holds a one-button floor and a todo app
44+
with an element spread, `merge`/`omit`, a component spread, delegated and
45+
direct events, `class`/`style` objects, a keyed `<For>`, `<Show>`,
46+
`<Loading>` around a `lazy()` child and a store — compiled at measure time
47+
by the **native `@solidjs/compiler` of the checkout being measured**
48+
(`packages/compiler/index.js`, so the compare job measures the base with the
49+
base's compiler) in client DOM mode with the production posture the Vite
50+
plugin uses (`dev: false`, `hydratable` from the scenario), then bundled like
51+
every other scenario. The compiler sees only each file's basename, so the
52+
output — and the numbers — are the same on every host. The compiled app's
53+
own modules report as the `app` package. CI needs nothing beyond what it
54+
already does: the compiler is built before `pnpm build`.
55+
3556
## Frozen floor caps
3657

3758
The three floor scenarios — the signals floor, the simple app, and the

‎scripts/size/attribute.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import { bundle, moduleOf, packageOf, scenarios, toKB } from "./bundle.mjs";
1414
const args = process.argv.slice(2);
1515
const minAt = args.indexOf("--min");
1616
const threshold = minAt >= 0 ? parseInt(args[minAt + 1], 10) : 200;
17-
const filters = args.filter((a, i) => !a.startsWith("--") && i !== minAt + 1);
17+
// Without `--min`, minAt is -1 and `i !== minAt + 1` would drop the first
18+
// positional filter (index 0); only exclude the value argument when the flag
19+
// is present. (The same fix size.mjs carries for `--json`.)
20+
const filters = args.filter((a, i) => !a.startsWith("--") && (minAt < 0 || i !== minAt + 1));
1821

1922
for (const scenario of scenarios) {
2023
if (filters.length && !filters.some(f => scenario.name.includes(f))) continue;

0 commit comments

Comments
 (0)