Skip to content

feat(google-maps): add ScriptGoogleMapsGeoJson component#656

Merged
harlan-zw merged 10 commits intomainfrom
worktree-geojson-655
Mar 19, 2026
Merged

feat(google-maps): add ScriptGoogleMapsGeoJson component#656
harlan-zw merged 10 commits intomainfrom
worktree-geojson-655

Conversation

@harlan-zw
Copy link
Collaborator

🔗 Linked issue

Resolves #655

❓ Type of change

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

📚 Description

Adds a ScriptGoogleMapsGeoJson component that wraps google.maps.Data to load and style GeoJSON data on the map. Accepts src (string URL for loadGeoJson or object for addGeoJson) and style props, emits mouse events (click, contextmenu, etc.) and feature lifecycle events (addfeature, removefeature, setgeometry, setproperty, removeproperty). Includes unit tests, mock infrastructure, and playground integration.

- Add Data layer mock (createMockDataLayer) with GeoJSON methods
- Add DATA_MOUSE_EVENTS and DATA_FEATURE_EVENTS constants
- Add simulateGeoJsonLifecycle helper and geoJson test options
- Add unit tests covering creation, loading, events, cleanup, lifecycle
- Add GeoJson to playground sfcs page
@vercel
Copy link
Contributor

vercel bot commented Mar 19, 2026

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

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment Mar 19, 2026 2:46pm

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new Vue 3 component ScriptGoogleMapsGeoJson.vue implementing a Google Maps Data layer that accepts src (URL or GeoJSON object) and style props, loads GeoJSON via loadGeoJson or addGeoJson, applies reactive style updates, watches src to reload features, emits mouse and feature-lifecycle events, and cleans up listeners and map attachment. Adds a playground toggle and inline GeoJSON example, new test helpers and mocks for Data layers, a Vitest suite validating loading, styling, events, and cleanup, and documentation updates describing the component and API.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature being added: a new component called ScriptGoogleMapsGeoJson for Google Maps.
Description check ✅ Passed The description includes linked issue, type of change (new feature), and a clear overview of the component's functionality, props, and events.
Linked Issues check ✅ Passed The implementation fulfills all requirements from issue #655: component creation, src prop handling for both URLs and objects, style prop support with reactivity, event emission for mouse and feature lifecycle events, and proper cleanup.
Out of Scope Changes check ✅ Passed All changes are within scope: the new component, tests, mocks, documentation, playground example, and an e2e test snapshot update are all directly related to the GeoJSON feature implementation.

✏️ 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 worktree-geojson-655
📝 Coding Plan
  • Generate coding plan for human review comments

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

@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 (2)
src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue (2)

70-73: Style watcher doesn't reset styling when style becomes undefined.

If a consumer removes the style prop (sets it to undefined), the watcher condition style being truthy prevents setStyle from being called. The layer retains its previous styling. If this is intentional, consider documenting it; otherwise, you may want to reset to default styling.

💡 Optional: Reset to default when style is removed
 watch(() => props.style, (style) => {
-  if (dataLayer.value && style)
-    dataLayer.value.setStyle(style)
+  if (dataLayer.value)
+    dataLayer.value.setStyle(style ?? {})
 }, { deep: true })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue` around lines
70 - 73, The watcher on props.style currently only calls
dataLayer.value.setStyle(style) when style is truthy, so when the prop is
removed the layer keeps previous styles; update the watcher (watch(() =>
props.style, ...)) to handle falsy/undefined by calling
dataLayer.value.setStyle(null) (or undefined per the Maps API) to reset to
default styling, e.g. check for dataLayer.value existence and call
setStyle(style) when style is provided and setStyle(null) when style is
undefined/removed; touch the watcher logic and add a short comment documenting
the intended reset behavior.

63-68: Consider adding deep: true to the src watcher for object mutations.

When src is a GeoJSON object, consumers might mutate the object's features array rather than replacing the entire object reference. Without deep: true, such mutations won't trigger a reload.

💡 Suggested change
-watch(() => props.src, (src) => {
+watch(() => props.src, (src) => {
   if (!dataLayer.value)
     return
   dataLayer.value.forEach(feature => dataLayer.value!.remove(feature))
   loadGeoJson(src, dataLayer.value)
-})
+}, { deep: true })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue` around lines
63 - 68, The watcher on props.src should observe deep mutations so in the
watcher defined for props.src (the callback that clears dataLayer.value and
calls loadGeoJson) add the watcher option { deep: true } to ensure modifications
inside a GeoJSON object (e.g., changes to features array) trigger the handler;
update the watcher invocation where dataLayer.value is referenced and
loadGeoJson(src, dataLayer.value) is called to include the deep: true option.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue`:
- Around line 70-73: The watcher on props.style currently only calls
dataLayer.value.setStyle(style) when style is truthy, so when the prop is
removed the layer keeps previous styles; update the watcher (watch(() =>
props.style, ...)) to handle falsy/undefined by calling
dataLayer.value.setStyle(null) (or undefined per the Maps API) to reset to
default styling, e.g. check for dataLayer.value existence and call
setStyle(style) when style is provided and setStyle(null) when style is
undefined/removed; touch the watcher logic and add a short comment documenting
the intended reset behavior.
- Around line 63-68: The watcher on props.src should observe deep mutations so
in the watcher defined for props.src (the callback that clears dataLayer.value
and calls loadGeoJson) add the watcher option { deep: true } to ensure
modifications inside a GeoJSON object (e.g., changes to features array) trigger
the handler; update the watcher invocation where dataLayer.value is referenced
and loadGeoJson(src, dataLayer.value) is called to include the deep: true
option.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1df12fdd-b757-49a2-ac00-26f75c1c4681

📥 Commits

Reviewing files that changed from the base of the PR and between 2fe1be3 and 2585f77.

📒 Files selected for processing (5)
  • playground/pages/third-parties/google-maps/sfcs.vue
  • src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue
  • test/unit/__helpers__/google-maps-test-utils.ts
  • test/unit/__mocks__/google-maps-api.ts
  • test/unit/google-maps-geojson.test.ts

@harlan-zw
Copy link
Collaborator Author

@DamianGlowala please review 🙏

Copy link

@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

🧹 Nitpick comments (1)
docs/content/scripts/google-maps.md (1)

587-589: Good callout, but the surrounding “all components use options” wording is now inaccurate.

The new callout is helpful, but readers can still be misled by the earlier absolute statement that all SFC components use options. Consider changing that sentence to “most” to keep docs internally consistent.

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

In `@docs/content/scripts/google-maps.md` around lines 587 - 589, The docs state
that "all SFC components use options" which conflicts with the new callout about
ScriptGoogleMapsGeoJson; update the earlier absolute sentence to a qualified one
such as "most SFC components use the options pattern" and add a brief
parenthetical noting the exception (ScriptGoogleMapsGeoJson uses src and style
props) so the callout and surrounding text are consistent; search for the
sentence referencing "all SFC components use options" and replace it, keeping
the existing ::callout and the mention of ScriptGoogleMapsGeoJson, src, style,
and options intact.
🤖 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.md`:
- Around line 534-545: The script block is using TypeScript (e.g., the typed
parameter in handleFeatureClick and Google types referenced) but the <script
setup> tag lacks lang="ts"; update the <script setup> tag to <script setup
lang="ts"> so TypeScript is enabled for the geoJsonStyle constant and the
handleFeatureClick(event: google.maps.Data.MouseEvent) function, ensuring proper
type checking and editor support.
- Line 605: The docs line for ScriptGoogleMapsGeoJson incorrectly lists the
style prop as only google.maps.Data.StyleOptions; update that table row (the row
for ScriptGoogleMapsGeoJson) so the style column shows the full union type
google.maps.Data.StylingFunction | google.maps.Data.StyleOptions, preserving the
existing formatting/markdown and backticks used for other types.

