Skip to content

Commit 9bc11b2

Browse files
committed
3.5: data-allow-mismatch
1 parent e1a923e commit 9bc11b2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/api/ssr.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,23 @@ A runtime API used to retrieve the context object passed to `renderToString()` o
220220
}
221221
</script>
222222
```
223+
224+
## data-allow-mismatch <sup class="vt-badge" data-text="3.5+" /> {#data-allow-mismatch}
225+
226+
A special attribute that can be used to suppress [hydration mismatch](/guide/scaling-up/ssr#hydration-mismatch) warnings.
227+
228+
- **Example**
229+
230+
```html
231+
<div data-allow-mismatch="text">{{ data.toLocaleString() }}</div>
232+
```
233+
234+
The value can limit the allowed mismatch to a specific type. Allowed values are:
235+
236+
- `text`
237+
- `children` (only allows mismatch for direct children)
238+
- `class`
239+
- `style`
240+
- `attribute`
241+
242+
If no value is provided, all types of mismatches will be allowed.

src/guide/scaling-up/ssr.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ If the DOM structure of the pre-rendered HTML does not match the expected output
314314

315315
When Vue encounters a hydration mismatch, it will attempt to automatically recover and adjust the pre-rendered DOM to match the client-side state. This will lead to some rendering performance loss due to incorrect nodes being discarded and new nodes being mounted, but in most cases, the app should continue to work as expected. That said, it is still best to eliminate hydration mismatches during development.
316316

317+
#### Suppressing Hydration Mismatches <sup class="vt-badge" data-text="3.5+" /> {#suppressing-hydration-mismatches}
318+
319+
In Vue 3.5+, it is possible to selectively suppress inevitable hydration mismatches by using the [`data-allow-mismatch`](/api/ssr#data-allow-mismatch) attribute.
320+
317321
### Custom Directives {#custom-directives}
318322

319323
Since most custom directives involve direct DOM manipulation, they are ignored during SSR. However, if you want to specify how a custom directive should be rendered (i.e. what attributes it should add to the rendered element), you can use the `getSSRProps` directive hook:

0 commit comments

Comments
 (0)