question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different query params in getStaticProps cause ignore cache

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
hatsumatsucommented, Aug 3, 2021

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.

1reaction
styflecommented, Sep 30, 2021

Would still be great to have a fix for this in nextjs to account for generic nodejs hosting solutions.

I tried the steps to reproduce and it only reproduces on Vercel, not with next start. Therefore, the fix is only for Vercel.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found