-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using generateStaticParams causes issues with searchParams #49735
Comments
I encounter almost the same problem. Using If I remove the Is there any solution? |
@filipkowal, not that I know of at the moment. Maybe @leerob can get some eyes on it as this has been an issue for a couple of months now (it was originally part of the discussion of App dir) |
If you are trying to dynamically read URL search params, this requires the page being dynamic. A statically generate page would not have access to the incoming request where the search parameters are read. |
Ok maybe a dumb question, is there a way to have both? For example have the main content of the page static but the metadata dynamic? Because usually you want to canonical paginate pages to itself. |
Could you expand more on what you're trying to use the query parameters for in this instance? |
Yeah, so my paginated pages are ?page=2 for example. In order to self canonical (which if my memory is serving me correctly is the right move), I need that searchParam in generateMetadata in order to do so. I would also like to update the title to reference what page the user is on. This is a common practice with paginated pages. |
At first, I thought we're having the same problem with the generateStaticParams being in the root layout and a dynamic page inside (which is explained here #49373) but if you are trying to have both generateStaticParams and use searchParams on the same page, the error is a correct outcome. You cannot have both, static and dynamic on one page. It would be helpful if the linter informed about it. Have you tried the following approach to pagination though? If you'd like to have statically generated paginated pages, you can have the pagination defined as a route |
@filipkowal yea that would be nice of the linter to inform you of that because technically nothing breaks in production and if you refresh locally it goes away. As for you suggestion, Google recommends Also in my case I have In the production version of this website I have the categories hardcoded as I did do some research into competition and
I just didn't want their to be a collision of |
@JamesSingleton This is the same with cookies and generateStaticParams. As an example: export function generateStaticParams() {
return [];
} This will cause our pages to be statically generated by users visiting the product pages which is great! But now we'd like the price on those PDP's to be dynamic per customer and basically stream them in via a Reading trough multiple issue on GH like #49373, I noticed that everyone expects to be able to mix static and dynamic components which is not the case, your page either needs to be fully static or will be dynamic. I noted the following "Good to know" section on https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering stating the following: "In the future, Next.js will introduce hybrid server-side rendering where layouts and pages in a route can be independently statically or dynamically rendered, instead of the whole route." @leerob please feel free correct me where I'm wrong. |
@Jordaneisenburger yea, I guess I would expect some sort of error to be thrown or warning to persist if it was truly an issue. After diving into it more it makes sense and it would be nice if I could do server components with pagination but with my current setup I can't because I already have a dynamic route. That is why I fell back on |
This comment has been minimized.
This comment has been minimized.
@tseppl There is a partial solution that allows you to use middleware to separate requests without searchParams (and generate them statically) and requests with searchParams (these must be dynamic). So, for example:
Check out both versions of the category page (clp and plp) and the middleware. This is not a complete solution to the problem (I believe that partial prerendering will be), but it always allows a large part of the pages to be statically rendered (and load faster) |
But you could render it with default params.. (for example pagination) |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 Binaries: Node: 18.16.0 npm: 9.5.1 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 13.4.3-canary.0 eslint-config-next: 13.4.2 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/JamesSingleton/searchparams-issue-next-13
To Reproduce
npm run dev
Go to FCS Category
Describe the Bug
For some reason due to using
generateStaticParams
, if the page you are going to uses thesearchParams
param available to the page andgenerateMetadata
functions you will get aDynamic server usage: searchParams.page
Expected Behavior
Ideally there is no error. I have gone through https://nextjs.org/docs/app/api-reference/functions/generate-static-params#generate-params-from-the-top-down but there is no mention of
searchParams
.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: