expect(`Hydration children mismatch in <div>`).not.toHaveBeenWarned()
})
+ test('text w/ newlines', async () => {
+ mountWithHydration('<div>1\n2\n3</div>', () => h('div', '1\r\n2\r3'))
+ expect(`Hydration text mismatch`).not.toHaveBeenWarned()
+ })
+
test('comment', () => {
const { vnode, container } = mountWithHydration('<!---->', () => null)
expect(vnode.el).toBe(container.firstChild)
) {
clientText = clientText.slice(1)
}
- if (el.textContent !== clientText) {
+ const { textContent } = el
+ if (
+ textContent !== clientText &&
+ // innerHTML normalize \r\n or \r into a single \n in the DOM
+ textContent !== clientText.replace(/\r\n|\r/g, '\n')
+ ) {
if (!isMismatchAllowed(el, MismatchTypes.TEXT)) {
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration text content mismatch on`,
el,
- `\n - rendered on server: ${el.textContent}` +
- `\n - expected on client: ${vnode.children as string}`,
+ `\n - rendered on server: ${textContent}` +
+ `\n - expected on client: ${clientText}`,
)
logMismatchError()
}
-
el.textContent = vnode.children as string
}
}