Skip to content

Guard against invalid camera values in map events#1023

Open
tzh476 wants to merge 1 commit into
visgl:mainfrom
tzh476:guard-invalid-camera-events
Open

Guard against invalid camera values in map events#1023
tzh476 wants to merge 1 commit into
visgl:mainfrom
tzh476:guard-invalid-camera-events

Conversation

@tzh476

@tzh476 tzh476 commented Jul 8, 2026

Copy link
Copy Markdown

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_changed event reads an invalid camera snapshot such as a non-finite zoom value, the component now:

  • skips updating the internal tracked camera state instead of overwriting it with fallback values like zoom: 0
  • skips emitting an onCameraChanged event with synthetic fallback bounds/center/zoom
  • keeps the existing warning so unexpected Maps API values remain visible to developers

This 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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