Repository navigation
fix(hydration): avoid mismatch during hydrate text with newlines in interpolation - #9232
Conversation
Size ReportBundles
Usages
|
skirtles-code
left a comment
There was a problem hiding this comment.
Any reason not to include test cases for the change to hydration.ts?
|
/ecosystem-ci run |
It seems that |
|
📝 Ran ecosystem CI: Open
|
But can't you create a node that has the relevant content directly, rather than relying on jsdom to normalize it? |
Done |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Server rendered text and the client value may legitimately differ because of how the HTML parser handles the markup: - `\r\n` / `\r` are normalized into `\n` (vuejs#9232) - the first newline right after a `<pre>` / `<textarea>` start tag is dropped (vuejs#11873) Both are compensated for in the text children branch of `hydrateElement`, but the branch that hydrates a single text vnode compares the raw values, so the same input is considered equivalent in one place and a mismatch in the other. It is reached whenever the text is not the only child of an element, e.g. `<div>{{ code }}<CopyButton /></div>`, `<span>{{ a }} {{ b }}</span>`, a component whose root is a text node, or a slot returning text. As a consequence `data-allow-mismatch="text"` is ignored for those nodes, and in production (where `logMismatchError` is not dev-only) correct SSR output still logs `Hydration completed but contains mismatches.` Move the normalization into a shared helper used by both branches. The two steps are also applied in the order the parser applies them (normalize line endings first, then drop the leading newline), which fixes `<pre>` text that starts with `\r\n` as well.
close #9229