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,14 +54,19 @@ const clientBoundary = { ...@@ -52,14 +54,19 @@ const clientBoundary = {
ts.isFunctionOrConstructorTypeNode(typeDeclarationNode) || ts.isFunctionOrConstructorTypeNode(typeDeclarationNode) ||
ts.isClassDeclaration(typeDeclarationNode) ts.isClassDeclaration(typeDeclarationNode)
) { ) {
diagnostics.push({ // There's a special case for the error file that the `reset` prop is allowed
file: source, // to be a function:
category: ts.DiagnosticCategory.Warning, // https://github.com/vercel/next.js/issues/46573
code: NEXT_TS_ERRORS.INVALID_CLIENT_ENTRY_PROP, if (!isErrorFile || propName !== 'reset') {
messageText: `Props must be serializable for components in the "use client" entry file, "${propName}" is invalid.`, diagnostics.push({
start: prop.getStart(), file: source,
length: prop.getWidth(), category: ts.DiagnosticCategory.Warning,
}) code: NEXT_TS_ERRORS.INVALID_CLIENT_ENTRY_PROP,
messageText: `Props must be serializable for components in the "use client" entry file, "${propName}" is invalid.`,
start: prop.getStart(),
length: prop.getWidth(),
})
}
} }
} }
} }
......
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