8000 fix(hmr): avoid hydration for hmr updating by edison1105 · Pull Request #12262 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(hmr): avoid hydration for hmr updating #12262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add test case
  • Loading branch information
edison1105 committed Oct 25, 2024
commit 52b0b731a56028809df3dbc812bc0bf44f7939d6
38 changes: 38 additions & 0 deletions packages/runtime-core/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import * as runtimeTest from '@vue/runtime-test'
import { createApp, registerRuntimeCompiler } from '@vue/runtime-test'
import { baseCompile } from '@vue/compiler-core'
import { createSSRApp } from '@vue/runtime-dom'

declare var __VUE_HMR_RUNTIME__: HMRRuntime
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
Expand Down Expand Up @@ -894,4 +895,41 @@ describe('hot module replacement', () => {
await timeout()
expect(serializeInner(root)).toBe('<div>bar</div>')
})

/**
* @vitest-environment jsdom
*/
test('reload child wrapped in KeepAlive', async () => {
const id = 'child-reload'
const Child: ComponentOptions = {
__hmrId: id,
render: compileToFunction(`<div>foo</div>`),
}
createRecord(id, Child)

const appId = 'test-app-id'
const App: ComponentOptions = {
__hmrId: appId,
components: { Child },
render: compileToFunction(`
<div>
<KeepAlive>
<Child />
</KeepAlive>
</div>
`),
}

const root = document.createElement('div')
root.innerHTML = runtimeTest.renderToString(h(App))
createSSRApp(App).mount(root)
expect(root.innerHTML).toBe('<div><div>foo</div></div>')

reload(id, {
__hmrId: id,
render: compileToFunction(`<div>bar</div>`),
})
await timeout()
expect(root.innerHTML).toBe('<div><div>bar</div></div>')
})
})
0