Skip to content

Commit 670ef25

Browse files
committed
fix(solid): the refresh proxy forwards every argument (#4513)
The refresh transform registers PascalCase functions as components, and its proxy called the registered function with `props` only. A plain helper such as `function GlobalTest(...arr)` that is called directly then saw only its first argument in dev, while the production build (no proxy) saw all of them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 2ba10bd commit 670ef25

3 files changed

Lines changed: 22 additions & 3 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+
Hot reload: a PascalCase helper function that the refresh transform wraps now gets every argument when it is called directly, not only the first (#4513).

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ function createProxy<P extends Record<string, any>>(
8888
instances: LiveInstances,
8989
location?: string
9090
): (props: P) => SolidElement {
91-
function HMRComp(props: P): SolidElement {
91+
// Rest arguments are forwarded: the transform also registers PascalCase
92+
// functions that are plain helpers, called directly with any number of
93+
// arguments (#4513).
94+
function HMRComp(props: P, ...rest: unknown[]): SolidElement {
9295
if (getOwner()) {
9396
instances.count++;
9497
onCleanup(() => {
@@ -108,7 +111,10 @@ function createProxy<P extends Record<string, any>>(
108111
() => {
109112
const c = source();
110113
if (c) {
111-
return untrack(() => c(props), (c as any)[$DEVCOMP] && `<${name}>`);
114+
return untrack(
115+
() => (c as (...args: unknown[]) => SolidElement)(props, ...rest),
116+
(c as any)[$DEVCOMP] && `<${name}>`
117+
);
112118
}
113119
return undefined;
114120
},
@@ -118,7 +124,7 @@ function createProxy<P extends Record<string, any>>(
118124
// No $DEVCOMP brand means the source never went through observedComponent, so
119125
// this is a plain function call (e.g. a context provider called directly),
120126
// not a tracked component render.
121-
return s(props);
127+
return (s as (...args: unknown[]) => SolidElement)(props, ...rest);
122128
}
123129
// The component's own name, so a `createComponent` call the compiler did
124130
// not label (no `sourceNames`) still opens a `<Name>` root rather than a

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ describe("$$component proxy owner paths", () => {
174174
const { proxies } = executeModule(hot, { Counter: { impl: () => null } });
175175
expect(proxies.Counter.name).toBe("Counter");
176176
});
177+
178+
test("a PascalCase helper called directly gets every argument (#4513)", () => {
179+
const { hot } = createViteHot();
180+
const { proxies } = executeModule(hot, {
181+
GlobalTest: { impl: ((...arr: number[]) => arr) as any }
182+
});
183+
expect((proxies.GlobalTest as any)(1, 2, 3)).toEqual([1, 2, 3]);
184+
});
177185
});
178186

179187
describe("$$component proxy swapping (vite mode)", () => {

0 commit comments

Comments
 (0)