Skip to content

Commit 974506c

Browse files
ryansolidClaude via Cursorcursoragent
authored
fix(refresh): make the HMR memo plumbing — no name, no path, no records (#3633)
#3629 gave the solid-js/refresh memo an empty name so it left owner paths, but the attribution engine still recorded it: a `create` record with nodeName "" per component mount (painted `<Counter> › · create`), and a blank-named re-run on every swap. Empty-string residue, not gone. Observe tiers now have a notion of framework plumbing: the internal `_plumbing` memo option sets CONFIG_PLUMBING at creation, the observe `computed()` literal withholds `_name` for it (so `ownerPath` skips it), and the engine's `excludedNode` reads the bit before the observer-exclusion walk — creation, re-runs and checks are recorded for nothing it is, while everything it owns stays observed. The prod literal never carries the bit. Size: observe tier 17,618 -> 17,670 B (+52), engine 31,625 -> 31,664 B (+39); prod scenarios byte-identical. Caps ratcheted with notes. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 5351a3e commit 974506c

10 files changed

Lines changed: 107 additions & 17 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
The `solid-js/refresh` HMR memo is now framework plumbing to the observe tiers: an internal `_plumbing` memo option (`CONFIG_PLUMBING`) leaves it unnamed, out of every owner path, and unrecorded by the attribution engine — no creation or re-run record of its own — while the component body it runs stays fully observed. Replaces the empty-name workaround from #3629, which still produced a blank-named `create` record per component mount.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type InteractionRef,
55
type OriginRef
66
} from "./attribution-hooks.js";
7-
import { CONFIG_DERIVED_OVERRIDE, NOT_PENDING } from "./constants.js";
7+
import { CONFIG_DERIVED_OVERRIDE, CONFIG_PLUMBING, NOT_PENDING } from "./constants.js";
88
import {
99
anyExcluded,
1010
emitDiagnostic,
@@ -547,11 +547,15 @@ interface AttributedNode {
547547
}
548548

549549
/**
550-
* Under an owner the observer marked as its own (`OBSERVE.exclude`): the
551-
* engine records nothing about the node. Cached per node once any exclusion
552-
* exists; before that the answer is a flag read.
550+
* Under an owner the observer marked as its own (`OBSERVE.exclude`), or
551+
* framework plumbing itself (`CONFIG_PLUMBING` — the HMR memo between a
552+
* component's root and its body, which is nobody's node): the engine records
553+
* nothing about the node. Plumbing is a bit read and excludes the node alone,
554+
* not what it owns; the observer exclusion is cached per node once any
555+
* exists, before that a flag read.
553556
*/
554557
function excludedNode(el: Computed<any> | Signal<any>): boolean {
558+
if ((el._config & CONFIG_PLUMBING) !== 0) return true;
555559
if (!anyExcluded()) return false;
556560
const node = el as AttributedNode;
557561
if (node._devExcluded === undefined) node._devExcluded = isExcluded(el);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ export const CONFIG_ADOPTED_UNFLUSHED = 1 << 24;
195195
* (`transitionBlocked`) skip it; the revert drops the override and re-derives
196196
* it (`resolveOptimisticNodes`). Cleared with the override. */
197197
export const CONFIG_DERIVED_OVERRIDE = 1 << 23;
198+
/** Observe tiers only: the node is framework plumbing (the `solid-js/refresh`
199+
* HMR memo between a component's root and its body) — it has no name, is no
200+
* segment of any owner path, and the attribution engine records nothing about
201+
* it (creation, re-runs, checks), while the nodes it owns stay fully observed.
202+
* Set from the internal `_plumbing` option at creation; never set in prod. */
203+
export const CONFIG_PLUMBING = 1 << 25;
198204

199205
export const STATUS_NONE = 0;
200206
export const STATUS_PENDING = 1 << 0;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
CONFIG_HAS_SNAPSHOT,
2525
CONFIG_INPUTS_PUBLISHED,
2626
CONFIG_NO_SNAPSHOT,
27+
CONFIG_PLUMBING,
2728
CONFIG_OPTIMISTIC,
2829
CONFIG_DERIVED_OVERRIDE,
2930
CONFIG_OVERRIDE_SUPERSEDED,
@@ -989,6 +990,9 @@ export function computed<T>(
989990
(!context || options?.lazy ? CONFIG_AUTO_DISPOSE : 0) |
990991
(options?.sync ? CONFIG_SYNC : 0) |
991992
(options?._noSnapshot ? CONFIG_NO_SNAPSHOT : 0) |
993+
// Plumbing is an observe-tier notion (a name and records to
994+
// withhold); the prod literal never carries the bit.
995+
(options?._plumbing ? CONFIG_PLUMBING : 0) |
992996
(snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
993997
_equals: options?.equals ?? isEqual,
994998
_disposal: null,
@@ -1017,7 +1021,9 @@ export function computed<T>(
10171021
_notifiedAt: -1,
10181022
_loading: loading,
10191023
_x: null,
1020-
_name: options?.name ?? "computed"
1024+
// The slot is always present (hidden class); plumbing leaves it
1025+
// unset, which `ownerPath` skips.
1026+
_name: options?._plumbing ? undefined : (options?.name ?? "computed")
10211027
} as Computed<T>)
10221028
: ({
10231029
id: inheritId(options, transparent, context),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface NodeOptions<T> {
3838
* CONFIG_DIRECT_COMMIT / CONFIG_AUTHORITATIVE_READ, keeping the per-flag
3939
* option arms out of the core creation path. */
4040
_extraConfig?: number;
41+
/** Observe tiers: framework plumbing — no name, no owner-path segment, no
42+
* attribution records of its own; its children stay observed (internal —
43+
* not part of public API; see CONFIG_PLUMBING). */
44+
_plumbing?: boolean;
4145
unobserved?: () => void;
4246
lazy?: boolean;
4347
sync?: boolean;

‎packages/signals/src/signals.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ export interface MemoOptions<T> {
263263
* the full semantics. No-op outside hydration.
264264
*/
265265
transparent?: boolean;
266+
/**
267+
* @internal Framework plumbing (the `solid-js/refresh` HMR memo): in the
268+
* observe tiers the memo has no name, is no owner-path segment, and the
269+
* attribution engine records nothing about it, while what it owns stays
270+
* observed. Not part of the public API.
271+
*/
272+
_plumbing?: boolean;
266273
/**
267274
* Custom equality function, or `false` to always notify subscribers.
268275
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.

‎packages/solid/src/refresh/index.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ function createProxy<P extends Record<string, any>>(
8888
}
8989
const s = untrack(source);
9090
if (!s || $DEVCOMP in s) {
91-
// Nameless on purpose (`""` — a memo with no `name` is labelled
92-
// "computed"): the memo sits between the component's dev root
93-
// (`<Name>`, from `observedComponent`) and the body it runs, and the
94-
// observe layer's `ownerPath` skips owners with an empty name — so the
95-
// component reads as `<App> › <Router>` in every owner path (tracks,
96-
// findings, captures) rather than `<App> › [solid-refresh]App ›
97-
// <Router>`. The root above is the component's identity; this node is
98-
// plumbing.
91+
// Plumbing: the memo sits between the component's dev root (`<Name>`,
92+
// from `observedComponent`) and the body it runs, and is nobody's
93+
// node — `_plumbing` leaves it unnamed, out of every owner path, and
94+
// unrecorded by the attribution engine (no creation or re-run of its
95+
// own), while the body's nodes stay observed. The component reads as
96+
// `<App> › <Router>` in tracks, findings and captures; the root above
97+
// is its identity.
9998
return createMemo(
10099
() => {
101100
const c = source();
@@ -104,7 +103,7 @@ function createProxy<P extends Record<string, any>>(
104103
}
105104
return undefined;
106105
},
107-
{ name: "", transparent: true }
106+
{ _plumbing: true, transparent: true }
108107
) as unknown as SolidElement;
109108
}
110109
// No $DEVCOMP brand means the source never went through observedComponent, so

‎packages/solid/test/component.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe("Strict Read Warning", () => {
290290
}
291291
return undefined;
292292
},
293-
{ name: "", transparent: true }
293+
{ _plumbing: true, transparent: true }
294294
);
295295
}
296296
return s(props);

‎packages/solid/test/refresh.spec.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getOwner,
99
ownerPath
1010
} from "../src/index.js";
11+
import { attribution } from "../src/attribution.js";
1112
import {
1213
$$component,
1314
$$decline,
@@ -119,6 +120,52 @@ describe("$$component proxy owner paths", () => {
119120
expect(inner).toEqual(["<Counter>", "total"]);
120121
});
121122

123+
test("the wrapper is nobody's node: the engine records the body's nodes, never the memo", () => {
124+
const { hot, fireAccept } = createViteHot();
125+
const release = attribution.enable({ log: false });
126+
const creates: [string, string][] = [];
127+
const reruns: string[] = [];
128+
const offCreate = attribution.subscribe("create", e => creates.push([e.nodeName, e.nodeKind]));
129+
const offRerun = attribution.subscribe("rerun", e => reruns.push(e.nodeName));
130+
try {
131+
const first = executeModule(hot, {
132+
Counter: {
133+
impl: () => {
134+
createMemo(() => 1, { name: "total" })();
135+
return null;
136+
},
137+
options: { signature: "sig-a" }
138+
}
139+
});
140+
render(first.proxies.Counter);
141+
flush();
142+
expect(creates).toEqual([["total", "memo"]]);
143+
144+
// A swap re-runs the wrapper's memo; that run is not a record either —
145+
// only the new body's nodes are.
146+
executeModule(hot, {
147+
Counter: {
148+
impl: () => {
149+
createMemo(() => 2, { name: "total2" })();
150+
return null;
151+
},
152+
options: { signature: "sig-b" }
153+
}
154+
});
155+
fireAccept({});
156+
flush();
157+
expect(creates).toEqual([
158+
["total", "memo"],
159+
["total2", "memo"]
160+
]);
161+
expect(reruns).toEqual([]);
162+
} finally {
163+
offCreate();
164+
offRerun();
165+
release();
166+
}
167+
});
168+
122169
test("the proxy carries the component's name for an unlabelled createComponent", () => {
123170
const { hot } = createViteHot();
124171
const { proxies } = executeModule(hot, { Counter: { impl: () => null } });

‎scripts/size/.size-limit.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,13 @@ module.exports = [
19441944
// then the reactive graph it reaches through deps and subs, with a Set of the met
19451945
// nodes), the graph record at navigation settle, the per-route size history judged
19461946
// series by series, the option and its merge, and the finding's three leak shapes.
1947-
limit: "17.65 KB",
1947+
// CONFIG_PLUMBING (2026-09-24): 17.65 -> 17.70 KB, measured at 17,670 B
1948+
// against 17,618 on next (+52 B). The observe `computed()` literal reads
1949+
// one more option (`_plumbing`) into a config bit and withholds `_name`
1950+
// for it — the solid-js/refresh HMR memo, so it is no owner-path segment
1951+
// and the engine records nothing about it (`excludedNode` reads the bit).
1952+
// Prod literal untouched; prod scenarios byte-identical.
1953+
limit: "17.70 KB",
19481954
modifyEsbuildConfig: observeEsbuildConfig
19491955
},
19501956
{
@@ -2221,7 +2227,12 @@ module.exports = [
22212227
// latest companions and derived overrides are never judged) is +35 B:
22222228
// 31,625 B, under the same cap (25 B of headroom; the next finding moves
22232229
// it). Tier unchanged at 17,618.
2224-
limit: "31.65 KB",
2230+
// CONFIG_PLUMBING (2026-09-24): 31.65 -> 31.70 KB, measured at 31,664 B
2231+
// against 31,625 on next (+39 B): `excludedNode` reads the bit before the
2232+
// observer-exclusion walk, so the solid-js/refresh HMR memo is recorded
2233+
// nowhere (creation, re-run, checks) while what it owns stays observed.
2234+
// The tier's own +52 B is charged in the scenario above.
2235+
limit: "31.70 KB",
22252236
modifyEsbuildConfig: observeEsbuildConfig
22262237
},
22272238
{

0 commit comments

Comments
 (0)