Skip to content

fix: guard events.connect against null target - #3871

Open
ErfanBagheri404 wants to merge 1 commit into
pmndrs:masterfrom
ErfanBagheri404:fix/connect-null-guard
Open

fix: guard events.connect against null target#3871
ErfanBagheri404 wants to merge 1 commit into
pmndrs:masterfrom
ErfanBagheri404:fix/connect-null-guard

Conversation

@ErfanBagheri404

Copy link
Copy Markdown

Summary

events.connect(target) does target.addEventListener(...) with no null guard. disconnect already checks if (events.connected), but connect does not.

When a <Canvas> subtree is DOM-reparented via appendChild during a spring animation, r3f calls events.connect(eventSource) with target == null, crashing with:

TypeError: Cannot read properties of null (reading "addEventListener")

This happens 23+ times per fullscreen entry/exit with a common Fullscreenable pattern.

Fix

Add if (!target) return at the top of the connect method in packages/fiber/src/web/events.ts, matching the defensive style already used in disconnect.

Fixes #3754

The connect target is null when the canvas subtree is DOM-reparented
(e.g. during a spring animation via appendChild between containers).
Disconnect already guards via if(events.connected); mirror that for
connect. Fixes pmndrs#3754.
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.

events.connect throws TypeError on null target during DOM-reparenting animations

1 participant