From 06700235dd4752aecc8c98d2c6c19d831ad4756b Mon Sep 17 00:00:00 2001 From: Sreetam Das Date: Sun, 23 Apr 2023 23:34:20 +0530 Subject: [PATCH] fix: TS plugin showing warning for `global-error` file's `reset` prop (#48756) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TS plugin incorrectly gives a warning for the `reset` prop in the `global-error.tsx` file. This was previously reported and fixed for the `error.tsx` file. - https://github.com/vercel/next.js/issues/46573 - https://github.com/vercel/next.js/pull/46898 --- You can see a reproduction on [CodeSandbox](https://codesandbox.io/p/sandbox/summer-dawn-b0gydg?file=%2Fapp%2Flayout.tsx&selection=%5B%7B%22endColumn%22%3A16%2C%22endLineNumber%22%3A18%2C%22startColumn%22%3A16%2C%22startLineNumber%22%3A18%7D%5D) — `global-error.tsx`'s `reset` prop has the following warning: ``` Props must be serializable for components in the "use client" entry file, "reset" is invalid. ts(71007) ``` I haven't filed an issue for this yet since this was a simple enough fix, but happy to create one if needed :) --- packages/next/src/server/typescript/rules/client-boundary.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/server/typescript/rules/client-boundary.ts b/packages/next/src/server/typescript/rules/client-boundary.ts index f6ce8bbab4742..7e134d4b2cc99 100644 --- a/packages/next/src/server/typescript/rules/client-boundary.ts +++ b/packages/next/src/server/typescript/rules/client-boundary.ts @@ -40,6 +40,7 @@ const clientBoundary = { const diagnostics: ts.Diagnostic[] = [] const isErrorFile = /[\\/]error\.tsx?$/.test(source.fileName) + const isGlobalErrorFile = /[\\/]global-error\.tsx?$/.test(source.fileName) const props = node.parameters?.[0]?.name if (props && ts.isObjectBindingPattern(props)) { @@ -57,7 +58,7 @@ const clientBoundary = { // There's a special case for the error file that the `reset` prop is allowed // to be a function: // https://github.com/vercel/next.js/issues/46573 - if (!isErrorFile || propName !== 'reset') { + if (!(isErrorFile || isGlobalErrorFile) || propName !== 'reset') { diagnostics.push({ file: source, category: ts.DiagnosticCategory.Warning,