Skip to content

Commit e77087a

Browse files
ryansolidClaude via Cursorcursoragent
authored
fix(refresh): keep the HMR wrapper out of owner paths (#3629)
The solid-js/refresh proxy wraps every component body in a memo so a module swap re-runs it in place. That memo was named `[solid-refresh]App`, so it sat between the component's dev root and the body in every owner path — `<App> › [solid-refresh]App › <Router>` on the Performance panel, in diagnostic findings and in captures. Two nodes are needed (a root for identity, a memo to re-run); two names are not. The memo is now nameless (`""` — an omitted name is labelled "computed"), which `ownerPath` skips. The proxy also reports the component's own name, so a createComponent the compiler did not label opens a `<App>` root rather than `<[solid-refresh]App>`. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 757d1eb commit e77087a

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
The `solid-js/refresh` HMR wrapper no longer appears in owner paths. Its memo is nameless, so a component reads as `<App> › <Router>` in performance-track labels, diagnostic findings and captures rather than `<App> › [solid-refresh]App › <Router>`; the proxy also carries the component's own name, so an unlabelled `createComponent` opens a `<App>` root rather than `<[solid-refresh]App>`.

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ function createProxy<P extends Record<string, any>>(
7979
instances: LiveInstances,
8080
location?: string
8181
): (props: P) => SolidElement {
82-
const refreshName = `[solid-refresh]${name}`;
8382
function HMRComp(props: P): SolidElement {
8483
if (getOwner()) {
8584
instances.count++;
@@ -89,6 +88,14 @@ function createProxy<P extends Record<string, any>>(
8988
}
9089
const s = untrack(source);
9190
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.
9299
return createMemo(
93100
() => {
94101
const c = source();
@@ -97,15 +104,18 @@ function createProxy<P extends Record<string, any>>(
97104
}
98105
return undefined;
99106
},
100-
{ name: refreshName, transparent: true }
107+
{ name: "", transparent: true }
101108
) as unknown as SolidElement;
102109
}
103110
// No $DEVCOMP brand means the source never went through observedComponent, so
104111
// this is a plain function call (e.g. a context provider called directly),
105112
// not a tracked component render.
106113
return s(props);
107114
}
108-
setComponentProperty(HMRComp, "name", refreshName);
115+
// The component's own name, so a `createComponent` call the compiler did
116+
// not label (no `sourceNames`) still opens a `<Name>` root rather than a
117+
// `<[solid-refresh]Name>` one.
118+
setComponentProperty(HMRComp, "name", name);
109119
if (location) {
110120
setComponentProperty(HMRComp, "location", location);
111121
}

‎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: "[solid-refresh]MyComponent", transparent: true }
293+
{ name: "", transparent: true }
294294
);
295295
}
296296
return s(props);

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { afterEach, describe, expect, test, vi } from "vitest";
2-
import { createComponent, createRoot, createSignal, flush } from "../src/index.js";
2+
import {
3+
createComponent,
4+
createMemo,
5+
createRoot,
6+
createSignal,
7+
flush,
8+
getOwner,
9+
ownerPath
10+
} from "../src/index.js";
311
import {
412
$$component,
513
$$decline,
@@ -86,6 +94,38 @@ afterEach(() => {
8694
configureRefresh({ invalidate: undefined });
8795
});
8896

97+
describe("$$component proxy owner paths", () => {
98+
test("the wrapper adds no segment: a body's owner path is the component's root alone", () => {
99+
const { hot } = createViteHot();
100+
let inner: string[] | undefined;
101+
const { proxies } = executeModule(hot, {
102+
Counter: {
103+
impl: () => {
104+
// A node the body owns, located the way a finding or a tracks span
105+
// locates it — through the owners above it.
106+
createMemo(
107+
() => {
108+
inner = ownerPath(getOwner());
109+
return 0;
110+
},
111+
{ name: "total" }
112+
)();
113+
return null;
114+
}
115+
}
116+
});
117+
render(proxies.Counter);
118+
flush();
119+
expect(inner).toEqual(["<Counter>", "total"]);
120+
});
121+
122+
test("the proxy carries the component's name for an unlabelled createComponent", () => {
123+
const { hot } = createViteHot();
124+
const { proxies } = executeModule(hot, { Counter: { impl: () => null } });
125+
expect(proxies.Counter.name).toBe("Counter");
126+
});
127+
});
128+
89129
describe("$$component proxy swapping (vite mode)", () => {
90130
test("unchanged signature keeps the mounted component and its reactive state", () => {
91131
const { hot, fireAccept, invalidate } = createViteHot();

0 commit comments

Comments
 (0)