Different query params in getStaticProps cause ignore cache
See original GitHub issueWhat version of Next.js are you using?
11.0.1
What version of Node.js are you using?
14.17.1
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Hello, when I enter in my application like https://myapp.com/offer/1?utm_source=twitter
then I receive a cached page (I’m using ISR), the code:
// File: pages/offer/[id]/index.js
export async function getStaticPaths() {
return {
paths: [],
fallback: true,
};
}
export async function getStaticProps(context) {
const { offer } = await getOffer(context.params.id);
return {
props: {
offer,
},
revalidate: 300,
};
}
BUT, if I enter in https://myapp.com/offer/1?utm_source=facebook
, the getOffer
function is called again, even with revalidate
prop. How do avoid this? I need the same page without a new api call.
Expected Behavior
The same page without a new api call
To Reproduce
// File: pages/offer/[id]/index.js
export async function getStaticPaths() {
return {
paths: [],
fallback: true,
};
}
export async function getStaticProps(context) {
const { offer } = await getOffer(context.params.id);
return {
props: {
offer,
},
revalidate: 300,
};
}
- enter in
https://myapp.com/offer/1?utm_source=twitter
- enter ir
https://myapp.com/offer/1?utm_source=facebook
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Make getStaticProps support URL query string #17269
I propose being able to export a function that allows defining the query parameters that should be used to generate different static pages...
Read more >Next.js query params inside getStaticProps (Incremental Static ...
Have you ever wondered how to access query parameters "context.req.query" inside getStaticProps ???In this video we will look at a possible ...
Read more >Why can't I get query params in ```getStaticProps```?
I understand that getInitialProps is now deprecated, but it works. Why is not getStaticProps working, and should I use it instead of ...
Read more >Shallow Routing
Shallow routing allows you to change the URL without running data fetching methods again, that includes getServerSideProps , getStaticProps , and ...
Read more >Mastering data fetching with React Query and Next.js
Learn how React Query simplifies data fetching and caching for you ... or no library according to the nature and scale of your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a valid concern. Many sites face randomized query parameters from third parties they can not control which produces a huge amount of computation on hosts like vercel.
I tried the steps to reproduce and it only reproduces on Vercel, not with
next start
. Therefore, the fix is only for Vercel.