Skip to content

fix(google-maps): handle marker + mapOptions.styles conflict#719

Merged
harlan-zw merged 4 commits intomainfrom
fix/google-maps-marker-styles
Apr 17, 2026
Merged

fix(google-maps): handle marker + mapOptions.styles conflict#719
harlan-zw merged 4 commits intomainfrom
fix/google-maps-marker-styles

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

@harlan-zw harlan-zw commented Apr 17, 2026

🔗 Linked issue

Resolves #716

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

v1 ScriptGoogleMapsMarker uses AdvancedMarkerElement, which requires a mapId. Google Maps treats JSON styles and mapId as mutually exclusive, so combining mapOptions.styles with a marker silently broke the map ("This Page Can't Load Google Maps Correctly.").

Google's API makes this genuinely unresolvable (styles need the raster renderer, advanced markers need the vector renderer). Rather than pick a side, this PR:

  • Preserves the existing styles-only path in ScriptGoogleMaps (no regression for users with styled maps and no markers).
  • Adds a dev-mode warning in ScriptGoogleMapsMarker when the parent map has no mapId, pointing users to cloud-based map styling.
  • Changes the default mapId fallback from the arbitrary 'map' to Google's pre-registered 'DEMO_MAP_ID', which silences the "initialized without a valid Map ID" warning Google logs for unregistered IDs.
  • Updates the Map Styling guide to frame the conflict as JSON styles vs. markers (a Google constraint), not styles vs. the module.

No runtime behavior change for existing users; only new behavior is a dev-mode warning at the point the conflict actually surfaces.

Closes #716

JSON `mapOptions.styles` previously dropped `mapId`, breaking
`AdvancedMarkerElement` which v1 `ScriptGoogleMapsMarker` requires.
Always pass `mapId` through; add a dev warning when `styles` is set
pointing users to cloud-based styling.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 17, 2026

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

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment Apr 17, 2026 1:58am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@719

commit: 5ae6d9a

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 86cce9ad-88f1-4d81-a35e-9a8c3d07f915

📥 Commits

Reviewing files that changed from the base of the PR and between ca99693 and 5ae6d9a.

📒 Files selected for processing (1)
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue

📝 Walkthrough

Walkthrough

Updated documentation to change JSON styles wording to “Styles apply” and add an amber callout stating JSON styles cannot be used with ScriptGoogleMapsMarker; the callout notes AdvancedMarkerElement requires a mapId and that Google Maps treats styles and mapId as mutually exclusive, recommending cloud-based map IDs when markers are present. In ScriptGoogleMaps.vue the computed options sets mapId to undefined when props.mapOptions?.styles is provided and otherwise uses currentMapId.value || 'DEMO_MAP_ID'. ScriptGoogleMapsMarker.vue now emits a dev-only console.warn if an AdvancedMarkerElement is created while the parent map lacks a mapId.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(google-maps): handle marker + mapOptions.styles conflict' accurately describes the main change: addressing the conflict between markers and JSON styles in Google Maps configuration.
Description check ✅ Passed The description clearly explains the bug (markers need mapId but styles drop it), the approach taken (preserve styles-only path, add dev warning, change default mapId, update docs), and confirms no runtime behavior change for existing users.
Linked Issues check ✅ Passed The PR fully addresses issue #716 by implementing option (b): updating documentation, providing a migration path to cloud-based styling, and adding a dev-mode warning to guide users when the conflict is encountered.
Out of Scope Changes check ✅ Passed All changes (documentation updates, marker warning logic, mapId default fallback, and style/mapId mutual-exclusion handling) are directly scoped to resolving the marker + styles conflict described in issue #716.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/google-maps-marker-styles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/content/scripts/google-maps/1.guides/2.map-styling.md`:
- Line 15: Update the docs sentence that says "Styles apply to the static map
placeholder and to the interactive map when the map has no markers" to reflect
current runtime behavior: because ScriptGoogleMaps.vue always passes a mapId
(fallback 'map') in the options computation (see options computation in
ScriptGoogleMaps.vue around the current lines 225–235), Google Maps ignores JSON
`styles` for the interactive map and JSON styles only affect the static
placeholder in v1; alternatively note that restoring the original behavior would
require adopting the scoped-fallback change in the component's options
computation.

