Closed KallendJack closed 3 months ago
Hi @KallendJack,
Can't reproduce without a link, but where exactly does the hydration problem occur ? I think later versions of React now help with visualization, but you can compare the DOM markup between the initial HTTP request and what's rendered after hydration, this would help pinpoint where the problem lies exactly.
It could be due to other libraries you're using like Mantine which may render differently on the server (if isMobile
is true
on the server and false
on the client, you'd have an error like this). Without a reproduction and exact pinpointing of the DOM diffs between server and client it's hard to tell.
Hi @KallendJack,
Can't reproduce without a link, but where exactly does the hydration problem occur ? I think later versions of React now help with visualization, but you can compare the DOM markup between the initial HTTP request and what's rendered after hydration, this would help pinpoint where the problem lies exactly.
It could be due to other libraries you're using like Mantine which may render differently on the server (if
isMobile
istrue
on the server andfalse
on the client, you'd have an error like this). Without a reproduction and exact pinpointing of the DOM diffs between server and client it's hard to tell.
Hi @aymeric-giraudet. Thanks for your response. Here is the link to the two pages I am seeing the issues:
https://feature-app-dir.peracto3carbon.pub/category/simple-products https://feature-app-dir.peracto3carbon.pub/search?q=s
I have also tried it without Mantine, but I have tried removing many things with no luck.
Locally, it comes up saying the hit count doesn't match:
However, this component only contains the following:
'use client'
import { useStats } from 'react-instantsearch'
export function AlgoliaHitCount() {
const { nbHits } = useStats()
return (
<span data-testid="algolia-hit-count" className="text-sm font-normal text-brand-black">
({nbHits})
</span>
)
}
Hi @KallendJack,
This is due to having two different InstantSearchNext
components on the page which is not supported.
I can think of two ways to fix this, in order of simplicity/relevance :
InstantSearch
instead of InstantSearchNext
for the autocomplete ? I'm not sure this needs to be rendered on the server and is even relevant for SEO. This could even be a browser-only component. I see it loads and injects hits on the page on the server even though it's not used in markup. This would make the page perform better too.InstantSearchNext
around the root may work ?Hi @KallendJack,
This is due to having two different
InstantSearchNext
components on the page which is not supported.I can think of two ways to fix this, in order of simplicity/relevance :
- Can you use
InstantSearch
instead ofInstantSearchNext
for the autocomplete ? I'm not sure this needs to be rendered on the server and is even relevant for SEO. This could even be a browser-only component. I see it loads and injects hits on the page on the server even though it's not used in markup. This would make the page perform better too.- Haven't tried it, but having a single
InstantSearchNext
around the root may work ?
Hi @aymeric-giraudet, thanks for this I'll give it a go
@aymeric-giraudet This fixes it... kind of 😆. I am now using InstantSearch for the autocomplete and InstantSearchNext for the category page. However, when the Autocomplete loads in it seems to overwrite the results on the category page. It also seems to use the
Thanks again.
UPDATE
I realized that I had my Autocomplete within the category page as part of my no-results view. This caused the <Configure to be nested inside, causing the error. Changing this to a regular input has fixed the issue. Thanks a lot for your help. I will mark this issue as closed.
Is it an option to use
InstantSearch is designed to be used only once per page, so it's also designed to have only one set of server side rendering results for example
This is now resolved for me. Thanks for all the help. Please see comments above to see how I resolved.
🐛 Current behavior
I have been following the documentation for react-instantsearch-next here
When using this and going to a search page via a hard refresh or directly to the URL. There are hydration errors, which end up displaying the wrong data from Algolia. At first, I thought this may be my setup, but I still receive these errors when setting it up exactly like the docs. This is my current component:
And the page rendering it (page.tsx)
This is making the whole package unusable with SSR for my project, as it is displaying incorrect results and crashing with hydration errors. Any assistance would be greatly appreciated.
package.json
🔍 Steps to reproduce
Live reproduction
N/A
💭 Expected behavior
There are no hydration errors and the correct data is displaying.
Package version
"react-instantsearch": "^7.11.4","react-instantsearch-nextjs": "^0.3.7",
Operating system
macOS
Browser
Chrome
Code of Conduct