File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
21
21
h,
22
22
nextTick,
23
23
onMounted,
24
+ onServerPrefetch,
24
25
openBlock,
25
26
reactive,
26
27
ref,
@@ -518,6 +519,45 @@ describe('SSR hydration', () => {
518
519
)
519
520
})
520
521
522
+ test('with data-allow-mismatch component when using onServerPrefetch', async () => {
523
+ const Comp = {
524
+ template: `
525
+ <div>Comp2</div>
526
+ `,
527
+ }
528
+ let foo: any
529
+ const App = {
530
+ setup() {
531
+ const flag = ref(true)
532
+ foo = () => {
533
+ flag.value = false
534
+ }
535
+ onServerPrefetch(() => (flag.value = false))
536
+ return { flag }
537
+ },
538
+ components: {
539
+ Comp,
540
+ },
541
+ template: `
542
+ <span data-allow-mismatch>
543
+ <Comp v-if="flag"></Comp>
544
+ </span>
545
+ `,
546
+ }
547
+ // hydrate
548
+ const container = document.createElement('div')
549
+ container.innerHTML = await renderToString(h(App))
550
+ createSSRApp(App).mount(container)
551
+ expect(container.innerHTML).toBe(
552
+ '<span data-allow-mismatch=""><div>Comp2</div></span>',
553
+ )
554
+ foo()
555
+ await nextTick()
556
+ expect(container.innerHTML).toBe(
557
+ '<span data-allow-mismatch=""><!--v-if--></span>',
558
+ )
559
+ })
560
+
521
561
test('Teleport unmount (full integration)', async () => {
522
562
const Comp1 = {
523
563
template: `
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import {
41
41
import type { TeleportImpl, TeleportVNode } from './components/Teleport'
42
42
import { isAsyncWrapper } from './apiAsyncComponent'
43
43
import { isReactive } from '@vue/reactivity'
44
+ import { updateHOCHostEl } from './componentRenderUtils'
44
45
45
46
export type RootHydrateFunction = (
46
47
vnode: VNode<Node, Element>,
@@ -716,6 +717,11 @@ export function createHydrationFunctions(
716
717
getContainerType(container),
717
718
slotScopeIds,
718
719
)
720
+ // the component vnode's el should be updated when a mismatch occurs.
721
+ if (parentComponent) {
722
+ parentComponent.vnode.el = vnode.el
723
+ updateHOCHostEl(parentComponent, vnode.el)
724
+ }
719
725
return next
720
726
}
721
727
You can’t perform that action at this time.
0 commit comments