You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Flag to Favor Hydration Performance over User Safety (#28655)
If false, this ignores text comparison checks during hydration at the
risk of privacy safety.
Since React 18 we recreate the DOM starting from the nearest Suspense
boundary if any of the text content mismatches. This ensures that if we
have nodes that otherwise line up correctly such as if they're the same
type of Component but in a different order, then we don't accidentally
transfer state or attributes to the wrong one.
If we didn't do this e.g. attributes like image src might not line up
with the text. E.g. you might show the wrong profile picture with the
wrong name. However, the main reason we do this is because it's a
security/privacy concern if state from the original node can transfer to
the other one. For example if you start typing into a text field to
reply to a story but then it turns out that the hydration was in a
different order, you might submit that text into a different story than
you intended. Similarly, if you've already clicked an item and that gets
replayed using Action replaying or is synchronously force hydrated -
that click might end up applying to a different item in the list than
you intended. E.g. liking the wrong photo.
Unfortunately a common case where this happens is when Google Translate
is applied to a page. It'll always cause mismatches and recreate the
tree. Most of the time this wouldn't be visible to users because it'd
just recreate to the same thing and then translate again. It can affect
metrics that trace when this hydration happened though.
Meta can use this flag to decide if they favor this perf metric over the
risk to user privacy.
This is similar to the old enableClientRenderFallbackOnTextMismatch flag
except this flag doesn't patch up the text when there's a mismatch.
Because we don't have the patching anymore. The assumption is that it is
safe to ignore the safety concern because we assume it's a match and
therefore favoring not patching it will lead to better perf.
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
86
-
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
87
+
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
88
+
89
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
90
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
91
+
- Date formatting in a user's locale which doesn't match the server.
92
+
- External changing data without sending a snapshot of it along with the HTML.
93
+
- Invalid HTML tag nesting.
94
+
95
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
96
+
97
+
https://react.dev/link/hydration-mismatch
98
+
99
+
<Mismatch isClient={true}>
100
+
<div className="parent">
101
+
<main className="child">
102
+
+ client
103
+
- server
104
+
]",
105
+
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
"Warning: A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:
87
112
88
-
- A server/client branch \`if (typeof window !== 'undefined')\`.
89
-
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
90
-
- Date formatting in a user's locale which doesn't match the server.
91
-
- External changing data without sending a snapshot of it along with the HTML.
92
-
- Invalid HTML tag nesting.
113
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
114
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
115
+
- Date formatting in a user's locale which doesn't match the server.
116
+
- External changing data without sending a snapshot of it along with the HTML.
117
+
- Invalid HTML tag nesting.
93
118
94
-
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
119
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
95
120
96
-
https://react.dev/link/hydration-mismatch
121
+
https://react.dev/link/hydration-mismatch
97
122
98
-
<Mismatch isClient={true}>
99
-
<div className="parent">
100
-
<main className="child">
101
-
+ client
102
-
- server
103
-
]",
104
-
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
126
-
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
152
+
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
127
153
128
-
- A server/client branch \`if (typeof window !== 'undefined')\`.
129
-
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
130
-
- Date formatting in a user's locale which doesn't match the server.
131
-
- External changing data without sending a snapshot of it along with the HTML.
132
-
- Invalid HTML tag nesting.
154
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
155
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
156
+
- Date formatting in a user's locale which doesn't match the server.
157
+
- External changing data without sending a snapshot of it along with the HTML.
158
+
- Invalid HTML tag nesting.
133
159
134
-
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
160
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
135
161
136
-
https://react.dev/link/hydration-mismatch
162
+
https://react.dev/link/hydration-mismatch
137
163
138
-
<Mismatch isClient={true}>
139
-
<div>
140
-
+ This markup contains an nbsp entity: client text
141
-
- This markup contains an nbsp entity: server text
142
-
]",
143
-
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
144
-
]
145
-
`);
164
+
<Mismatch isClient={true}>
165
+
<div>
166
+
+ This markup contains an nbsp entity: client text
167
+
- This markup contains an nbsp entity: server text
168
+
]",
169
+
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
"Warning: A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:
176
+
177
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
178
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
179
+
- Date formatting in a user's locale which doesn't match the server.
180
+
- External changing data without sending a snapshot of it along with the HTML.
181
+
- Invalid HTML tag nesting.
182
+
183
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
184
+
185
+
https://react.dev/link/hydration-mismatch
186
+
187
+
<Mismatch isClient={true}>
188
+
<div>
189
+
+ This markup contains an nbsp entity: client text
190
+
- This markup contains an nbsp entity: server text
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
555
-
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
"Warning: An error occurred during hydration. The server HTML was replaced with client content.",
605
+
"Caught [Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
606
+
607
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
608
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
609
+
- Date formatting in a user's locale which doesn't match the server.
610
+
- External changing data without sending a snapshot of it along with the HTML.
611
+
- Invalid HTML tag nesting.
612
+
613
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
614
+
615
+
https://react.dev/link/hydration-mismatch
616
+
617
+
<Mismatch isClient={true}>
618
+
<div className="parent">
619
+
+ only
620
+
-
621
+
]",
622
+
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
"Warning: A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:
556
629
557
-
- A server/client branch \`if (typeof window !== 'undefined')\`.
558
-
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
559
-
- Date formatting in a user's locale which doesn't match the server.
560
-
- External changing data without sending a snapshot of it along with the HTML.
561
-
- Invalid HTML tag nesting.
630
+
- A server/client branch \`if (typeof window !== 'undefined')\`.
631
+
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
632
+
- Date formatting in a user's locale which doesn't match the server.
633
+
- External changing data without sending a snapshot of it along with the HTML.
634
+
- Invalid HTML tag nesting.
562
635
563
-
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
636
+
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
564
637
565
-
https://react.dev/link/hydration-mismatch
638
+
https://react.dev/link/hydration-mismatch
566
639
567
-
<Mismatch isClient={true}>
568
-
<div className="parent">
569
-
+ only
570
-
-
571
-
]",
572
-
"Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]",
0 commit comments