Skip to content

Clear class component refs on unmount in compat - #5225

Open
contactjawad wants to merge 1 commit into
preactjs:mainfrom
contactjawad:fix-class-ref-unmount-null
Open

contactjawad wants to merge 1 commit into
preactjs:mainfrom
contactjawad:fix-class-ref-unmount-null

Conversation

@contactjawad

Copy link
Copy Markdown

An object ref on a class component isn't reset to null when the component unmounts (preact/compat):

const ref = createRef()
// render <Foo ref={ref} />, then unmount Foo
ref.current // still the old Foo instance, expected null

In unmount() the ref is only cleared when r.current is falsy or equals the vnode's DOM node. For a compat class component the ref points at the component instance (vnode._component), so neither case matches and the stale instance is left behind. DOM refs and function refs are already cleared — it's just the instance case slipping through.

I added r.current == vnode._component to that guard. Ran the refs suite too to check nothing regressed. Test added.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant