Vue Hydration Mismatch
up:: Vue Usually has two causes:
- Invalid HTML
- Different states in client/server
Invalid HTML
Vue returns the HTML in the virtual DOM as written. The browser is forgiving and ‘fills in the gaps’. Hence the two DOMs don’t match each other.
Different states in client/server
Using Universal Rendering, the code runs both on the server as well as the client. In this example, the Math.random
function gets executed twice. Once on the server, once on the client. The outcome might not be the same. Hence there is a hydration error.
Common pitfalls
- Dates, Timestamps and RaRandomising
- Authentification (the server is not aware of
localStorage
)