Skip to content

fix(hydration): skip lazy hydration for patched components #13283

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 16, 2025
Merged
Show file tree
Hide file tree
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 e2e test
  • Loading branch information
edison1105 committed May 6, 2025
commit 1e876f7c949ae6912b68edaebd1fcc1e719f5cfb
10 changes: 8 additions & 2 deletions packages/vue/__tests__/e2e/hydration-strat-media.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
} = Vue

const Comp = {
setup() {
props: {
value: Boolean
},
setup(props) {
const count = ref(0)
onMounted(() => {
console.log('hydrated')
window.isHydrated = true
})
return () => {
props.value
return h('button', { onClick: () => count.value++ }, count.value)
}
},
Expand All @@ -37,7 +41,9 @@
onMounted(() => {
window.isRootMounted = true
})
return () => h(AsyncComp)

const show = (window.show = ref(true))
return () => h(AsyncComp,{ value: show.value })
},
}).mount('#app')
</script>
30 changes: 30 additions & 0 deletions packages/vue/__tests__/e2e/hydrationStrategies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ describe('async component hydration strategies', () => {
await assertHydrationSuccess()
})

// #13255
test('media query (patched before hydration)', async () => {
const spy = vi.fn()
const currentPage = page()
currentPage.on('pageerror', spy)

const warn: any[] = []
currentPage.on('console', e => warn.push(e.text()))

await goToCase('media')
await page().waitForFunction(() => window.isRootMounted)
expect(await page().evaluate(() => window.isHydrated)).toBe(false)

// patch
await page().evaluate(() => (window.show.value = false))
await click('button')
expect(await text('button')).toBe('1')

// resize
await page().setViewport({ width: 400, height: 600 })
await page().waitForFunction(() => window.isHydrated)
await assertHydrationSuccess('2')

expect(spy).toBeCalledTimes(0)
currentPage.off('pageerror', spy)
expect(
warn.some(w => w.includes('Skipping lazy hydration for component')),
).toBe(true)
})

test('interaction', async () => {
await goToCase('interaction')
await page().waitForFunction(() => window.isRootMounted)
Expand Down
Loading