I'm using Inertia.js + Vue 3 for Server-Side Rendering (SSR). In certain cases, I want to pre-fetch and set data during server-side rendering.
<template>
data: {{myData}}
</template>
<script setup>
import {ref} from "vue";
const isServer = typeof window === 'undefined'
const myData = ref(null)
if (isServer) {
console.log('on server')
myData.value = 'data from server'
} else {
console.log('on client')
if (myData.value === null) {
myData.value = 'data is null'
}
}
</script>
Both console logs are visible. However, in the browser, myData initially displays as 'Data from the server' but quickly changes to 'Data is null'. When I check the page source, myData is rendered as 'Data from the server'.
Does this mean that the const myData gets redefined as null when the browser renders the page? Is this normal behavior, and does it imply that prefetching data while rendering on the server is not possible?
My expectation is that if the page is rendered on the client, it should display skeletons and perform a partial reload. But if the page is rendered on the server, it should fully render without a partial reload.
Any insights or solutions would be greatly appreciated. Thank you!