# SSR

To get started you'll first need to upgrade to the following package versions:

* `@useractify/search` version **5.50.1** (minimum)

Afterwards you'll use the `generateProviderProps` method on the server, you provide all of the props you normally would to the `ReactifySearchProvider` component, these props will be parsed and then returned with an additional prop called `preload`, this is what enables SSR to work correctly.

In addition to the usual props there is a new one called `query` which should contain the url query params as an object which will look something like this e.g.

```typescript
const url = `/collections/all?category=%5B"Shorts"%5D&colour=%5B"atlantic"%5D`;
const query = {
  category: "[\"Shorts\"]",
  colour: "[\"atlantic\"]",
};
```

The tech stack you're using will determine exactly how this should be implemented but generally speaking you'll want to serialise the return value of `generateProviderProps` and pass it to the client, see some examples below.

### NextJs

**Sandbox** <https://codesandbox.io/p/devbox/reactify-search-ssr-nextjs-sandbox-p28m4g>

```javascript
import React from "react";
import { ReactifySearchProvider, generateProviderProps } from "@usereactify/search";

// "props" is the return value from Main.getInitialProps
const Main = (props) => {
  return (
    <ReactifySearchProvider
      {...props}
    >
      ...
    </ReactifySearchProvider>
  );
};

// Runs on the server, returns the props provided and generates the special "preload" prop
Main.getInitialProps = async (context) => {
  const serverProps = await generateProviderProps({
    mode: "collection",
    collectionHandle: "shirts",
    shopifyPermanentDomain: "usereactify-demo-big.myshopify.com",
    query: context.query,
  });
  
  return serverProps;
};

export default Main;

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://search.docs.reactify.com.au/guides/ssr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
