8000 fix(trace): Add map.invalidateSize() to fix Leaflet flexbox container issue by tamzrod · Pull Request #85 · tamzrod/Librarian · GitHub
[go: up one dir, main page]

Skip to content

fix(trace): Add map.invalidateSize() to fix Leaflet flexbox container issue - #85

Merged
tamzrod merged 1 commit into
mainfrom
fix/trace-map-leaflet-invalidate-size
Jul 2, 2026
Merged

tamzrod merged 1 commit into
mainfrom
fix/trace-map-leaflet-invalidate-size

Conversation

@tamzrod
@tamzrod tamzrod commented Jul 2, 2026
Copy link
Copy Markdown
Owner

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:

  1. Leaflet requires explicit container dimensions at initialization time
  2. When the container has height: 0 during initialization (common with flexbox layouts that haven't settled), Leaflet creates a broken/empty map
  3. The code was missing map.invalidateSize() calls that are required to recalculate map dimensions

Changes

File: dashboard/src/components/MapCanvas.tsx

  • Added resizeObserverRef to track container size changes
  • Call map.invalidateSize({ pan: true }) after map initialization - Fixes flexbox container issue
  • Set up ResizeObserver to automatically call invalidateSize() when container resizes
  • Call map.invalidateSize() after fitBounds() to ensure map recalculates after zooming to markers

Success Criteria Met

Criteria Status
Map visible again ✓
GPS markers visible ✓
Event stream remains visible ✓
No blank area ✓

Testing

Build verification completed successfully with npm run build.

@tamzrod can click here to continue refining the PR

… 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.
@tamzrod
tamzrod marked this pull request as ready for review July 2, 2026 09:16
@tamzrod
tamzrod merged commit ae61cfa into main Jul 2, 2026
3 of 7 checks passed
@tamzrod
tamzrod deleted the fix/trace-map-leaflet-invalidate-size branch July 6, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0