Replies: 44 comments 41 replies
-
Have similar use case. My search page url is like |
Beta Was this translation helpful? Give feedback.
-
I propose being able to export a function that allows defining the query parameters that should be used to generate different static pages (because you probably don't want to generate a different static page if the only changed parameter was Example for
(they would behave similarly to In this case, I would expect to generate the pages statically, and returning the statically generated page based on the slug and query parameters. This is very important if you want static pages with pagination that have the page number in the query, or for pages that have a search mechanism and the search params are sent in the query (which is natural, although it could be passed in the path too). The query parameters that would be considered could be specified in a method similar to Proposal: getStaticParamsexport function getStaticParams() {
return ['page', 'order'];
} This method would return an array of strings with the query parameters that should be considered for SSG, similarly to how it already happens in the case of slugs in the page path, and at the same time it would also able to ignore parameters like Facebook In this case it would generate different static pages for |
Beta Was this translation helpful? Give feedback.
-
I have the same issue as @lucasbasquerotto: in my case I want to get the same regenerated page taking into account only the slug, especially because for traffic coming from Facebook Ads there's the query param |
Beta Was this translation helpful? Give feedback.
-
Hi! We have the same issue, I would like a certain number of selected, frequently visited or SEO-friendly search results to be SSGed and can't due to query parameters not being handled by getStaticPaths/Props :/ Have like a hundred of versions of this page SSGed basically, corresponding to search results valued by the business for specific purposes. |
Beta Was this translation helpful? Give feedback.
-
Totally agree with those ideas of including In my case, I have a small blog with pagination, and it could be very fast with GSP (I could build all the pagination pages in Would be awesome to use |
Beta Was this translation helpful? Give feedback.
-
We also have this use case. I would love to have this. |
Beta Was this translation helpful? Give feedback.
-
I also have this issue. Everyone seems focused on a new export async function getStaticPaths() {
return {
fallback: false,
pages: [
{ params: { pathSegment }, query: { getParam } },
],
}
} That would certainly suit my needs, and IMO it makes sense to treat dynamic path segments and GET params similarly. |
Beta Was this translation helpful? Give feedback.
-
Are there |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
+1 for this, it'd be very helpful! @timneutkens do you guys have any plans to implement this any time soon? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Yea would be awesome to see this. Currently my solution is to have one static generated page with all known paths/params, and then a second server side page which handles any custom filters with queries.
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Another point that is directly related to this request is the possibility of also accessing the host that is making the request within I saw in some issues members of Vercel team discarding this possibility saying that A very clear case where it is necessary to know which host within |
Beta Was this translation helpful? Give feedback.
-
**Hot take**: I'm probably over simplifying things, but I see very little reason why getStaticProps and getServerSideProps should have totally different APIs, and when you pick one you get locked out of seemingly unrelated features only available to the other (I'm looking at you, prefetching). Effectively SSG and ISR are caches, why not transparently treat them like caches instead of being opaque about it?
Splitting users into two tracks and supporting some features in one track and not in the other creates a divided ecosystem and lots of maintenance overhead. Is there a good reason not to just have `getProps` and allow users to configure any caching as their needs require? getStaticPaths is just pre warming the cache, why not make it less opaque by exposing a `prewarmCache` or `preload` API where users can make/describe any requests (including headers, query params, path, etc) as needed?
I'm already seeing issues with the cache-that's-not-a-cache approach:
1. SSR routes cannot have their json data prefetched. Why? Why do I have to rewrite my entire app to use getStaticProps (and give up access to query params, headers etc) just to take advantage of this feature? Sure, make it opt in so that people don't accidentally blow up their origin, but I don't see why it's limited to SSG
2. No access to the request and response object in getStaticProps routes. Yes, I get that these routes will be served from the file system (cache), but why not let users define their own cache keys and stick some basic cache eviction on there to prevent the cache exploding if a user decides they want to cache on every query param and header. There *is* a request object during revalidation / initial generation, and access to that can be incredibly powerful, even for 'static-ish' content. [Cloudfront does this](https://aws.amazon.com/blogs/networking-and-content-delivery/amazon-cloudfront-announces-cache-and-origin-request-policies), as does [Cloudflare](https://support.cloudflare.com/hc/en-us/articles/115004290387-Creating-Cache-Keys) and it's tremendously useful.
3. No ability to programmatically invalidate the SSG/ISR cache. Any cache should have the ability to clear all or part of it when we know the content has changed. Computing ETags is expensive when you're using a DB or CMS to drive your content. It's much more performant to push an invalidation on content changes.
I can tell that my tone is a little combative, I'm not meaning to be. I think Next.js is a great project with a lot of great direction, but this one thing feels a bit off to me.
…On Mon, Apr 5, 2021 at 12:21 AM Jean Marcos ***@***.***> wrote:
Another point that is directly related to this request is the possibility
of also accessing the host that is making the request within
getStaticProps.
I saw in some issues members of Vercel team discarding this possibility
saying that getStaticProps will be executed at build time, and therefore
there is no access to the request object. However, *since the fallback
option (including its blocking value) has been added, we must consider use
cases where getStaticProps will be run on the production server when the
fallback is true.*
A very clear case where it is necessary to know which host within
getStaticProps is the case of a page that runs on *multiple domains
(tenants)* and that needs *SEO*. Using getStaticProps currently I just
can't get the *absolute url* for the page, so I can't set the meta tags
correctly, like og: url.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#17269 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS6R3RUAHSHWEALIGHB6ETTHDX67ANCNFSM4SSFBLSQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I seem to have the exact opposite requirement to the OP. For us, we want Is there a way to do this currently without having to separate into two different pages? |
Beta Was this translation helpful? Give feedback.
-
+1 for this, it'd be very helpful! I have the same case but I am unable to get query params in getStaticProps. Next.js v13 |
Beta Was this translation helpful? Give feedback.
-
Any plans for a solution in nextjs 13 with appDir? My use case is that I need one searchParam which might have 5 different values for each page. Currently I need to switch to dynamic rendering although static rendering is what I want. |
Beta Was this translation helpful? Give feedback.
-
Same problem, I can´t set the |
Beta Was this translation helpful? Give feedback.
-
Same problem! Is there a solution? |
Beta Was this translation helpful? Give feedback.
-
Similar problem here though mine has an additional need to generate different responses based on a request header as well as the search params. We have product pages with product types that are available in multiple colour and size options. The url structure is like To complicate matters further we also have a service in front of our application that sends through a header containing a list of AB test feature flag settings to render the page with. So in order to use ISR we'd need access to this too. It's kind of crazy that we're building exactly the sort of application that nextjs would shine for but we can't use a core feature like this because we have no control over what's included in the cache key. |
Beta Was this translation helpful? Give feedback.
-
+1 for this! |
Beta Was this translation helpful? Give feedback.
-
Any solution yet for this? |
Beta Was this translation helpful? Give feedback.
-
Following |
Beta Was this translation helpful? Give feedback.
-
Wondering if it is not possible to use redirects in next.config or middleware to achieve this?
// next.config.js
|
Beta Was this translation helpful? Give feedback.
-
Following this too!, I have a page called /houses and also a dynamic one called /houses/[id] now I only have 15 houses on the website thus I used generateStaticParams and next js now uses SSG to render all those house pages statically only in build time the thing is, at the /houses route where the user can see all the houses I have a place where they can filter the house in some ways, but not that many combinations, I filter through the query parameters and as soon as I use searchParams my page automatically becomes dynamic, which I don't want! we need a solution not only for dynamic routes (aka [id]) but also for searchParams aka /houses?min-price=300 so even if I have 20 different filter combination I can use SSG and pre render them all in build time saving major costs in requests! edit: there is one solution I came up with which I dont like, instead of using /houses to display the houses I can seperate them so /house/[id] is one route and /houses/[filter] is a second route but it is a really dumb solution because as soon as I want multiple queries it becomes very weird to manage |
Beta Was this translation helpful? Give feedback.
-
Following |
Beta Was this translation helpful? Give feedback.
-
Following |
Beta Was this translation helpful? Give feedback.
-
following |
Beta Was this translation helpful? Give feedback.
-
following |
Beta Was this translation helpful? Give feedback.
-
any news here? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Feature request
Hi NextJS. Thanks for the great OSS.
Is your feature request related to a problem? Please describe.
As
getStaticProps
now supportfallback
and server-side SWR, it'd be much more useful ifGetStaticPropsContext
supports URL query string like?foo=bar
.Our users spend the largest amount of time on searchable pages, such as
/products?brand=x
,/restaurants?type=italian
,/products/that-t-shirt?size-max=12
, etc. It is essential forgetStaticProps
to supportfallback
with either full URL or query string as params. Otherwise, we can only adopt GSP for a very small portion of pages. Feel like a waste of such a valuable feature.Describe the solution you'd like
I'd prefer NextJs to keep it simple and provide a URL path string as it is now from
NextContext
ofgetInitialProps
. So that we can customize the way to parse these URLs.Describe alternatives you've considered
Currently, there is already a
params
provided inGetStaticPropsContext
, but it excludes the query string. It'd be okay if NextJS putquery
inGetStaticPropsContext
like existing GSSP androute.query
. It's just that the query string formats for recursive/SEO-friendly object and array are always subjective and questionable.Beta Was this translation helpful? Give feedback.
All reactions