> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: About Page Rendering

## Article: About Page Rendering

## Article Link: https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-frontend/about-page-rendering.md

## Article Content:

# About Page Rendering

Page rendering turns a page of your site into what a site visitor sees. When a site visitor loads a page of your published site, the page renders first on the server, and then again in the site visitor's browser. Each [Editor React Component (ERC)](https://dev.wix.com/docs/studio-two/code-your-site/code-model/editor-react-components/about-editor-react-components.md) on the page is a React component, and its code runs in both places. Knowing which parts of it run where helps you avoid repeated side effects, and errors from code that needs a browser.

## How a page renders

When a site visitor loads a page of your published site, including by following a link from another page of your site, the page renders on the server, and the resulting HTML goes to the browser. The browser then runs the code of each ERC again, and React attaches it to the HTML that's already on the page. React calls this step [hydration](https://react.dev/reference/react-dom/client/hydrateRoot). After hydration, ERCs respond to the site visitor, such as when they click a button.

Published pages are cached, so the same server-rendered HTML can go to more than one site visitor. For details, see [About Caching](https://dev.wix.com/docs/studio-two/maintain-your-site/scale-your-site/about-caching.md).

## Where your code runs

Standard React rules decide where each part of the code of an ERC runs:

- **The component function's body:** Runs on the server and again in the browser. This includes everything the component does to determine what to render.
- **Effects:** Run only in the browser, after hydration. Code in a `useEffect()` callback is an example.
- **Event handlers:** Run only in the browser, when the site visitor triggers the event. An `onClick` handler is an example.

The same applies to the code that ERCs get their values from. A [Data Source](https://dev.wix.com/docs/studio-two/code-your-site/code-model/data-sources/about-data-sources.md) attached to the page renders its provider component on the server and again in the browser. A [function library](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/about-function-libraries.md) function that a Wix user connects to an ERC prop also runs in both places.

### Side effects

The component function's body runs on the server and again in the browser. So if that code changes something outside the component, the change can happen more than once. For example, it can save the same record twice, or send an analytics event twice. To keep the change out of the server render, put the code in an effect or an event handler, which run only in the browser.

Because published pages are cached, the server run might not happen for every site visitor. The browser run does.

### Code that needs a browser

The component function's body also runs on the server, where there's no `window` or `document` object, and no browser storage. Code there that reads them throws an error on the server, unless it checks for them first. Put that code in an effect or an event handler, which run only in the browser.

If code in the component function's body needs to know whether it's running on the server, read the `SSR` property of the [Rendering Context API](https://dev.wix.com/docs/sdk/site-sdk/rendering-and-performance/rendering-context/introduction.md). It's `true` while the page renders on the server. Use it for work that doesn't change what the component renders. Don't use it to choose what the component renders, because then the HTML from the server differs from the first browser render.

## Logs and errors during the server render

When your code writes log entries with the monitoring client during the server render, such as with `captureMessage()`, the entries don't appear on the **Logs** page. Only entries from the browser render do. For how to write log entries, see [About Logs in Studio Two](https://dev.wix.com/docs/studio-two/test-your-site/work-with-logs/about-logs-in-studio-two.md).

If an ERC throws an error only during the server render, such as from code that reads `window`, the rest of the page still renders on the server. The HTML from the server leaves out that ERC, and it renders in the browser after hydration. The error doesn't appear on the **Logs** page. To find it, open the browser's developer console and look for the text `Failed to render OOI component in SSR with error:`.

## Server rendering and the editor

The Studio Two editor doesn't render pages on the server. On the canvas and in Preview, ERCs render only in the browser, and the `SSR` property of the Rendering Context API is `false`. So in Preview, code in the component function's body doesn't run on the server, and errors that happen only on the server don't show. To check how a page renders on the server, open a test site or your live site.

## See also

- [About Building a Custom Frontend](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-frontend/about-building-a-custom-frontend.md)
- [About Editor React Components](https://dev.wix.com/docs/studio-two/code-your-site/code-model/editor-react-components/about-editor-react-components.md)
- [About the Rendering Context API](https://dev.wix.com/docs/sdk/site-sdk/rendering-and-performance/rendering-context/introduction.md)