fix(solid): guard devComponent against undefined owner - #3005
Open
elcoosp wants to merge 1 commit into
Open
Conversation
devComponent unconditionally dereferenced getOwner() and assigned owner._component, throwing "Cannot read properties of undefined" when a component is rendered inside a root with no enclosing owner (e.g. a nested transparent root created by a router or manually nested createRoot). This hard-crashed the entire reactive system (REACTIVITY_HALTED) in dev builds. The _component metadata is dev-only decoration; skip it gracefully when owner is undefined. Production builds are unaffected. Fixes a dev-mode crash when nesting roots (legal in Solid). Signed-off-by: elcoosp <elcoosp@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
devComponent(inpackages/solid/src/client/core.ts) unconditionally dereferencedgetOwner()and assignedowner._component, throwing "Cannot read properties of undefined (reading '[something]')" — surfacing asREACTIVITY_HALTED— whenever a component is rendered inside a root that has no enclosing owner.This happens with a legally nested root: e.g. a component rendered inside a router's
Provider/transparent root that is itself created within another owner. In dev builds this hard-crashes the entire reactive system. Production builds never hit this path.Fix
The
_componentmetadata is dev-only decoration. Guard it withif (owner)so it is skipped gracefully when there is no enclosing owner.Reproduction
Render any component through a nested transparent root (
createRoot(() => createRoot(() => <Comp/>, {transparent:true}), {transparent:true}), or a routerProvidernested inside another root) in a dev build →devComponentthrows. With the guard, it renders fine.Scope
devComponentis dev instrumentation).This was found while running vitest browser-mode tests against a Solid 2.0 app where a router
Provideris nested inside a testrender()root.