In `@packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue`:
- Around line 225-235: The computed options currently forces mapId via const
mapId = currentMapId.value || 'map', which breaks JSON styles and silently
breaks AdvancedMarkerElement; change this to not default to the literal 'map'
(use const FALLBACK_MAP_ID = 'map' only if you keep it, otherwise remove it) and
instead set mapId = currentMapId.value ?? undefined; then add validation in the
ScriptGoogleMapsMarker (or wherever markers are registered) to throw or log a
clear error if a marker component is mounted but no valid/currentMapId is
provided (fail-fast), or alternatively only apply the fallback when no markers
are present (check a hasMarkers flag/registry before using FALLBACK_MAP_ID);
also update handling around options (the computed options function and its defu
call, and any docs/examples referencing mapOptions.styles) to warn when mapId is
present that styles will be ignored and document the breaking change if markers
are mandatory.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6647212-e708-4754-8fa7-4a9cf2f939b4

📥 Commits

Reviewing files that changed from the base of the PR and between a660032 and 9d15300.

📒 Files selected for processing (2)
  • docs/content/scripts/google-maps/1.guides/2.map-styling.md
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue

Comment thread docs/content/scripts/google-maps/1.guides/2.map-styling.md Outdated
Preserve JSON styles for maps without markers (no regression for
styles-only users). Warn at the marker, where the conflict actually
surfaces, when the parent map has no mapId. Update the styling guide
to state the conflict is between styles and markers.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue (1)

60-62: LGTM — dev warning correctly targets the styles/mapId conflict.

The !map.get('mapId') check on google.maps.Map (an MVCObject) is a valid way to detect the styled-map case, and it aligns with the parent's options computed where mapId is dropped only when mapOptions.styles is set. Gating on import.meta.dev keeps this out of production bundles.

One optional consideration: if a user mounts many <ScriptGoogleMapsMarker> children against the same styled map, this will log once per marker. If that becomes noisy in practice, you could dedupe by tagging the map (e.g. map.set('__nuxtScriptsStylesWarned', true)) after the first warn. Non-blocking.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue`
around lines 60 - 62, The dev-only console warning in ScriptGoogleMapsMarker.vue
currently logs once per marker when a styled map lacks a mapId; to avoid noisy
repeat warnings, modify the logic around the existing import.meta.dev &&
!map.get('mapId') check to first test a custom flag on the map (e.g.
map.get('__nuxtScriptsStylesWarned')) and only call console.warn and then set
that flag (map.set('__nuxtScriptsStylesWarned', true')) on first occurrence;
keep the existing guard and message text intact so behavior and wording remain
unchanged except for deduplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue`:
- Around line 60-62: The dev-only console warning in ScriptGoogleMapsMarker.vue
currently logs once per marker when a styled map lacks a mapId; to avoid noisy
repeat warnings, modify the logic around the existing import.meta.dev &&
!map.get('mapId') check to first test a custom flag on the map (e.g.
map.get('__nuxtScriptsStylesWarned')) and only call console.warn and then set
that flag (map.set('__nuxtScriptsStylesWarned', true')) on first occurrence;
keep the existing guard and message text intact so behavior and wording remain
unchanged except for deduplication.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa373025-7fc0-4a82-9cd4-c1603f9a441c

📥 Commits

Reviewing files that changed from the base of the PR and between 9d15300 and dfba95e.

📒 Files selected for processing (3)
  • docs/content/scripts/google-maps/1.guides/2.map-styling.md
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue
✅ Files skipped from review due to trivial changes (1)
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/content/scripts/google-maps/1.guides/2.map-styling.md

Google's pre-registered dev map ID. An arbitrary string like 'map'
triggers a console warning every load; DEMO_MAP_ID renders silently
and matches Google's documented convention for examples.
@harlan-zw harlan-zw changed the title fix(google-maps): allow marker to work with mapOptions.styles fix(google-maps): handle marker + mapOptions.styles conflict Apr 17, 2026
@harlan-zw harlan-zw merged commit 67af0c1 into main Apr 17, 2026
20 of 21 checks passed
@harlan-zw harlan-zw deleted the fix/google-maps-marker-styles branch April 17, 2026 02:23
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.

ScriptGoogleMapsMarker cannot be used with mapOptions.styles

1 participant