fix(hydration): avoid component double mount during hydration#14690
Merged
edison1105 merged 2 commits intominorfrom Apr 7, 2026
Merged
fix(hydration): avoid component double mount during hydration#14690edison1105 merged 2 commits intominorfrom
edison1105 merged 2 commits intominorfrom
Conversation
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/hydration.spec.ts (1)
4688-4747: Avoid fixedsetTimeout(10)synchronization in this hydration test.This test can become timing-sensitive on slower CI runners. Prefer a deterministic async gate so the assertion does not depend on wall-clock timing.
Proposed deterministic test sync
- const beforeMount = vi.fn() - const data = ref({ beforeMount }) + const beforeMount = vi.fn() + let resolveAsyncSetup!: () => void + const serverData = ref({ + beforeMount, + ready: Promise.resolve(), + }) + const clientData = ref({ + beforeMount, + ready: new Promise<void>(r => { + resolveAsyncSetup = r + }), + }) const vaporChildCode = ` <script vapor> import { onBeforeMount } from 'vue' const data = _data onBeforeMount(() => data.value.beforeMount()) - await new Promise(r => setTimeout(r, 10)) + await data.value.ready </script> <template><h1>Async component</h1></template> ` @@ serverComponents.VaporChild = compile( vaporChildCode, - data, + serverData, serverComponents, { vapor: true, ssr: true, }, ) clientComponents.VaporChild = compile( vaporChildCode, - data, + clientData, clientComponents, { vapor: true, ssr: false, }, ) @@ - const serverApp = compile(appCode, data, serverComponents, { + const serverApp = compile(appCode, serverData, serverComponents, { vapor: false, ssr: true, }) @@ - const clientApp = compile(appCode, data, clientComponents, { + const clientApp = compile(appCode, clientData, clientComponents, { vapor: false, ssr: false, }) @@ app.mount(container) - await new Promise(r => setTimeout(r, 10)) + resolveAsyncSetup() + await Promise.resolve() await nextTick()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-vapor/__tests__/hydration.spec.ts` around lines 4688 - 4747, The test uses two fixed setTimeout(10) waits (one inside vaporChildCode and one after app.mount) which is flaky; replace them with a deterministic async gate: change the component code (vaporChildCode) to await a Promise you control (e.g. a Deferred exposed via test-supplied data or a global like window.__vaporChildGate), and in the test create/resolve that Deferred instead of sleeping; then swap both await new Promise(r => setTimeout(r, 10)) usages to await that gate (and keep the final await nextTick() for microtask flush). Update places referencing vaporChildCode, appCode, app.mount and runtimeVapor.vaporInteropPlugin to use the new gate so the test waits deterministically.
🤖 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/runtime-vapor/__tests__/hydration.spec.ts`:
- Around line 4688-4747: The test uses two fixed setTimeout(10) waits (one
inside vaporChildCode and one after app.mount) which is flaky; replace them with
a deterministic async gate: change the component code (vaporChildCode) to await
a Promise you control (e.g. a Deferred exposed via test-supplied data or a
global like window.__vaporChildGate), and in the test create/resolve that
Deferred instead of sleeping; then swap both await new Promise(r =>
setTimeout(r, 10)) usages to await that gate (and keep the final await
nextTick() for microtask flush). Update places referencing vaporChildCode,
appCode, app.mount and runtimeVapor.vaporInteropPlugin to use the new gate so
the test waits deterministically.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 522792bb-114b-4665-b0c2-c86e456e6495
📒 Files selected for processing (3)
packages/runtime-vapor/__tests__/hydration.spec.tspackages/runtime-vapor/src/component.tspackages/runtime-vapor/src/vdomInterop.ts
9c91951 to
ffd5d16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by CodeRabbit
Bug Fixes
beforeMountexecute exactly once during component hydration and interop operations.Tests