fix: correct map centering on station selection in desktop layout#65
Merged
fix: correct map centering on station selection in desktop layout#65
Conversation
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)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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
Changes Made
resize()call when sidebarhasMountedchanges totrue, so Mapbox recalculates the map container dimensions after the sidebar occupies its real space in the desktop layoutuseEffectinStationsMaptoflyTothe selected station whenmapInstanceorselectedStationIdchanges, as a fallback if the map wasn't ready whenflyToStationwas calledsetSelectedStationIdinflyToStationbefore checking if map ref is availableunsafe-evalfrom CSPscript-src— no longer required by Mapbox GL JS since they droppednew Function()usage internallyRoot Cause
On desktop,
<main>starts withabsolute inset-0(full screen) and transitions torelative flex-1(excluding sidebar) after React hydrates. Mapbox initialized with the full-screen dimensions, soflyTowas centering based on a wider container than the actual visible map area, resulting in the station pin appearing off-center to the left.Checklist
Related Issues
Closes #