Consider a Vue 3 app using SSR. The server renders a list of items, but the client has a different list initially. What will Vue do during hydration?
<template>
<ul>
<li v-for="item in items" :key="item.id">{{ item.text }}</li>
</ul>
</template>
<script setup>
import { ref } from 'vue'
const items = ref([{ id: 1, text: 'A' }, { id: 2, text: 'B' }])
// Assume server rendered items: [{ id: 1, text: 'A' }, { id: 2, text: 'C' }]
</script>Think about how Vue tries to reuse server markup and patch only differences.
Vue's hydration process reuses the server-rendered DOM and patches only the differences found in client data. It updates text content or attributes as needed without full re-rendering.
In a Vue 3 SSR app, the server renders the component and the client hydrates it. At what point does the mounted() lifecycle hook run?
Consider when the component is fully interactive on the client.
The mounted() hook runs after hydration completes and the component is attached to the DOM on the client. It does not run on the server.
Given this Vue 3 SSR app, the console shows a hydration warning about mismatched content. What causes this warning?
<template>
<div>{{ message }}</div>
</template>
<script setup>
import { ref } from 'vue'
const message = ref('Hello from client')
// Server rendered message was 'Hello from server'
</script>Check if the server and client render the same text content.
Hydration warnings occur when the client-side data produces different markup than the server-rendered HTML, causing Vue to detect mismatches.
Choose the code snippet that prevents hydration mismatch by ensuring server and client render the same content.
Think about what value the server rendered and what the client starts with.
To avoid hydration mismatch, the initial client state must match the server-rendered content. Setting count to 1 initially matches server output.
Given this Vue 3 SSR component, what will the user see after hydration completes?
<template> <button @click="increment">Clicked {{ count }} times</button> </template> <script setup> import { ref } from 'vue' const count = ref(5) // server rendered with count=5 function increment() { count.value++ } </script>
Consider how Vue preserves reactive state from server to client during hydration.
Vue hydrates with the server state (count=5). The button shows 'Clicked 5 times' initially and increments correctly on clicks.