fix: resolve state management issues and memory leaks#152
Open
hobostay wants to merge 1 commit intopascalorg:mainfrom
Open
fix: resolve state management issues and memory leaks#152hobostay wants to merge 1 commit intopascalorg:mainfrom
hobostay wants to merge 1 commit intopascalorg:mainfrom
Conversation
This commit fixes several issues in the core state management:
1. Fix deleteNodesAction recursive call issue
- Previously, the function recursively called get().deleteNodes()
inside the set() callback, which could cause state inconsistencies.
- Now collects all descendant IDs first in a separate pass, then
deletes them all in a single batch operation.
2. Fix memory leak in use-scene temporal tracking
- Module-level variables (prevPastLength, prevFutureLength,
prevNodesSnapshot) persisted across store re-creations.
- Now cleared in unloadScene() to release stale node references.
- Added clearTemporalTracking() helper function.
3. Remove unused variable in wall-system
- Removed debug variable 'useFrameNb' that was declared but never used.
4. Fix requestAnimationFrame in updateNodesAction
- Previously used RAF without cleanup, causing multiple queued
callbacks when updates happened rapidly.
- Now uses a single tracked RAF with cancellation support.
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.
Summary
This PR fixes several issues in the core state management that could cause bugs and memory leaks:
1. Fix deleteNodesAction recursive call issue
Problem: In
packages/core/src/store/actions/node-actions.ts, thedeleteNodesActionrecursively calledget().deleteNodes()inside theset()callback. This could cause state inconsistencies because the recursive call would try to modify state that's already being modified.Fix: Now collects all descendant IDs first in a separate pass using a helper function
collectDescendants(), then deletes them all in a single batch operation.2. Fix memory leak in use-scene temporal tracking
Problem: In
packages/core/src/store/use-scene.ts, the module-level variablesprevPastLength,prevFutureLength, andprevNodesSnapshotpersisted across store re-creations and scene unloads. This could cause memory leaks by holding references to deleted nodes.Fix:
unloadScene()to release stale node referencesclearTemporalTracking()helper function for clarityclearSceneHistory()now calls this helper3. Remove unused variable in wall-system
Problem: In
packages/core/src/systems/wall/wall-system.tsx, the variableuseFrameNbwas declared and incremented but never used. This appeared to be debug code that was left in.Fix: Removed the unused variable declaration and increment.
4. Fix requestAnimationFrame in updateNodesAction
Problem: In
packages/core/src/store/actions/node-actions.ts,updateNodesActionusedrequestAnimationFramewithout any cleanup mechanism. If updates happened rapidly, multiple RAF callbacks could be queued, causing unnecessary re-renders and potential performance issues.Fix:
pendingRafId) and pending updates (pendingUpdates)Test plan
Checklist
🤖 Generated with Claude Code