Skip to content

Commit cc0396b

Browse files
ryansolidClaude via Cursorcursoragent
committed
fix(signals,solid): reserve _parent from property mangling — the second cross-package owner field; retire the wall-clock tripwires
Signals' prod/observe artifacts rename every `_` field but `_name`; the dev artifact the suites run against is unmangled. Two `_parent` reads crossed the package boundary and only worked in dev: solid-js's client hydration walked `owner._parent` to mark the snapshot root (prod marked the current owner instead), and the core's `ownerPath`/`isExcluded` walks over server owners (`ownerPath` shimmed by `located()`, now removed; `OBSERVE.exclude` a silent no-op for a server owner outside dev). `_parent` is reserved alongside `_name`; ~40 B brotli on the prod app scenarios, two caps bumped. Pinned from both ends: solid's cross-package-fields spec checks the reserved fields survive mangling and scans every built client artifact for a signals `_` field not on the list; web's server-owner-walks spec runs `ownerPath` and `OBSERVE.exclude` over server owners against the built observe and development artifacts. Timing tripwires that flaked under parallel CI load: heap-mark re-measures a round over the cap; attribution-navigation asserts against the wait actually taken rather than a timer's nominal 10ms; both shell-gating specs prove ordering by settling gates by hand (shell-gating-harness.ts) instead of wall-clock deltas against timers. RFC 08 gains "Values in records — the PII surface": every record and finding field that carries user data, `data.error` on the server error findings included, for exporters that leave the process. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 59c4192 commit cc0396b

14 files changed

Lines changed: 575 additions & 193 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
`_parent` joins `_name` as a field signals' property mangling reserves — the two cross-package owner fields.
7+
8+
Signals' prod and observe artifacts rename every `_`-prefixed property except a reserved list; the dev artifact (which the test suites run against) is unmangled. Two things read `_parent` across the package boundary and only worked in dev:
9+
10+
- `solid-js`'s client hydration walks `owner._parent` to the root to mark the hydration snapshot scope. In the built prod and observe artifacts the walk found nothing and marked the current owner instead, so computations created outside that owner's subtree during hydration read live values rather than the server snapshot.
11+
- The core's owner walks — `ownerPath` and `OBSERVE.exclude`/`isExcluded` — over `solid-js`'s server owners. `ownerPath` had a server-side shim (`located()`, now removed); `OBSERVE.exclude` was a silent no-op for a server owner outside dev.
12+
13+
Cost: ~40 B brotli on the prod app scenarios; the observe scenarios did not grow. Pinned from both ends: `packages/solid/test/cross-package-fields.spec.ts` checks the reserved fields survive in the mangled artifacts and scans the built client artifacts of `solid-js`, `@solidjs/web` and `@solidjs/universal` for any signals `_` field that is not reserved; `packages/web/test/server/server-owner-walks.spec.tsx` runs `ownerPath` and `OBSERVE.exclude` over server owners against the built observe and development artifacts.
14+
15+
Also: RFC 08 gains "Values in records — the PII surface", the complete list of record and finding fields that carry user data (value previews, interaction target text, navigation paths/params, `data.error` on the server error findings) for exporters that leave the process.

