instantsearch icon indicating copy to clipboard operation
instantsearch copied to clipboard

fix(react-instantsearch-nextjs): fix incorrect usage of headers

Open cungminh2710 opened this issue 1 year ago • 2 comments

Summary

Currently, NextJS App Router will throw this error when using with react-instantsearch-nextjs

⨯ Error: `headers` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context

This is because the headers are only for server component - not in a client component. The InstantSearchNext component is a client component, hence this error.

image

This PR is to fix this issue by clearly stating InstantSearchNext is a client component, and put the nonce value into InstantSearchNext props

cungminh2710 avatar Aug 24 '24 09:08 cungminh2710

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 218739e7a73443cec5866d82d6798259f74a900e:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

codesandbox-ci[bot] avatar Aug 24 '24 10:08 codesandbox-ci[bot]

Hi, could you explain more why you want to have this change? the example given in the repository works already for server and client navigation. Is this for a different case?

Haroenv avatar Aug 26 '24 08:08 Haroenv

Can you explain more @cungminh2710?

Haroenv avatar Sep 10 '24 09:09 Haroenv

There was some misunderstand from my end when seeing the error. Will close it now as it's working propperly in latest next version 👍

cungminh2710 avatar Sep 17 '24 00:09 cungminh2710

Thanks for your contribution!

Haroenv avatar Sep 17 '24 08:09 Haroenv