Unverified Commit abf7da32 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix TS plugin showing warning for error file's `reset` prop (#46898)

This should be a special case of having a function as the client
boundary's prop. Fixes NEXT-732, fixes #46573.
parent 5dae98ea
...@@ -39,6 +39,8 @@ const clientBoundary = { ...@@ -39,6 +39,8 @@ const clientBoundary = {
const diagnostics: ts.Diagnostic[] = [] const diagnostics: ts.Diagnostic[] = []
const isErrorFile = /[\\/]error\.tsx?$/.test(source.fileName)
const props = node.parameters?.[0]?.name const props = node.parameters?.[0]?.name
if (props && ts.isObjectBindingPattern(props)) { if (props && ts.isObjectBindingPattern(props)) {
for (const prop of (props as ts.ObjectBindingPattern).elements) { for (const prop of (props as ts.ObjectBindingPattern).elements) {
...@@ -52,6 +54,10 @@ const clientBoundary = { ...@@ -52,6 +54,10 @@ const clientBoundary = {
ts.isFunctionOrConstructorTypeNode(typeDeclarationNode) || ts.isFunctionOrConstructorTypeNode(typeDeclarationNode) ||
ts.isClassDeclaration(typeDeclarationNode) ts.isClassDeclaration(typeDeclarationNode)
) { ) {
// 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') {
diagnostics.push({ diagnostics.push({
file: source, file: source,
category: ts.DiagnosticCategory.Warning, category: ts.DiagnosticCategory.Warning,
...@@ -64,6 +70,7 @@ const clientBoundary = { ...@@ -64,6 +70,7 @@ const clientBoundary = {
} }
} }
} }
}
return diagnostics return diagnostics
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment