Skip to content

Commit ddce363

Browse files
committed
perf(solid): keep prod createComponent's owned path one closure (#4565)
The ownerless branch re-enters createComponent inside its new root, so the owned path is a single untrack closure again and the ownerless body still runs through untrack (and its external-source hook), as in dev. Owned path: 1.27 ms per 200k calls vs 2.37 ms with the nested untrack (next: 0.98 ms). Hello world 9,978 B brotli. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent b30027b commit ddce363

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/solid/src/client/component.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ export function createComponent<T extends Record<string, any>>(
100100
return runAsSolidCopy(() => observedComponent(Comp, props || ({} as T), name, loc));
101101
}
102102
if (IS_OBSERVE) return observedComponent(Comp, props || ({} as T), name, loc);
103-
// Ownerless creation gets the root dev and observe always give, so context reads match.
104-
return (getOwner() ? untrack : createRoot)(() => untrack(() => Comp(props || ({} as T))));
103+
// Ownerless creation (module-scope JSX, a timer, after an await) gets the
104+
// root dev and observe always give, so context reads match. The call runs
105+
// again inside that root and takes the owned path, untrack included; the
106+
// owned path stays a single closure, as before. createRoot's dispose lands
107+
// in `name`, which production ignores.
108+
return getOwner()
109+
? untrack(() => Comp(props || ({} as T)))
110+
: createRoot((createComponent<T>).bind(null, Comp, props) as () => SolidElement);
105111
}
106112

107113
/**

0 commit comments

Comments
 (0)