SSR support for Next.js 13 /app
directory?
#5413
-
Hi Team, do you have any plan to support Next.js 13, specially for the SSR? I tested for the client-side rendering, seems working so far. Few routing issues but those are already addressed here. However, SSR is not working at all with the |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 29 replies
-
We haven't yet tried the beta app directory. At the moment I'm not sure where it would fit in, as they expect usage of |
Beta Was this translation helpful? Give feedback.
-
We (http://shop.coop.co.uk) are starting to rebuild our site in Next 13 and we would love to see support for the new @Haroenv it might be worth engaging with some of the Next/Vercel developer relations team (led by @leerob) to see if they can give any advice on your query/thought above. I also noticed that the Next 13 |
Beta Was this translation helpful? Give feedback.
-
My team would also benefit from support for SSR in the |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
Hey all, Just wanted to bump this issue again. We worked around this by going client-side but I'd like to know if there's any plans for addressing this on the roadmap. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? I'm also waiting for a proper solution with Next js 13 app dir. |
Beta Was this translation helpful? Give feedback.
-
@Haroenv can you give an update on this topic? Is it on your roadmap or can we expect to build a solution on our own with direct API access if we want to realize a app-router project within the next half year? |
Beta Was this translation helpful? Give feedback.
-
While There are some caveats that prevent us from documenting this officially
Those caveats taken in account, here's an example: https://codesandbox.io/p/sandbox/interesting-rhodes-4pgtu6?file=%2Fapp%2Fpage.tsx "use client";
import React, { use } from "react";
import algoliasearch from "algoliasearch/lite";
import { Hit as AlgoliaHit } from "instantsearch.js";
import {
DynamicWidgets,
InstantSearch,
Hits,
Highlight,
RefinementList,
SearchBox,
InstantSearchSSRProvider,
InstantSearchServerState,
} from "react-instantsearch-hooks-web";
import { renderToString } from "react-dom/server";
import { Panel } from "../components/Panel";
import { getServerState } from "react-instantsearch-hooks-server";
const client = algoliasearch("latency", "6be0576ff61c053d5f9a3225e2a90f76");
type HitProps = {
hit: AlgoliaHit<{
name: string;
price: number;
}>;
};
function Hit({ hit }: HitProps) {
return (
<>
<Highlight hit={hit} attribute="name" className="Hit-label" />
<span className="Hit-price">${hit.price}</span>
</>
);
}
type SearchPageProps = {
serverState?: InstantSearchServerState;
};
function Search({ serverState }: SearchPageProps) {
return (
<InstantSearchSSRProvider {...serverState}>
<InstantSearch
searchClient={client}
indexName="instant_search"
insights={true}
>
<div className="Container">
<div>
<DynamicWidgets fallbackComponent={FallbackComponent} />
</div>
<div>
<SearchBox />
<Hits hitComponent={Hit} />
</div>
</div>
</InstantSearch>
</InstantSearchSSRProvider>
);
}
function FallbackComponent({ attribute }: { attribute: string }) {
return (
<Panel header={attribute}>
<RefinementList attribute={attribute} />
</Panel>
);
}
export default function SearchPage() {
const serverState = use(
getServerState(<Search />, {
renderToString,
})
);
return <Search serverState={serverState} />;
} Remember as well that when you use App dir, you don't have to convert your entire app at once, you can leave the search page as a regular "pages" component. |
Beta Was this translation helpful? Give feedback.
-
This is what we're doing at the moment for our search page and category/taxonomy page, but it's not ideal – there is a hard browser navigation/load as users move between the Thanks a lot for sharing the experimental example, it's great to see that your team have been looking into this :) |
Beta Was this translation helpful? Give feedback.
-
Not really an option for us as we are converting to new app dir in next js and going backwards to the pages folder just is not an option. We have instantsearch working under new structure except for routing section. And nothing we try seems to work. Could be the algolia deal breaker. Seems we would have a working option by now. It's been months. Answer above is not "answer" as it does not contain routing. |
Beta Was this translation helpful? Give feedback.
-
Hey all, I'm updating this discussion with news ! We released an experimental package which supports Next.js App Router, you can check its usage there : https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#app-router-experimental Don't hesitate to provide feedback right here ! A few drawbacks we already know of are that using the browser's forward button from one InstantSearch page to another can have issues, and there currently is a useless query being made on the client but it will be fixed by #5854 |
Beta Was this translation helpful? Give feedback.
Hey all, I'm updating this discussion with news !
We released an experimental package which supports Next.js App Router, you can check its usage there : https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#app-router-experimental
Don't hesitate to provide feedback right here !
A few drawbacks we already know of are that using the browser's forward button from one InstantSearch page to another can have issues, and there currently is a useless query being made on the client but it will be fixed by #5854