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.

Middleware + Incremental Regeneration not working

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

res.unstable_revalidate(path) was working fine when using a _middleware previously, but in the last few days it wasn’t working. It would call the get request on the path just fine, but that wasn’t causing the cache to break.

I removed the _middleware.js and it all worked fine. I added the _middleware back in, and again, cache wouldn’t break.

I feel like something must have changed on vercel / next side?

( PS. I dont know if this is happening in canary release )

( PSS. Sorry about the basic issue, but I just wanted to report the issue )

Expected Behavior

Invalidate the cached page.

Link to reproduction

To Reproduce

The _middle wasn’t fancy, just making paths like this: /something-page-PAGEID and it was getting the PAGEID at the end, and doing:

const url = req.nextUrl.clone() let path = req.nextUrl.pathname let getId = path.substr(path.lastIndexOf(‘-’) + 1)

url.pathname = ${getId} return NextResponse.rewrite(url)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ijjkcommented, Jul 6, 2022

@nicosh that appears to be different as the error is failing to write the file due to the : character being used in the filename which isn’t allowed on Windows. You could resolve this by ensuring that character is not included in the path e.g. strip the port info from the currentHost value

1reaction
normdoowcommented, Jun 28, 2022

Hi, in the latest canary of Next.js of Next.js unstable_revalidate no longer triggers middleware. If you were previously rewriting in middleware to the actual path being rewritten this is no longer supported. The path passed to unstable_revalidate should be the actual path being revalidated without a rewrite needed e.g. pages/blog/[slug] res.unstable_revalidate('/blog/first')

Believe this is causing my current setup issues as I’m trying to upgraded to the latest 12.2. I use middleware to pass the specific domain for the site (allows for multiple custom domains). getStaticProps needs the domain info to function. This works great for normal views of pages. But when revalidate tries to hit getStaticPaths it now doesn’t have the domain data that it needs. Is there a different way to do this in the new version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incremental Static Regeneration - Data Fetching - Next.js
Incremental Static Regeneration (ISR) enables you to use static-generation on a per-page basis, without needing to rebuild the entire site.
Read more >
Incremental Static Regeneration with Next.js - LogRocket Blog
Next.js v9.5 introduces Incremental Static Regeneration, a hybrid version of SSG and SSR, which can regenerate static pages during runtime.
Read more >
Incremental Static Regeneration – Vercel Docs
Learn how Incremental Static Regeneration works on Vercel and how it provides better performance, increased security, and faster builds.
Read more >
Incremental Static Regeneration middleware - Reddit
Incremental Static Regeneration middleware (works with Sapper). I've made a package that should enable incremental static regeneration.
Read more >
refresh incremental static regeneration pages #30807 - GitHub
I need to trigger a page refresh as fast as possible. I want to show the user a personal page under / with...
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