Consider this Astro component that fetches data and renders it. SSR is enabled in the project.
---
const data = await fetch('https://api.example.com/items').then(res => res.json());
---
-
{data.items.map(item => (
<li>{item.name}</li>
))}
What will the user see when visiting this page?
--- const data = await fetch('https://api.example.com/items').then(res => res.json()); --- <ul> {data.items.map(item => ( <li>{item.name}</li> ))} </ul>
Think about when the data is fetched and how SSR works in Astro.
With SSR enabled, Astro fetches data on the server before sending HTML. So the list is fully rendered in the HTML.
You want to enable SSR in your Astro project. Which of these astro.config.mjs snippets is correct?
Check Astro's official config option for SSR output.
Astro enables SSR by setting output: 'server' in the config file.
This Astro page uses SSR and fetches data. But it crashes with ReferenceError: window is not defined. Why?
---
const data = await fetch('https://api.example.com/data').then(r => r.json());
const width = window.innerWidth;
---
Screen width: {width}
--- const data = await fetch('https://api.example.com/data').then(r => r.json()); const width = window.innerWidth; --- <p>Screen width: {width}</p>
Think about what runs on the server vs the browser.
During SSR, code runs on the server where window does not exist, causing the error.
This Astro component uses SSR and client hydration for interactivity.
--- import Counter from '../components/Counter.jsx'; ---Counter Example
The Counter component starts at 0 and increments on button click. What does the user see initially?
--- import Counter from '../components/Counter.jsx'; --- <h1>Counter Example</h1> <Counter client:load />
Consider how SSR and client hydration work together in Astro.
SSR renders the initial HTML with the button showing 'Count: 0'. Client hydration makes it interactive.
Choose the most accurate description of what enabling SSR in Astro does.
Think about what SSR means in web development.
SSR means server-side rendering: pages are built on the server and sent as complete HTML.
