Guard against invalid camera values in map events#1023
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55f9af1fa7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 'report an issue at https://github.com/visgl/react-google-maps/issues/new' | ||
| ); | ||
|
|
||
| return; |
There was a problem hiding this comment.
Preserve valid camera state when bounds are unavailable
When a bounds_changed event fires while getBounds() is still unavailable but getCenter() and getZoom() are valid, this early return leaves cameraStateRef.current stale even though bounds is not stored in the ref. That stale ref is what useMapCameraParams uses to decide whether to call moveCamera, so valid camera changes in this state can be mistaken for unsynced props and trigger redundant camera updates/stutter. Please only abort for invalid fields that are actually written here, or update the stored center/zoom before skipping bounds-dependent work.
Useful? React with 👍 / 👎.
Summary
This prevents invalid camera values returned by the Maps API from being turned into fallback camera state inside the Map component.
In particular, when a
bounds_changedevent reads an invalid camera snapshot such as a non-finite zoom value, the component now:zoom: 0onCameraChangedevent with synthetic fallback bounds/center/zoomThis is a defensive fix for one feedback-loop failure mode discussed in #563. It does not claim to fix every underlying Maps JS API pinch-zoom issue, but it avoids amplifying invalid camera snapshots through React state and controlled camera updates.
Tests
npm test