Fix infinite loop in LearningMap component caused by unstable useEffect dependencies #19
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.
Problem
Users encountered a "Maximum update depth exceeded" error when
learningmap-datawas present in localStorage, causing the application to crash with an infinite loop:Root Cause
The
useEffecthook inLearningMap.tsx(lines 115-127) includedgetViewportandgetRoadmapStatein its dependency array:While
getViewport(from React Flow'suseReactFlow()hook) andgetRoadmapState(from Zustand store) are stable functions, including them in the dependency array caused React to detect changes and re-trigger the effect under certain conditions. This created an infinite loop:onChangecallbackSolution
Removed the unnecessary function dependencies from the dependency array:
This follows React best practices for stable function references from hooks and stores. Functions from Zustand stores and React Flow hooks don't change between renders and don't need to be tracked as dependencies.
Testing
Changes
packages/learningmap/src/LearningMap.tsx- removed 2 function dependencies from useEffect dependency arrayThis is a minimal, surgical fix that resolves the infinite loop while maintaining all existing functionality.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.