GithubHelp home page GithubHelp logo

Revalidation is not working about platforms HOT 7 CLOSED

vercel avatar vercel commented on May 14, 2024 2
Revalidation is not working

from platforms.

Comments (7)

steven-tey avatar steven-tey commented on May 14, 2024 3

Thanks for the bug report @ahanusek @0x6c23 – this should've been fixed with vercel/next.js#38306, you'll just need to make a redeploy :)

from platforms.

0x6c23 avatar 0x6c23 commented on May 14, 2024 1

Same happens when manually putting the bypassToken into x-prerender-revalidate and calling the endpoints.

When I call /_sites/blog/id I get a cache header of REVALIDATED but the same problem persists, when deployed on vercel the site initially loads the new version but than reverts to the old one.

When I call /id I get cache header HIT and nothing happens.

EDIT:

Sometimes it seems to work. But it's very random. I just had a phase of like 20-30 minutes where it worked everytime (during the editing of the block). Now it stopped working altogether again. Nothing changed on my end

from platforms.

ahanusek avatar ahanusek commented on May 14, 2024 1

@steven-tey Thanks, now the path is proper and page is revalidated, but there is another issue in Next.js =>

vercel/next.js#38306

So now, page is revalidated, I see that rendered HTML has refreshed data, but after that endpoint with .json data (https://subdomain.domian.pl/_next/data/build_number/pl/p/dynamic_page_name.json) return stale data from cache and overwrite view (maybe is somehow connected with next-i18next locales).

from platforms.

0x6c23 avatar 0x6c23 commented on May 14, 2024 1

@steven-tey Thanks, now the path is proper and page is revalidated, but there is another issue in Next.js =>

vercel/next.js#38306

So now, page is revalidated, I see that rendered HTML has refreshed data, but after that endpoint with .json data (https://subdomain.domian.pl/_next/data/build_number/pl/p/dynamic_page_name.json) return stale data from cache and overwrite view (maybe is somehow connected with next-i18next locales).

Exactly the same issue I'm having, which I also described while creating this issue. Pages get revalidated but when opening them they get overwritten by the old version after a split second. Not using locales.

It's not only when using <Link>, it also happens when visiting the site directly.

from platforms.

ahanusek avatar ahanusek commented on May 14, 2024 1

Yep, works for me. Thanks.

from platforms.

ahanusek avatar ahanusek commented on May 14, 2024

Have similar issues when trying to revalidate page for subdomain. I'm just sending request to URL below:

https://subdomain.domain.pl/api/revalidate?secret=token&page=pagePath

api/revalidate.ts

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  // Check for secret to confirm this is a valid request
  if (req.query.secret !== process.env.REVALIDATE_API_TOKEN) {
    return res.status(401).json({ message: 'Invalid token' });
  }
  const path = String(req.query.page);
  // eslint-disable-next-line no-console
  console.log(`Revalidating page: ${path} for host ${req.headers.host}`, { header: req.headers });
  try {
    // this should be the actual path not a rewritten path
    // e.g. for "/blog/[slug]" this should be "/blog/post-1"
    await res.revalidate(`/${path}`);
    return res.json({ revalidated: true });
  } catch (err) {
    // If there was an error, Next.js will continue
    // to show the last successfully generated page
    // @ts-ignore
    // eslint-disable-next-line no-console
    console.log('Error when updating url', path, err?.message, err);
    return res.status(500).send('Error revalidating');
  }
}

And getting 404

Failed to revalidate /pagePath: Invalid response 404

But when I'm just copy this path and use together with the url https://subdomain.domain.pl, in browser it works perfectly fine, so page exists. My middleware.ts is the exactly same like in this repo. Any hint how to solve that issue?

from platforms.

steven-tey avatar steven-tey commented on May 14, 2024

Hey @0x6c23 @ahanusek! Apologies for this – this is due to the fact that Middleware doesn't execute for on-demand ISR requests, which means you have to put the exact URL that you want revalidated.

In this case, that's /_sites/${siteId}/${slug} and it has to be sent to the same hostname that you want revalidated.

I've updated the code for the revalidate() function and the part where it's called to account for this.

from platforms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.