Fix tracked-controls.controller undefined on controllerconnected after reconnect#5804
Open
vincentfretin wants to merge 1 commit intoaframevr:masterfrom
Open
Fix tracked-controls.controller undefined on controllerconnected after reconnect#5804vincentfretin wants to merge 1 commit intoaframevr:masterfrom
vincentfretin wants to merge 1 commit intoaframevr:masterfrom
Conversation
…r reconnect
On controller reconnect, injectTrackedControls calls setAttribute('tracked-controls', ...)
with unchanged data so update/updateController is skipped. tracked-controls' own
controllersupdated listener fires too late because it was registered after the specific
controller component's listener. Explicitly call updateController before emitting
controllerconnected.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
When a controller disconnects and reconnects,
el.components['tracked-controls'].controllerisundefinedat the time thecontrollerconnectedevent fires, producing an error can't access gamepad on undefined on the haptics component at https://github.com/supermedium/superframe/blob/7439b2f77ade516077e8edfc41991ee0fc9d07a9/components/haptics/index.js#L31 so losing the vibrations when you put both controllers on the ground and picking them up again.Root cause: The specific controller component (e.g. meta-touch-controls) registers its
controllersupdatedlistener before tracked-controls' listener (because tracked-controls is created later duringinjectTrackedControls). On reconnect:controllersupdatedhandler fires firstcheckControllerPresentAndSetup→injectTrackedControls→setAttribute('tracked-controls', ...)with unchanged dataupdate()/updateController()because the data hasn't changedcontrollerconnectedis emitted withtracked-controls.controllerstillundefinedcontrollersupdatedlistener fires after, but too lateFix: In
checkControllerPresentAndSetup, explicitly calltrackedControls.updateController()before emittingcontrollerconnected. The check is skipped on first connect (tracked-controls doesn't exist yet) to avoid a redundant call.