8000 fix(Teleport): hydrate disabled Teleport with undefined target by linzhe141 · Pull Request #11235 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(Teleport): hydrate disabled Teleport with undefined target #11235

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
chore: Merge branch 'main' into fix-hydrate-teleport
  • Loading branch information
linzhe141 committed Sep 20, 2024
commit f070c70dc8e461bc2be828da75feffad2492b020
152 changes: 152 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2060,5 +2060,157 @@ describe('SSR hydration', () => {
`<!--teleport start--><div> Menu is open... </div><!--teleport end-->`,
)
})

test('escape css var name', () => {
const container = document.createElement('div')
container.innerHTML = `<div style="padding: 4px;--foo\\.bar:red;"></div>`
const app = createSSRApp({
setup() {
useCssVars(() => ({
'foo.bar': 'red',
}))
return () => h(Child)
},
})
const Child = {
setup() {
return () => h('div', { style: 'padding: 4px' })
},
}
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
})

describe('data-allow-mismatch', () => {
test('element text content', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="text">foo</div>`,
() => h('div', 'bar'),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="text">bar</div>',
)
expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
})

test('not enough children', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"></div>`,
() => h('div', [h('span', 'foo'), h('span', 'bar')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>',
)
expect(`Hydration children mismatch`).not.toHaveBeenWarned()
})

test('too many children', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>`,
() => h('div', [h('span', 'foo')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><span>foo</span></div>',
)
expect(`Hydration children mismatch`).not.toHaveBeenWarned()
})

test('complete mismatch', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>`,
() => h('div', [h('div', 'foo'), h('p', 'bar')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><div>foo</div><p>bar</p></div>',
)
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})

test('fragment mismatch removal', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--></div>`,
() => h('div', [h('span', 'replaced')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><span>replaced</span></div>',
)
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})

test('fragment not enough children', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><!--[--><div>foo</div><!--]--><div>baz</div></div>`,
() => h('div', [[h('div', 'foo'), h('div', 'bar')], h('div', 'baz')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>',
)
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})

test('fragment too many children', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>`,
() => h('div', [[h('div', 'foo')], h('div', 'baz')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><!--[--><div>foo</div><!--]--><div>baz</div></div>',
)
// fragment ends early and attempts to hydrate the extra <div>bar</div>
// as 2nd fragment child.
expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
// excessive children removal
expect(`Hydration children mismatch`).not.toHaveBeenWarned()
})

test('comment mismatch (element)', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children"><span></span></div>`,
() => h('div', [createCommentVNode('hi')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><!--hi--></div>',
)
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})

test('comment mismatch (text)', () => {
const { container } = mountWithHydration(
`<div data-allow-mismatch="children">foobar</div>`,
() => h('div', [createCommentVNode('hi')]),
)
expect(container.innerHTML).toBe(
'<div data-allow-mismatch="children"><!--hi--></div>',
)
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
})

test('class mismatch', () => {
mountWithHydration(
`<div class="foo bar" data-allow-mismatch="class"></div>`,
() => h('div', { class: 'foo' }),
)
expect(`Hydration class mismatch`).not.toHaveBeenWarned()
})

test('style mismatch', () => {
mountWithHydration(
`<div style="color:red;" data-allow-mismatch="style"></div>`,
() => h('div', { style: { color: 'green' } }),
)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})

test('attr mismatch', () => {
mountWithHydration(`<div data-allow-mismatch="attribute"></div>`, () =>
h('div', { id: 'foo' }),
)
mountWithHydration(
`<div id="bar" data-allow-mismatch="attribute"></div>`,
() => h('div', { id: 'foo' }),
)
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})
})
})
You are viewing a condensed version of this merge commit. You can view the full changes here.
0