File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ describe('SSR hydration', () => {
8282 expect ( `Hydration children mismatch in <div>` ) . not . toHaveBeenWarned ( )
8383 } )
8484
85+ test ( 'text w/ newlines' , async ( ) => {
86+ mountWithHydration ( '<div>1\n2\n3</div>' , ( ) => h ( 'div' , '1\r\n2\r3' ) )
87+ expect ( `Hydration text mismatch` ) . not . toHaveBeenWarned ( )
88+ } )
89+
8590 test ( 'comment' , ( ) => {
8691 const { vnode, container } = mountWithHydration ( '<!---->' , ( ) => null )
8792 expect ( vnode . el ) . toBe ( container . firstChild )
Original file line number Diff line number Diff line change @@ -460,18 +460,22 @@ export function createHydrationFunctions(
460460 ) {
461461 clientText = clientText . slice ( 1 )
462462 }
463- if ( el . textContent !== clientText ) {
463+ const { textContent } = el
464+ if (
465+ textContent !== clientText &&
466+ // innerHTML normalize \r\n or \r into a single \n in the DOM
467+ textContent !== clientText . replace ( / \r \n | \r / g, '\n' )
468+ ) {
464469 if ( ! isMismatchAllowed ( el , MismatchTypes . TEXT ) ) {
465470 ; ( __DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ ) &&
466471 warn (
467472 `Hydration text content mismatch on` ,
468473 el ,
469- `\n - rendered on server: ${ el . textContent } ` +
470- `\n - expected on client: ${ vnode . children as string } ` ,
474+ `\n - rendered on server: ${ textContent } ` +
475+ `\n - expected on client: ${ clientText } ` ,
471476 )
472477 logMismatchError ( )
473478 }
474-
475479 el . textContent = vnode . children as string
476480 }
477481 }
You can’t perform that action at this time.
0 commit comments