Skip to content

fix(maps): render renderless map components as null - #914

Merged
harlan-zw merged 1 commit into
mainfrom
fix/renderless-hydration
Sep 16, 2026
Merged

harlan-zw merged 1 commit into
mainfrom
fix/renderless-hydration

Conversation

@harlan-zw

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Papercut PC-18. Follow-up to #910, which fixed the same bug in the five MapLibre controls.

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

⚠️ Google Maps mismatches in nuxt dev too

ScriptGoogleMapsPolygon, Polyline, Circle, Rectangle and GeoJson had an empty <template>. An empty template compiles to an empty ssrRender on the server and return null on the client, even in development.

Measured with @nuxt/test-utils in dev: true mode, before this fix:

[Vue warn]: Hydration children mismatch ... Server rendered element contains fewer child nodes than client vdom.
  at <ScriptGoogleMaps ...>
Hydration completed but contains mismatches.

Under nuxt dev, the MapLibre and Leaflet pages logged no hydration message. After this fix, no page logs one.

Production builds: all eight components

ScriptMapLibreGeoJson, ScriptLeafletGeoJson and ScriptLeafletTileLayer had a template with only a comment. A production build strips template comments, so the server renders nothing. The client expects a comment node, and hydration reports a mismatch.

Fix

Each component now has no <template> and uses defineOptions({ render: () => null }). This is the shape #910 proved for the MapLibre controls.

  • The client normalizes null to a comment vnode.
  • With no ssrRender, the server calls render(), normalizes null the same way, and writes <!---->.
  • It does not depend on the compiler comments option.

Test infrastructure finding

@nuxt/test-utils builds inside the Vitest worker with NODE_ENV=test. The Vue compiler then loads its development build and keeps template comments. This repo's e2e tests therefore could never catch a production-only hydration bug.

The new test/e2e/map-hydration.test.ts sets vue.compilerOptions.comments: false. A probe test proves that each page's template comment is stripped from the server HTML. Without the probe, a silent fallback to development behaviour would make the hydration test pass for the wrong reason.

The fixture test/fixtures/map-hydration loads no map SDK, tiles, glyphs or sprites. Hydration compares the server HTML with the client's first render, which happens before any script loads. The Google Maps page uses a placeholder string for api-key. No real key is involved.

✅ Verification

Production-mode hydration test, per library:

Page Before fix After fix One component reverted
/maplibre (GeoJson) fail: Hydration completed but contains mismatches. pass ScriptMapLibreGeoJson: fail
/leaflet (GeoJson, TileLayer) fail: same message pass ScriptLeafletTileLayer: fail
/google-maps (5 components) fail: same message pass ScriptGoogleMapsPolygon: fail

The Google Maps mismatch reproduces without an API key.

  • pnpm lint: 0 errors. pnpm typecheck: exit 0.
  • Full suite: Tests 1206 passed | 22 skipped | 3 todo, Type Errors no errors. Two e2e files failed their fixture builds on CDN fetches (analytics.ahrefs.com, snap.licdn.com). A rerun of those two, with all map e2e files, passed: Test Files 5 passed, Tests 27 passed.

Non-breaking.

Eight map components had a template with only a comment or nothing. The
server rendered no node while the client expected a comment, so hydration
reported a mismatch. The five Google Maps components had empty templates,
which mismatch even in `nuxt dev`.

A `render` returning `null` yields a comment on both sides, the shape the
MapLibre controls adopted in #910. The new e2e fixture builds with
`comments: false`, because the Vitest worker loads Vue's development
compiler, which keeps template comments.
@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
scripts-playground Ready Ready Preview Sep 16, 2026 11:14am UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: e22419b

@github-actions

Copy link
Copy Markdown

📦 Package Size

No notable size changes

📚 22 runtime dependencies (no change)

