Repository navigation
fix(trace): Add map.invalidateSize() to fix Leaflet flexbox container issue - #85
Merged
Merged
Conversation
… issue
Root cause: Leaflet requires explicit container dimensions at initialization.
When the map container has 0 height (common with flexbox layouts that
haven't settled), Leaflet creates a broken map.
Changes:
- Add resizeObserverRef to track container size changes
- Call map.invalidateSize({ pan: true }) after map initialization
- Set up ResizeObserver to auto-invalidate on container resize
- Call map.invalidateSize() after fitBounds() to handle marker loading
This is a known Leaflet + React + Flexbox issue that requires invalidateSize()
to be called after layout settles.
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
Fixed the TRACE map regression where the map was completely missing after recent layout changes, while the Event Stream continued to render correctly.
Root Cause
The issue was a classic Leaflet + React + Flexbox bug:
height: 0during initialization (common with flexbox layouts that haven't settled), Leaflet creates a broken/empty mapmap.invalidateSize()calls that are required to recalculate map dimensionsChanges
File:
dashboard/src/components/MapCanvas.tsxresizeObserverRefto track container size changesmap.invalidateSize({ pan: true })after map initialization - Fixes flexbox container issueinvalidateSize()when container resizesmap.invalidateSize()afterfitBounds()to ensure map recalculates after zooming to markersSuccess Criteria Met
Testing
Build verification completed successfully with
npm run build.@tamzrod can click here to continue refining the PR