Skip to content

fix(runtime-core): avoid repeated hydration mismatch checks#14857

Open
edison1105 wants to merge 1 commit into
mainfrom
edison/fix-hydration-mismatch-log
Open

fix(runtime-core): avoid repeated hydration mismatch checks#14857
edison1105 wants to merge 1 commit into
mainfrom
edison/fix-hydration-mismatch-log

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented May 19, 2026

close #14855

Summary by CodeRabbit

  • Bug Fixes

    • Fixed duplicate warning messages during SSR hydration mismatches. Diagnostics are now emitted only once per mismatch event, reducing console noise and improving debugging clarity.
  • Tests

    • Added test coverage for hydration mismatch warning behavior to verify warnings are emitted exactly once during hydration operations with excess or missing DOM nodes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 23e0cb5a-9ca4-484e-83f6-b13503d7ba91

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce598e and b50e0b2.

📒 Files selected for processing (2)
  • packages/runtime-core/__tests__/hydration.spec.ts
  • packages/runtime-core/src/hydration.ts

📝 Walkthrough

Walkthrough

This PR refactors hydration mismatch handling to emit warnings and diagnostic logs only once per mismatch event, eliminating redundant isMismatchAllowed() and logMismatchError() calls during node removal and mounting loops. Test coverage validates both the excess-node and missing-node warning paths.

Changes

Hydration mismatch warning deduplication

Layer / File(s) Summary
Excess DOM nodes mismatch handling
packages/runtime-core/src/hydration.ts, packages/runtime-core/__tests__/hydration.spec.ts
After hydrateChildren() returns, the "more child nodes" warning and logMismatchError() call move outside the node-removal loop, executing once if mismatches aren't allowed. Test spies on Element.prototype.hasAttribute to verify the warning fires exactly once and the data-allow-mismatch check occurs once.
Missing child nodes mismatch handling
packages/runtime-core/src/hydration.ts, packages/runtime-core/__tests__/hydration.spec.ts
When server children run out, hasWarned is replaced with hasCheckedMismatch to gate the "fewer child nodes" warning and logMismatchError() call on the first encounter only. Test spies on Element.prototype.hasAttribute to verify the warning fires exactly once and the data-allow-mismatch check occurs once.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

scope:hydration, :hammer: p3-minor-bug

Suggested reviewers

  • Doctor-wu
  • LittleSound
  • KazariEX

Poem

🐰 A curious bunny hops through hydration's flow,
Where warnings once whispered with each DOM node below—
Now one chirp per mismatch, no redundant refrain,
The tests guard this promise with spy-powered chain!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: avoiding repeated hydration mismatch checks during SSR hydration, which directly addresses the linked issue.
Linked Issues check ✅ Passed The PR successfully addresses issue #14855 by hoisting mismatch checks outside loops so isMismatchAllowed() and logMismatchError() are called once per mismatch event rather than on every iteration.
Out of Scope Changes check ✅ Passed All changes are focused on resolving the redundant mismatch checks in hydration.ts and adding tests to verify the fix, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ 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 edison/fix-hydration-mismatch-log

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

@edison1105 edison1105 added 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope:hydration ready to merge The PR is ready to be merged. labels May 19, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14857
npm i https://pkg.pr.new/@vue/compiler-core@14857
yarn add https://pkg.pr.new/@vue/compiler-core@14857.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14857
npm i https://pkg.pr.new/@vue/compiler-dom@14857
yarn add https://pkg.pr.new/@vue/compiler-dom@14857.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14857
npm i https://pkg.pr.new/@vue/compiler-sfc@14857
yarn add https://pkg.pr.new/@vue/compiler-sfc@14857.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14857
npm i https://pkg.pr.new/@vue/compiler-ssr@14857
yarn add https://pkg.pr.new/@vue/compiler-ssr@14857.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14857
npm i https://pkg.pr.new/@vue/reactivity@14857
yarn add https://pkg.pr.new/@vue/reactivity@14857.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14857
npm i https://pkg.pr.new/@vue/runtime-core@14857
yarn add https://pkg.pr.new/@vue/runtime-core@14857.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14857
npm i https://pkg.pr.new/@vue/runtime-dom@14857
yarn add https://pkg.pr.new/@vue/runtime-dom@14857.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14857
npm i https://pkg.pr.new/@vue/server-renderer@14857
yarn add https://pkg.pr.new/@vue/server-renderer@14857.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14857
npm i https://pkg.pr.new/@vue/shared@14857
yarn add https://pkg.pr.new/@vue/shared@14857.tgz

vue

pnpm add https://pkg.pr.new/vue@14857
npm i https://pkg.pr.new/vue@14857
yarn add https://pkg.pr.new/vue@14857.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14857
npm i https://pkg.pr.new/@vue/compat@14857
yarn add https://pkg.pr.new/@vue/compat@14857.tgz

commit: b50e0b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready to merge The PR is ready to be merged. scope:hydration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logMismatchError() called redundantly in loop when SSR has excess child nodes

1 participant