---

Nitpick comments:
In `@docs/content/scripts/google-maps.md`:
- Around line 587-589: The docs state that "all SFC components use options"
which conflicts with the new callout about ScriptGoogleMapsGeoJson; update the
earlier absolute sentence to a qualified one such as "most SFC components use
the options pattern" and add a brief parenthetical noting the exception
(ScriptGoogleMapsGeoJson uses src and style props) so the callout and
surrounding text are consistent; search for the sentence referencing "all SFC
components use options" and replace it, keeping the existing ::callout and the
mention of ScriptGoogleMapsGeoJson, src, style, and options intact.
🪄 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: 3d59bdd1-a911-4a7d-bcde-69cb48a90cd7

📥 Commits

Reviewing files that changed from the base of the PR and between 2585f77 and b90d10a.

📒 Files selected for processing (1)
  • docs/content/scripts/google-maps.md

- Add `lang="ts"` to GeoJSON example script tag
- Update style prop type to include StylingFunction union in docs
- Regenerate lockfile for catalog: specifiers
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

Open in StackBlitz

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

commit: 042cb6c

Copy link

@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)
docs/content/scripts/google-maps.md (1)

587-589: Consider softening the “all components use options” wording for consistency.

This callout is helpful, but it now conflicts with the sentence at Line 585 (“All SFC components…”). Consider changing that sentence to “Most SFC components…” so the exception reads cleanly.

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

In `@docs/content/scripts/google-maps.md` around lines 587 - 589, Update the
sentence that currently reads "All SFC components..." so it softens that
absolute claim to "Most SFC components..." (or similar phrasing) so it aligns
with the callout about ScriptGoogleMapsGeoJson using src and style props; locate
the paragraph referencing "All SFC components" and change it to "Most SFC
components" to make the exception for ScriptGoogleMapsGeoJson clear and
consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/content/scripts/google-maps.md`:
- Around line 587-589: Update the sentence that currently reads "All SFC
components..." so it softens that absolute claim to "Most SFC components..." (or
similar phrasing) so it aligns with the callout about ScriptGoogleMapsGeoJson
using src and style props; locate the paragraph referencing "All SFC components"
and change it to "Most SFC components" to make the exception for
ScriptGoogleMapsGeoJson clear and consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b9a6357-1355-4a9f-936c-b8728c1c23e0

📥 Commits

Reviewing files that changed from the base of the PR and between b90d10a and f6c2243.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • docs/content/scripts/google-maps.md

features: [{
type: 'Feature',
geometry: { type: 'Point', coordinates: [150.644, -34.397] },
properties: { name: 'My Point' },
Copy link
Member

Choose a reason for hiding this comment

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

We could (but we don't need to) repeat :style and @click attrs for explicitness.

icon: i-simple-icons-github
to: https://github.com/nuxt/scripts/blob/main/src/runtime/components/ScriptGoogleMaps.vue
size: xs
- label: "<ScriptGoogleMapsGeoJson>"
Copy link
Member

Choose a reason for hiding this comment

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

Not sure where it is used, and, whether this is needed?

Co-authored-by: Damian Głowala <damian.glowala.rebkow@gmail.com>
- Remove GeoJson frontmatter link (not needed)
- "All SFC components" → "Most" with inline exception note
- Reword GeoJson description per reviewer suggestion
- Style watcher resets to default when prop removed
@harlan-zw harlan-zw merged commit fb54985 into main Mar 19, 2026
10 checks passed
@harlan-zw harlan-zw deleted the worktree-geojson-655 branch March 19, 2026 15:15
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.

<ScriptGoogleMapsGeoJson> component

2 participants