Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to revalidate route of a specific locale #36092

Closed
1 task done
miguelvictor opened this issue Apr 12, 2022 · 8 comments
Closed
1 task done

Failed to revalidate route of a specific locale #36092

miguelvictor opened this issue Apr 12, 2022 · 8 comments
Labels
bug Issue was opened via the bug report template.

Comments

@miguelvictor
Copy link

miguelvictor commented Apr 12, 2022

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Binaries:
  Node: 14.19.0
  npm: 6.14.16
  Yarn: 1.22.18
  pnpm: 6.32.6
Relevant packages:
  next: 12.1.5-canary.6
  react: 18.0.0
  react-dom: 18.0.0

What browser are you using? (if relevant)

Brave Version 1.37.111 Chromium: 100.0.4896.79 (Official Build) (x86_64)

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

I have a page with the same template but different content depending on the locale. My locale configuration looks like this

i18n: {
  locales: ["default", "se", "no", "fi"],
  defaultLocale: "default",
  localeDetection: false,
},

I want to use the unstable_revalidate API to regenerate a specific page for a specific locale but when i call it with the page route (e.g., unstable_revalidate('/se/interview')) it results into an error as shown below:

Error: Failed to revalidate /se/interview: Invalid response undefined
    at unstable_revalidate (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/api-utils/node.js:238:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async handler (/Users/miguelvictor/DFProjects/sdworx/.next/server/pages/api/webhook-ondemand-isr.js:71:9)
    at async Object.apiResolver (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/api-utils/node.js:184:9)
    at async NextNodeServer.runApi (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/next-server.js:397:9)
    at async Object.fn (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/base-server.js:473:37)
    at async Router.execute (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/router.js:233:32)
    at async NextNodeServer.run (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/base-server.js:583:29)
    at async NextNodeServer.handleRequest (/Users/miguelvictor/DFProjects/sdworx/node_modules/next/dist/server/base-server.js:298:20)

For more context (not sure if this helps), i am returning { notFound: true } in my getStaticProps if the locale is default.

Expected Behavior

It should regenerate the page of that specific locale without any errors.

To Reproduce

Pretty much the same with the example

try {
    await res.unstable_revalidate('/se/interview')
    return res.json({ revalidated: true })
} catch (err) {
    console.error(err)
    return res.status(500).send("Error revalidating")
}

Update:

  • I'm not using any middlewares in this project
@miguelvictor miguelvictor added the bug Issue was opened via the bug report template. label Apr 12, 2022
@Ashwinvalento
Copy link

If you are using middleware to internally rewite the pages, then the revalidation link will also get rewritten. I spent a lot of time trying to figure this. You can check the header for x-prerender-revalidate and return without rewriting.

if (
    url.pathname.includes(".") || // exclude all files in the public folder
    url.pathname.startsWith("/api") || // exclude all API routes
    req.headers.has("x-prerender-revalidate") // exclude the revalidate request
  ) {
    return undefined;
  }

This worked for me.

@miguelvictor
Copy link
Author

Oh. I'm not using any middlewares btw

@ipatate
Copy link

ipatate commented Apr 14, 2022

yep same problem and i fix with x-prerender-revalidate in middleware

@vnugent
Copy link

vnugent commented May 11, 2022

I'm having the same issue as the origin poster. Though it only happens on Vercel.com, not locally.

  • I verified that the issue exists in Next.js canary release (12.1.7-canary.3)
  • I don't have any middlewares
 # yarn next info

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64
    Binaries:
      Node: 16.11.0
      npm: 8.0.0
      Yarn: 1.19.0
      pnpm: N/A
    Relevant packages:
      next: 12.1.7-canary.3
      react: 18.0.0
      react-dom: 18.0.0

My revalidate.js is identical to the example in the documentation with an extra debugging console.log(err). Here's the error on Vercel.com

[GET] /api/revalidate?token=<redact>
Function Status:   500
Edge Status:   500
Duration:   1330.05 ms
Init Duration:   560.89 ms
Memory Used:   89 MB
ID:   cdg1::iad1::jq794-1652263407643-64d2be3b34fa
User Agent:    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36

info  - Loaded env from /var/task/.env
Error: Failed to revalidate /u/<redacted>: Invalid response 500
    at unstable_revalidate (/var/task/node_modules/next/dist/server/api-utils/node.js:243:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async handler (/var/task/.next/server/pages/api/revalidate.js:27:5)
    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:185:9)
    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:402:9)
    at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:498:37)
    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:226:36)
    at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:636:29)
    at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:323:20)
    at async Server.module.exports (/var/task/___next_launcher.js:29:9)

@ijjk
Copy link
Member

ijjk commented May 11, 2022

@vnugent are you not seeing a separate log that shows the reason for the 500 error? It should be logged at the page being revalidated

@vnugent
Copy link

vnugent commented May 11, 2022

@vnugent are you not seeing a separate log that shows the reason for the 500 error? It should be logged at the page being revalidated

@ijjk No errors. According to the log, the page being validated ran fine (status 200). We're not swallowing exceptions in getStaticProps(). So if there are any they should show up. Maybe I should open a support ticket?

*edit: I've looked at the log again. The target page was never called. Something must have caused the exception before the page was called.

The page component

export async function getStaticPaths (): Promise<any> {
  return {
    paths: [{ params: { uid: '<redacted>' } }],
    fallback: true
  }
}

export const getStaticProps: GetStaticProps<UserHomeProps> = async ({ params }) => {
 ...
  return {
    props: data
  }
}

...

@ijjk
Copy link
Member

ijjk commented Jul 11, 2022

Hi, this has been updated in the latest version of Next.js v12.2.2 and middleware does not execute for On-Demand ISR requests which seems to have been causing the issues here. Please update and give it a try!

If you are still encountering issues with this please open a fresh issue with a reproduction and we can investigate further!

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

5 participants