Fix: Resolve particle flickering issue during window resize #366
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.
Fix: Resolve particle flickering issue during window resize
Problem
Particles flicker rapidly when resizing the window or during slow scroll interactions. This issue occurs when the component is brought into view, and the window is resized, causing unexpected behavior in the particle animation.
Additionally
When the window is resized, the
refresh
parameter has an impact on particle positioning. If the window becomes smaller, particles accumulate outside the visible area. If the window becomes larger, gaps or missing particles are visible, which disrupts the intended effect.Solution:
Condition in
useEffect
:refresh
value is truthy before triggering the particle refresh. Ifrefresh
is truthy, resizing the window causes the particles to refresh. By passingfalse
to therefresh
parameter, we avoid this behavior.Performance Improvements:
useCallback
anduseMemo
to optimize performance slightly (approximately a 0.00065ms improvement). These hooks prevent unnecessary re-renders during window resizing and scrolling.Code Refactoring:
initCanva
) and moved it inside theuseEffect
hook to comply with the DRY.Testing:
Fixes #339.