-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression in TS plugin: allow
reset
prop in error files
The TypeScript error `Props must be serializable for components in the "use client" entry file, "reset" is invalid.` for the `reset` prop in `error.tsx` and `global-error.tsx` was fixed in #46898 and #48756, respectively. However, a regression of the fix was accidentally introduced in #67211. This PR restores the previous behavior and adds fixtures for manual testing. (Since the Next.js TS plugin only applies to VSCode, manual testing in VSCode is required. See `test/development/typescript-plugin/README.md` for details.)
- Loading branch information
1 parent
a5f30e6
commit 706cdfd
Showing
4 changed files
with
75 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
'use client' | ||
|
||
class MyClass {} | ||
|
||
export function ClientComponent({ | ||
unknownAction, | ||
//^^^^^^^^^^^ fine because it looks like an action | ||
unknown, | ||
//^^^^^ "Error(TS71007): Props must be serializable for components in the "use client" entry file. "unknown" is a function that's not a Server Action. Rename "unknown" either to "action" or have its name end with "Action" e.g. "unknownAction" to indicate it is a Server Action.ts(71007) | ||
//^^^^^ "Error(TS71007): Props must be serializable for components in the "use client" entry file. "unknown" is a function that's not a Server Action. Rename "unknown" either to "action" or have its name end with "Action" e.g. "unknownAction" to indicate it is a Server Action. ts(71007) | ||
foo, | ||
//^ "Error(TS71007): Props must be serializable for components in the "use client" entry file, "foo" is invalid.ts(71007) | ||
bar, | ||
//^ "Error(TS71007): Props must be serializable for components in the "use client" entry file, "bar" is invalid.ts(71007) | ||
}: { | ||
unknownAction: () => void | ||
unknown: () => void | ||
foo: new () => Error | ||
bar: MyClass | ||
}) { | ||
console.log({ unknown, unknownAction }) | ||
console.log({ unknown, unknownAction, foo, bar }) | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client' | ||
|
||
import { useEffect } from 'react' | ||
|
||
export default function Error({ | ||
error, | ||
reset, | ||
//^^^ fine because it's the special reset prop in an error file | ||
}: { | ||
error: Error & { digest?: string } | ||
reset: () => void | ||
}) { | ||
useEffect(() => { | ||
console.error(error) | ||
}, [error]) | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<button onClick={() => reset()}>Try again</button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use client' | ||
|
||
export default function GlobalError({ | ||
error, | ||
reset, | ||
//^^^ fine because it's the special reset prop in a global-error file | ||
}: { | ||
error: Error & { digest?: string } | ||
reset: () => void | ||
}) { | ||
return ( | ||
<html> | ||
<body> | ||
<h2>Something went wrong!</h2> | ||
<button onClick={() => reset()}>Try again</button> | ||
</body> | ||
</html> | ||
) | ||
} |