From f59710e907c01ab57730eec0ae571dfff80f49fa Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Wed, 21 Jun 2023 17:22:29 -0700 Subject: [PATCH] feat: support for numeric separators in revalidate config (#51438) ### 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 --- packages/next/src/server/typescript/rules/config.ts | 2 +- .../type-checks/config/revalidate-with-seperators/page.tsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/integration/app-types/src/app/type-checks/config/revalidate-with-seperators/page.tsx diff --git a/packages/next/src/server/typescript/rules/config.ts b/packages/next/src/server/typescript/rules/config.ts index 06f9f6221de6..bc38ac3076fd 100644 --- a/packages/next/src/server/typescript/rules/config.ts +++ b/packages/next/src/server/typescript/rules/config.ts @@ -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.` diff --git a/test/integration/app-types/src/app/type-checks/config/revalidate-with-seperators/page.tsx b/test/integration/app-types/src/app/type-checks/config/revalidate-with-seperators/page.tsx new file mode 100644 index 000000000000..905909c4a9d8 --- /dev/null +++ b/test/integration/app-types/src/app/type-checks/config/revalidate-with-seperators/page.tsx @@ -0,0 +1,5 @@ +export const revalidate = 500_500 + +export default function Page() { + return null +}