‎documentation/solid-2.0/08-dev-diagnostics.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,8 @@ createRoot(() => {
853853
854854
**Excluding the observer.** `OBSERVE.exclude(owner)` marks an owner subtree as the observer's own: diagnostics whose subject sits under it are built (a throwing site still throws) but never delivered or printed, and the attribution engine records no run for its computations, charges none of them to an interaction, counts no write to its signals or stores toward an interaction, and does not spend a once-per-key slot (`IMMUTABLE_UPDATE_IN_STORE`'s per-path memory) on them. An interaction whose writes all went to excluded subjects, with none of the app's work run — a click on the observer's own panel — is not recorded at all. Mark the root as it is created (a store's nodes take the owner the store was created under, recorded only once the engine is enabled — enable before creating the panel's stores), and make writes from outside the graph under it (`runWithOwner(owner, () => setPanel(…))`) so the writer's context is excluded too. `OBSERVE.isExcluded(subject)` answers the question for any owner or node.
855855
856+
**Values in records — the PII surface.** Records name things (owner paths, `name` options, store paths, route patterns, function ids) and are otherwise numbers, kinds and outcomes; a handful of fields carry _user data_, and an exporter that leaves the process owns scrubbing them (vendors already have the control surface — `beforeSend`, `sendDefaultPii` — and the runtime keeps producing them because they are what makes dev output readable). The complete list: `ChangeRecord.prev`/`value` and `HeldWrite.prev`/`value` — previews of the written values (`preview()`: strings quoted and cut at 40 characters, numbers/booleans verbatim, everything else a type tag such as `Array(12)` or `[Object]`), so the string case is the one to drop or hash unless opted in; `ChangeOrigin.target` (and `InteractionRef.target`) — the element hit, `tag#id "text"` with up to 30 characters of `textContent` for anything that is not an `input`/`textarea`/`select`, so a label but also whatever a `<td>` said; `ChangeOrigin.to`/`from`/`params` and `NavigationEvent.to`/`from`/`params` (`NavigationHop` too) — concrete paths and the values a route pattern bound (`/users/42`, `{ id: "42" }`), while `name` is the pattern; `DiagnosticEvent.message` and `data` for the responsiveness findings (`SILENT_HOLD`, `LONG_HOLD`) — the verdict sentence names the interaction (`click on button#next "Next →"`) and the navigation it was under (concrete `to`/`from`/`params`), and `data.interaction.target` / `data.navigation` carry the same fields structured; no finding quotes a value preview. `data.error` on the server error findings (`SSR_RENDER_ERROR_CONTAINED`, `SSR_ERROR_SANITIZED`, `SERVER_FN_ERROR_SANITIZED`) — the error **as thrown**, message and own properties, deliberately unsanitized: the wire got the generic message so the observer could see the real one, which means a driver's connection string or a query lands here, and an exporter treats it as it treats any captured exception. Dev-only checks may put the offending value on `data` (`PRELOAD_DESCRIPTOR_INVALID`'s `data.value`, `HEAD_TAG_INVALID`'s `data.detail`) — dev tier, never exported. Everything else is safe by construction: `RerunEvent` has names and numbers only; the runtimes' records (`"call"`, `"invocation"`, `"boundary"`, `"frame"`) never put arguments, results, thrown values, requests or responses on the record — those ride the `live` argument beside it, in-process only — and carry ids, methods, addresses, statuses and timings; `ownerPath` is component and primitive names. `stacks: true` adds first-party frames to `ChangeRecord.stack` (file paths, not values) and is a dev affordance to leave off in production.
857+
856858
`costs()` aggregates since `enable()`: `scopes` ranked by self-time with `wastedMs` (time in runs whose value didn't change — the equality cutoff absorbed them), and `writes` ranked by the total downstream re-run time each root write caused. Overlay work (optimistic-lane and held runs — `phase: "optimistic" | "held"`) is accounted separately as `overlayMs` and never blamed as waste.
857859
858860
### Provenance — "who wrote this"

‎packages/signals/rollup.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import prettier from "rollup-plugin-prettier";
2525
// single sequential post-pass (scripts/mangle-props.mjs) with one shared
2626
// nameCache per output; per-chunk terser would mangle the same property to
2727
// different names in different modules and break every cross-module member
28-
// access. `_name` is reserved (the cross-package label field).
28+
// access. `_name` and `_parent` are reserved (the cross-package owner fields).
2929
//
3030
// Two entries per build: `index` (the core) and `attribution` (the engine
3131
// behind `@solidjs/signals/attribution`). The engine reads the core's live

‎packages/signals/scripts/mangle-props.mjs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ for (const dir of process.argv.slice(2)) {
4040
keep_classnames: true,
4141
keep_fnames: true,
4242
module: false,
43-
// `_name` is the one cross-package field: solid-js writes the
44-
// component label onto signals' owners (`owner._name = "<App>"`) and
45-
// `ownerPath` reads it. Mangling it in the observe tree would put the
46-
// write and the read on different properties. Every other `_` field
47-
// is private to this package.
48-
properties: { regex: /^_/, reserved: ["_name"] }
43+
// Two cross-package owner fields, both reserved: `_name` — solid-js
44+
// writes the component label onto signals' owners (`owner._name =
45+
// "<App>"`) and `ownerPath` reads it — and `_parent`, the owner-tree
46+
// link, which solid-js walks on signals' owners (client hydration's
47+
// root lookup) and which the core walks on solid-js's server owners
48+
// (`ownerPath`, `OBSERVE.exclude`/`isExcluded`). Mangling either
49+
// puts the write and the read on different properties: before
50+
// `_parent` was reserved, the prod client marked the wrong snapshot
51+
// scope and `OBSERVE.exclude` was a silent no-op for server owners
52+
// in the observe tier. Every other `_` field is private to this
53+
// package; solid's cross-package-fields spec scans the downstream
54+
// artifacts for any new one.
55+
properties: { regex: /^_/, reserved: ["_name", "_parent"] }
4956
},
5057
// preserve_annotations: terser consumes /*@__PURE__*/ during parse and
5158
// only re-emits it when asked — without this the prod tree loses the

‎packages/signals/tests/attribution-navigation.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ describe("at — a router whose request predates the write it wraps", () => {
686686
// wraps, with the user's request time carried in.
687687
const requested = performance.now();
688688
await wait(10);
689+
// The wait actually taken on the engine's clock (a 10ms timer can fire a
690+
// hair under 10ms of `performance.now()`); settledMs must cover it.
691+
const waited = performance.now() - requested;
689692
OBSERVE!.attribution.withOrigin({ ...NAV, at: requested }, () => app.setLocation("/users/42"));
690693
flush();
691694
const [nav] = attribution.navigations();
@@ -694,7 +697,7 @@ describe("at — a router whose request predates the write it wraps", () => {
694697
app.resolve("b");
695698
await until(() => app.shown.includes("b@/users/42"), "the held page to land");
696699
expect(nav.outcome).toBe("held");
697-
expect(nav.settledMs).toBeGreaterThanOrEqual(10);
700+
expect(nav.settledMs).toBeGreaterThanOrEqual(waited);
698701
expect(nav.hold!.origin).toBe(nav.origin);
699702
});
700703
});

‎packages/signals/tests/heap-mark-incremental.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,23 @@ describe("heap marking stays incremental across mid-tick pulls", () => {
6363
// the rows within one process instead — linear scaling lands near 8×,
6464
// the quadratic regime near 64×. Best-of-k tames JIT/GC noise at the
6565
// small end. Measured locally: ~10× fixed (3 → 30 ms), ~50× on next
66-
// (17 → 850 ms).
66+
// (17 → 850 ms). Under a loaded worker (the suite runs beside two other
67+
// packages' suites) the one large sample can draw a GC pause the small
68+
// ones did not, so a round over the cap is re-measured: the quadratic
69+
// regime is over the cap every round, contention is not.
6770
const best = (N: number, k: number) => {
6871
let ms = Infinity;
6972
for (let i = 0; i < k; i++) ms = Math.min(ms, mount(N));
7073
return ms;
7174
};
7275
best(1000, 2); // warm
73-
const small = best(1000, 3);
74-
const large = best(8000, 2);
75-
expect(large / small).toBeLessThan(24);
76+
let ratio = Infinity;
77+
for (let round = 0; round < 3 && ratio >= 24; round++) {
78+
const small = best(1000, 3);
79+
const large = best(8000, 2);
80+
ratio = Math.min(ratio, large / small);
81+
}
82+
expect(ratio).toBeLessThan(24);
7683
});
7784

7885
it("a write landing between two mid-tick pulls is visible through a memo chain in the same pass", () => {

‎packages/solid/src/server/diagnostics.ts‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export type Finding = Omit<DiagnosticEvent, "sequence">;
2323
* `in <App> › <Page>`, the once-per-code footer). `subject` locates it; the
2424
* current owner by default, which is what the check sites want (they fire
2525
* inside the scope that misbehaved). Server owners are signals-shaped
26-
* enough for the core's `ownerPath` walk (`_parent` + `_name`), so component
27-
* labels (see `createComponent`) come through unchanged. No-op in prod.
26+
* enough for the core's `ownerPath` and exclusion walks (`_parent` +
27+
* `_name`, the two fields signals' property mangling reserves as
28+
* cross-package), so component labels (see `createComponent`) come through
29+
* unchanged in every tier. No-op in prod.
2830
*
2931
* Advisory (`info`) findings are structured-channel only, as in the core:
3032
* a fact worth recording that has not earned the console.
@@ -36,29 +38,10 @@ export function emitFinding(
3638
if (!IS_OBSERVE) return;
3739
// `OBSERVE`/`DEV` are typed optional (undefined in the tiers below theirs);
3840
// the gates above are the same conditions that define them.
39-
const entry = OBSERVE!.diagnostics.emit(located(finding, subject), subject);
41+
const entry = OBSERVE!.diagnostics.emit(finding, subject);
4042
if (IS_DEV && finding.severity !== "info") DEV!.report(entry);
4143
}
4244

43-
/**
44-
* The finding with its `ownerPath` — the labels up this entry's OWN owner
45-
* chain (`createComponentOwner`'s `<Name>`) — filled in here rather than by
46-
* the core's walk: the core reads `_parent` under its own build's property
47-
* mangling (the observe and prod artifacts rename `_`-fields; `_name` alone
48-
* is reserved as the cross-package label), so its walk finds nothing on a
49-
* server owner in the observe artifact. An `ownerPath` already on the
50-
* finding wins, as in the core.
51-
*/
52-
function located(finding: Finding, subject: DiagnosticSubject | null): Finding {
53-
if (finding.ownerPath !== undefined || !subject || !("_parent" in subject)) return finding;
54-
const path: string[] = [];
55-
for (let owner: any = subject; owner; owner = owner._parent) {
56-
const name = owner._name;
57-
if (typeof name === "string" && name.length) path.push(name);
58-
}
59-
return path.length ? { ...finding, ownerPath: path.reverse() } : finding;
60-
}
61-
6245
/**
6346
* The structured record alone, for a site that THROWS its message: the
6447
* thrown error is the console face, and the core lands the once-per-code
@@ -69,7 +52,7 @@ export function recordFinding(
6952
finding: Finding,
7053
subject: DiagnosticSubject | null = getOwner()
7154
): void {
72-
if (IS_OBSERVE) OBSERVE!.diagnostics.emit(located(finding, subject), subject);
55+
if (IS_OBSERVE) OBSERVE!.diagnostics.emit(finding, subject);
7356
}
7457

7558
/**
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* The cross-package `_`-field contract with `@solidjs/signals`.
3+
*
4+
* Signals' prod and observe artifacts mangle every `_`-prefixed property
5+
* (scripts/mangle-props.mjs) except a reserved list; the dev artifact is
6+
* unmangled. Any `_` field a downstream package reads or writes on a
7+
* signals object — an `Owner`, `Computed`, `Signal` — therefore only works
8+
* in every tier if it is on that list. The suite cannot see this: it runs
9+
* against source, where nothing is mangled. Two things went wrong before
10+
* this spec existed — the client's hydration root lookup walked `_parent`
11+
* (mangled → the wrong snapshot scope in prod), and the core's owner walks
12+
* found nothing on a server owner in the observe tier (`OBSERVE.exclude` a
13+
* silent no-op) — so the contract is pinned from both ends here:
14+
*
15+
* - the reserved fields survive in the mangled signals artifacts, and a
16+
* private one does not (so a change to the mangler's regex or list shows);
17+
* - every `_` field the built client artifacts of solid-js and
18+
* @solidjs/web touch is either reserved or not a signals field at all.
19+
*
20+
* Requires a prior `pnpm build`.
21+
*/
22+
import { readdirSync, readFileSync, statSync } from "node:fs";
23+
import { join, resolve } from "node:path";
24+
import { describe, expect, test } from "vitest";
25+
26+
const ROOT = resolve(import.meta.dirname, "../..");
27+
const SIGNALS = join(ROOT, "signals");
28+
29+
/** The mangler's reserved list, read from the script so the two cannot drift. */
30+
function reservedFields(): string[] {
31+
const script = readFileSync(join(SIGNALS, "scripts/mangle-props.mjs"), "utf8");
32+
const match = script.match(/reserved:\s*\[([^\]]*)\]/);
33+
if (!match) throw new Error("mangle-props.mjs: could not find the reserved list");
34+
return [...match[1].matchAll(/"(_\w+)"/g)].map(m => m[1]);
35+
}
36+
37+
/** Every `_` field declared on signals' node types — the ones the mangler renames. */
38+
function signalsFields(): Set<string> {
39+
const types = readFileSync(join(SIGNALS, "src/core/types.ts"), "utf8");
40+
return new Set([...types.matchAll(/^\s+(_\w+)\??:/gm)].map(m => m[1]));
41+
}
42+
43+
function jsFiles(dir: string): string[] {
44+
const out: string[] = [];
45+
for (const entry of readdirSync(dir)) {
46+
const path = join(dir, entry);
47+
if (statSync(path).isDirectory()) {
48+
if (entry !== "types" && entry !== "node_modules") out.push(...jsFiles(path));
49+
} else if (entry.endsWith(".js")) out.push(path);
50+
}
51+
return out;
52+
}
53+
54+
/** `._name` member accesses in `code`, by field, with a short context for the report. */
55+
function fieldAccesses(code: string): Map<string, string> {
56+
const seen = new Map<string, string>();
57+
for (const m of code.matchAll(/\.(_[A-Za-z]\w*)\b/g)) {
58+
if (!seen.has(m[1])) seen.set(m[1], code.slice(Math.max(0, m.index! - 40), m.index! + 40));
59+
}
60+
return seen;
61+
}
62+
63+
describe("cross-package _-fields", () => {
64+
const reserved = reservedFields();
65+
66+
test("the mangler reserves the two owner fields downstream packages walk", () => {
67+
expect(reserved).toEqual(expect.arrayContaining(["_name", "_parent"]));
68+
});
69+
70+
test("the reserved fields survive in the mangled signals artifacts; a private one does not", () => {
71+
for (const tier of ["prod", "observe"]) {
72+
const core = readFileSync(join(SIGNALS, `dist/${tier}/core/core.js`), "utf8");
73+
for (const field of reserved) expect(core, `${tier}: ${field}`).toMatch(`.${field}`);
74+
// `_firstChild` is the owner tree's other link and is private: its
75+
// absence proves the mangler ran on this file at all.
76+
expect(core, `${tier}: _firstChild should be mangled`).not.toMatch("._firstChild");
77+
}
78+
// The dev artifact is the unmangled one the suite runs against (flat and
79+
// code-split: the core sits in the chunk shared with the engine entry).
80+
const dev = readdirSync(join(SIGNALS, "dist"))
81+
.filter(f => /^dev.*\.js$/.test(f))
82+
.map(f => readFileSync(join(SIGNALS, "dist", f), "utf8"))
83+
.join("\n");
84+
expect(dev).toMatch("._firstChild");
85+
});
86+
87+
test("the built client artifacts touch no signals field the mangler renames", () => {
88+
const fields = signalsFields();
89+
expect(fields.has("_parent")).toBe(true); // the parser found the node types
90+
const artifacts = [
91+
...jsFiles(join(ROOT, "solid/dist")),
92+
...jsFiles(join(ROOT, "web/dist")),
93+
...jsFiles(join(ROOT, "web/frames/dist")),
94+
...jsFiles(join(ROOT, "web/server-functions/dist")),
95+
...jsFiles(join(ROOT, "universal/dist"))
96+
].filter(
97+
// Server artifacts work on solid-js's own SSR owners, whose `_` fields
98+
// are solid-js's and unmangled; only the client's objects are signals'.
99+
f => !/[/\\]server[^/\\]*\.js$/.test(f) && !/[/\\]server[/\\]/.test(f)
100+
);
101+
expect(artifacts.length).toBeGreaterThan(5);
102+
const offenders: string[] = [];
103+
for (const file of artifacts) {
104+
for (const [field, context] of fieldAccesses(readFileSync(file, "utf8"))) {
105+
if (fields.has(field) && !reserved.includes(field))
106+
offenders.push(`${file.slice(ROOT.length + 1)}: ${field} — …${context.trim()}…`);
107+
}
108+
}
109+
expect(
110+
offenders,
111+
"a downstream artifact reads a signals `_` field the mangler renames — reserve it in " +
112+
"packages/signals/scripts/mangle-props.mjs or stop reaching into the node"
113+
).toEqual([]);
114+
});
115+
});

0 commit comments

Comments
 (0)