Skip to content

Commit

Permalink
feat: support for numeric separators in revalidate config (#51438)
Browse files Browse the repository at this point in the history
### Fixing a bug

- [x] Related issues linked using `fixes #number`
- [x] Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- [ ] Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### What?

Currently, when the check on validating the type of `revalidate` is run,
we use the `Number` function to parse the value of `revalidate`, however
the `Number` function takes a
[`StringNumericLiteral`](https://tc39.es/ecma262/2023/#prod-StringNumericLiteral)
which doesn't allow the usage of the `_` separator to format your
numbers. This PR allows you to add numeric separators in the
`revalidate` export.

### Why?

When configuring the actual code, we should be allowed to use numeric
separators as it is a syntax that is supported by most runtimes.

### How?

A simple `replaceAll` call that removes all `_`s between digits.

Closes NEXT-1122
Fixes #49485

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
Yash-Singh1 and ijjk committed Jun 22, 2023
1 parent e73baa5 commit f59710e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/server/typescript/rules/config.ts
Expand Up @@ -101,7 +101,7 @@ const API_DOCS: Record<
},
link: 'https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate',
isValid: (value: string) => {
return value === 'false' || Number(value) >= 0
return value === 'false' || Number(value.replace(/_/g, '')) >= 0
},
getHint: (value: any) => {
return `Set the default revalidation time to \`${value}\` seconds.`
Expand Down
@@ -0,0 +1,5 @@
export const revalidate = 500_500

export default function Page() {
return null
}

0 comments on commit f59710e

Please sign in to comment.