fix(FallingText): stop the update loop on cleanup - #1082
Open
noron12234 wants to merge 1 commit into
Open
noron12234 wants to merge 1 commit into
noron12234 wants to merge 1 commit into
Conversation
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.
Changing a running FallingText's gravity recreates its effect, but the old updateLoop continues to schedule requestAnimationFrame callbacks. Unmounting stops Matter's runner and renderer while leaving that separate loop updating the old word elements and cleared engine.
This captures the latest frame ID and cancels it before the existing teardown, across all four JS/TS and CSS/Tailwind variants.
Reproduction in Chrome with a small Vite harness importing the actual component files: wrap requestAnimationFrame/cancelAnimationFrame to count pending callbacks named updateLoop; render FallingText with trigger="auto"; change gravity from 1 to 1.2 to 0.8, allowing effects to run between renders; unmount and observe for another 150 ms. Repeat for each variant, with and without React StrictMode.
Before: pending updateLoop callbacks grow from 1 to 2 to 3, and all three remain after unmount. Each case still executes 21 to 30 callbacks during the subsequent 150 ms observation.
After: pending callbacks stay at 1 across prop changes, become 0 on unmount, and no further updateLoop callback executes.
Validation:
The browser harness is local verification, not a new project test dependency. This is scoped to the component's separate animation loop; it does not change physics timing or other resource ownership. Developed with Codex assistance.