All tracked output (25)
Package output Gzipped Raw
@nuxt/scripts-cli · runtime dependencies 72 kB 355 kB
@nuxt/scripts-cli · dependency magicast 72 kB 355 kB
@nuxt/scripts-cli · export . 3.4 kB 12 kB
@nuxt/scripts-cli · published payload 3.4 kB 12 kB
@nuxt/scripts · runtime dependencies 436 kB 1.92 MB
@nuxt/scripts · dependency @nuxt/devtools-kit 2.9 kB 7.7 kB
@nuxt/scripts · dependency @oxc-project/types 0 B 0 B
@nuxt/scripts · dependency @vueuse/core 174 kB 707 kB
@nuxt/scripts · dependency @vueuse/shared 39 kB 154 kB
@nuxt/scripts · dependency h3 34 kB 146 kB
@nuxt/scripts · dependency semver 25 kB 72 kB
@nuxt/scripts · dependency sirv 8.8 kB 21 kB
@nuxt/scripts · dependency unstorage 70 kB 225 kB
@nuxt/scripts · dependency valibot 82 kB 590 kB
@nuxt/scripts · dist/runtime 101 kB 298 kB
@nuxt/scripts · export . 26 kB 106 kB
@nuxt/scripts · export ./registry 29 kB 90 kB
@nuxt/scripts · export ./stats 13 kB 91 kB
@nuxt/scripts · export ./types-source 47 kB 239 kB
@nuxt/scripts · published payload 216 kB 824 kB
@nuxt/scripts · components runtime 2.5 kB 6.4 kB
@nuxt/scripts · composables runtime 7.5 kB 24 kB
@nuxt/scripts · registry runtime 45 kB 133 kB
@nuxt/scripts · server runtime 29 kB 87 kB
@nuxt/scripts · utils runtime 2.5 kB 7.4 kB
Runtime dependencies (22)
Package Dependency Requested Resolved Cost
@nuxt/scripts-cli magicast ^0.5.5 0.5.5 📦 72 kB gzip
@nuxt/scripts-cli pathe ^2.0.3 2.0.3 ♻️ free via Nuxt 4.5.2
@nuxt/scripts @nuxt/devtools-kit ^3.4.2 3.4.2 📦 2.9 kB gzip
@nuxt/scripts @oxc-project/types ^0.150.0 0.150.0 📦 0 B gzip
@nuxt/scripts @vueuse/core ^14.4.0 14.4.0 📦 174 kB gzip
@nuxt/scripts @vueuse/shared ^14.4.0 14.4.0 📦 39 kB gzip
@nuxt/scripts consola ^3.4.2 3.4.2 ♻️ free via Nuxt 4.5.2
@nuxt/scripts defu ^6.1.7 6.1.7 ♻️ free via Nuxt 4.5.2
@nuxt/scripts h3 ^1.15.11 1.15.11 📦 34 kB gzip
@nuxt/scripts magic-string ^1.4.1 1.4.1 ♻️ free via Nuxt 4.5.2
@nuxt/scripts ofetch ^1.5.1 1.5.1 ♻️ free via Nuxt 4.5.2
@nuxt/scripts ohash ^2.0.12 2.0.12 ♻️ free via Nuxt 4.5.2
@nuxt/scripts oxc-walker ^1.1.1 1.1.1 ♻️ free via Nuxt 4.5.2
@nuxt/scripts pathe ^2.0.3 2.0.3 ♻️ free via Nuxt 4.5.2
@nuxt/scripts semver ^7.8.5 7.8.5 📦 25 kB gzip
@nuxt/scripts sirv ^3.0.2 3.0.2 📦 8.8 kB gzip
@nuxt/scripts std-env ^4.2.0 4.2.0 ♻️ free via Nuxt 4.5.2
@nuxt/scripts ufo ^1.6.4 1.6.4 ♻️ free via Nuxt 4.5.2
@nuxt/scripts ultrahtml ^1.7.0 1.7.0 ♻️ free via Nuxt 4.5.2
@nuxt/scripts unplugin ^3.3.0 3.3.0 ♻️ free via Nuxt 4.5.2
@nuxt/scripts unstorage ^1.17.5 1.17.5 📦 70 kB gzip
@nuxt/scripts valibot ^1.5.0 1.5.0 📦 82 kB gzip

Baseline: main_@_c9d0bcc5___2026-09-16 · gzip is the comparison metric · changes below 16 B gzip are ignored

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f7561510-5489-44b1-9412-db18654d2a21

📥 Commits

Reviewing files that changed from the base of the PR and between c9d0bcc and e22419b.

📒 Files selected for processing (17)
  • package.json
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsCircle.vue
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsGeoJson.vue
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsPolygon.vue
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsPolyline.vue
  • packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsRectangle.vue
  • packages/script/src/runtime/components/Leaflet/ScriptLeafletGeoJson.vue
  • packages/script/src/runtime/components/Leaflet/ScriptLeafletTileLayer.vue
  • packages/script/src/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue
  • test/e2e/map-hydration.test.ts
  • test/fixtures/map-hydration/app.vue
  • test/fixtures/map-hydration/nuxt.config.ts
  • test/fixtures/map-hydration/package.json
  • test/fixtures/map-hydration/pages/google-maps.vue
  • test/fixtures/map-hydration/pages/leaflet.vue
  • test/fixtures/map-hydration/pages/maplibre.vue
  • test/fixtures/map-hydration/tsconfig.json

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Map layer components for Google Maps, Leaflet, and MapLibre now use defineOptions({ render: () => null }) instead of empty templates. A new map-hydration Nuxt fixture covers the three map implementations. The fixture preparation script prepares this fixture. End-to-end tests verify production HTML and check for hydration or mismatch messages during browser navigation.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e2241

The map hydration changes include fixture coverage across all three map integrations, with no actionable issue identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: renderless map components now render as null to prevent hydration mismatches.
Description check ✅ Passed The description directly explains the hydration mismatch bug, the render-function fix, affected components, production-mode tests, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/renderless-hydration

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.

@harlan-zw harlan-zw added harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. labels Sep 16, 2026
@harlan-zw

harlan-zw commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 MERGED

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy. Last updated: 2026-09-16 12:24 UTC.

GitHub merged this pull request.

No material findings were recorded.

8312c038-94f6-4183-b421-0c82bcc5af36

@harlan-zw harlan-zw added harlan-agent-ready The automated Review passed every gate on this head commit. and removed harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. labels Sep 16, 2026
@harlan-zw
harlan-zw merged commit 4823a09 into main Sep 16, 2026
16 checks passed
@harlan-zw
harlan-zw deleted the fix/renderless-hydration branch September 16, 2026 12:21
@harlan-zw harlan-zw removed the harlan-agent-ready The automated Review passed every gate on this head commit. label Sep 16, 2026
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