Subscribe on changes!

[SSR Teleport] An error occurred when the disabled attribute has different values in multiple Teleport

avatar
Nov 18th 2022

Vue version

3.2.45

Link to minimal reproduction

https://sfc.vuejs.org/#__DEV____SSR__eNp9kM1uwyAQhF8Fba8x3C1qqX0OLna8bYnMj5bFjRT53bu4jlQ1Uk4ww8wH7A3ectZrRejBljP5zKog1zy4aM2vIVsRjCEvI6MopezsV+XnVwdTujoYrBFjz8kZ44I5EStOEnjZE6qffRmnBVuHqaKUWljieWC8sjXtSpHmXn+Gu3enypzi8L4v1hzygdPE8Xo4gQ/N7sKY9aWkKD+/tYY7DoqDXu1O82Q0TTv4Ys6lN6Z8nNu8LkUn+jSy01Qj+4AaS+gmSt8FScAOTn8YRswVqSOMMxLSM+a/6AO3YTcXN9h+AJ+JmU4=

Steps to reproduce

There is a difference between local and the Vue SFC Playground

local

  1. input
<script setup>
</script>

<template>
  <div id="box"></div>

  <teleport to="#box" :disabled="true">
    <p>text</p>
  </teleport>

  <teleport to="#box">
    <button>Button</button>
  </teleport>
</template>
  1. inject the teleport markup into the correct location in final page HTML

// entry-server.js

const ctx = {}
const html = await renderToString(app, ctx)

console.log(ctx.teleports) // { '#box': '<!--teleport anchor--><button>Button</button><!--teleport anchor-->' }

then modify the content of #box to

<div id="box"><!--teleport anchor--><button>Button</button><!--teleport anchor--></div>
  1. hydration error on the client
<div id="box"><button>Button</button><button>Button</button><!--teleport anchor--></div>

What is expected?

render the content correctly

What is actually happening?

[Vue warn]: Hydration children mismatch in

: server rendered element contains fewer child nodes than client vdom.

the wrong DOM was matched on the client

System Info

No response

Any additional comments?

No response

avatar
Nov 18th 2022

你的意思是给容器添加<!--teleport anchor--><button>Button</button><!--teleport anchor--> 但最终渲染到浏览器少了一个 <!--teleport anchor-->reproduce

avatar
Nov 18th 2022

I think this usage does not conform to the documentation. It is pointed out in the documentation that when rendering a teleport in ssr, its target container should only contain the rendered content of the teleport, that is, the initial container should not contain child nodes image (target as TeleportTargetElement)._lpa || target.firstChild

avatar
Nov 18th 2022

Replace the teleport content when handling during SSR.

avatar
Nov 22nd 2022

duplicate of #6152 ?

I feel that the reasons for the two issues are different