File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -1908,6 +1908,21 @@ describe('SSR hydration', () => {
1908
1908
expect ( `Hydration attribute mismatch` ) . toHaveBeenWarned ( )
1909
1909
} )
1910
1910
1911
+ // #11873
1912
+ test ( '<textarea> with newlines at the beginning' , async ( ) => {
1913
+ const render = ( ) => h ( 'textarea' , null , '\nhello' )
1914
+ const html = await renderToString ( createSSRApp ( { render } ) )
1915
+ mountWithHydration ( html , render )
1916
+ expect ( `Hydration text content mismatch` ) . not . toHaveBeenWarned ( )
1917
+ } )
1918
+
1919
+ test ( '<pre> with newlines at the beginning' , async ( ) => {
1920
+ const render = ( ) => h ( 'pre' , null , '\n' )
1921
+ const html = await renderToString ( createSSRApp ( { render } ) )
1922
+ mountWithHydration ( html , render )
1923
+ expect ( `Hydration text content mismatch` ) . not . toHaveBeenWarned ( )
1924
+ } )
1925
+
1911
1926
test ( 'boolean attr handling' , ( ) => {
1912
1927
mountWithHydration ( `<input />` , ( ) => h ( 'input' , { readonly : false } ) )
1913
1928
expect ( `Hydration attribute mismatch` ) . not . toHaveBeenWarned ( )
Original file line number Diff line number Diff line change @@ -440,7 +440,17 @@ export function createHydrationFunctions(
440
440
remove ( cur )
441
441
}
442
442
} else if ( shapeFlag & ShapeFlags . TEXT_CHILDREN ) {
443
- if ( el . textContent !== vnode . children ) {
443
+ // #11873 the HTML parser will "eat" the first newline when parsing
444
+ // <pre> and <textarea>, so if the client value starts with a newline,
445
+ // we need to remove it before comparing
446
+ let clientText = vnode . children as string
447
+ if (
448
+ clientText [ 0 ] === '\n' &&
449
+ ( el . tagName === 'PRE' || el . tagName === 'TEXTAREA' )
450
+ ) {
451
+ clientText = clientText . slice ( 1 )
452
+ }
453
+ if ( el . textContent !== clientText ) {
444
454
if ( ! isMismatchAllowed ( el , MismatchTypes . TEXT ) ) {
445
455
; ( __DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ ) &&
446
456
warn (
@@ -753,7 +763,7 @@ export function createHydrationFunctions(
753
763
const isTemplateNode = ( node : Node ) : node is HTMLTemplateElement => {
754
764
return (
755
765
node . nodeType === DOMNodeTypes . ELEMENT &&
756
- ( node as Element ) . tagName . toLowerCase ( ) === 'template '
766
+ ( node as Element ) . tagName === 'TEMPLATE '
757
767
)
758
768
}
759
769
You can’t perform that action at this time.
0 commit comments