Skip to content

fix: correct map centering on station selection in desktop layout#65

Merged
mitoperni merged 1 commit intomainfrom
fix/map-center-desktop-sidebar
Feb 19, 2026
Merged

fix: correct map centering on station selection in desktop layout#65
mitoperni merged 1 commit intomainfrom
fix/map-center-desktop-sidebar

Conversation

@mitoperni
Copy link
Owner

@mitoperni mitoperni commented Feb 19, 2026

Description

Fix intermittent issue where clicking a station in the table didn't center the map on desktop. The map appeared shifted to the right by a fixed amount, while on mobile it worked correctly.

Type of Change

  • Bug fix

Changes Made

  • Add resize() call when sidebar hasMounted changes to true, so Mapbox recalculates the map container dimensions after the sidebar occupies its real space in the desktop layout
  • Add useEffect in StationsMap to flyTo the selected station when mapInstance or selectedStationId changes, as a fallback if the map wasn't ready when flyToStation was called
  • Always call setSelectedStationId in flyToStation before checking if map ref is available
  • Remove unsafe-eval from CSP script-src — no longer required by Mapbox GL JS since they dropped new Function() usage internally

Root Cause

On desktop, <main> starts with absolute inset-0 (full screen) and transitions to relative flex-1 (excluding sidebar) after React hydrates. Mapbox initialized with the full-screen dimensions, so flyTo was centering based on a wider container than the actual visible map area, resulting in the station pin appearing off-center to the left.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • No TypeScript errors
  • Tests added/updated
  • All CI checks pass
  • Tested on different screen sizes
  • Loading states implemented
  • Error handling in place

Related Issues

Closes #


Open with Devin

On desktop the map container starts as absolute inset-0 (full screen)
and transitions to relative flex-1 after React hydrates, causing Mapbox
to initialize with incorrect dimensions and flyTo to center on a wider
container than the actual visible area.

- Call resize() when sidebar hasMounted to recalculate map dimensions
- Add useEffect to flyTo selected station when mapInstance or
  selectedStationId changes as fallback if map wasn't ready
- Always set selectedStationId in flyToStation before checking map ref
- Remove unsafe-eval from CSP script-src (no longer required by Mapbox GL JS)
@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cyclemap Ready Ready Preview, Comment Feb 19, 2026 7:41am

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@mitoperni mitoperni merged commit 92ce9df into main Feb 19, 2026
6 checks passed
@mitoperni mitoperni deleted the fix/map-center-desktop-sidebar branch February 19, 2026 08:46
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.

1 participant