Conversation
removeAllListeners() cleared the map filled by registerWindowListener(), so window-backed events (e.g. Motion accel) never fired again after a later addListener() on web. Only unregister the handles. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Description
WebPlugin.removeAllListeners()unregisters the window listeners and then also clears the map built byregisterWindowListener():Plugins call
registerWindowListener()once, in their constructor (for exampleMotionWebregistersdevicemotion→accelanddeviceorientation→orientation). AfterremoveAllListeners()the map is empty, so a lateraddListener()finds no window listener to attach and the event never fires again on web.removeWindowListener()already setsregistered = falseon each handle, which is whataddListener()checks before attaching it again. This PR keeps the map and only unregisters the handles.Change Type
Rationale / Problems Fixed
On web:
A common pattern is clearing listeners when a page or component unmounts and adding them again when it mounts. On the second mount window-backed events stop arriving, while the same code works on iOS and Android.
Tests or Reproductions
Added
Should re-register window listeners after removeAllListenerstocore/src/tests/web-plugin.spec.ts: register a window listener, add a listener, callremoveAllListeners(), add a new listener, dispatch the window event.getWindowListeners()['test']isundefinedand the new listener is not called.npm testincore: all suites pass.eslintandprettier --checkare clean on the changed files.Screenshots / Media
N/A
Platforms Affected
Notes / Comments
I found this while reading the code with an AI assistant (Claude); I checked the failing test and the fix myself.
🤖 Generated with Claude Code