diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/Errors/error-overlay-footer/error-feedback/error-feedback.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/Errors/error-overlay-footer/error-feedback/error-feedback.tsx index 1faa306e75717..4562ee545ea6b 100644 --- a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/Errors/error-overlay-footer/error-feedback/error-feedback.tsx +++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/Errors/error-overlay-footer/error-feedback/error-feedback.tsx @@ -7,13 +7,18 @@ interface ErrorFeedbackProps { errorCode: string } export function ErrorFeedback({ errorCode }: ErrorFeedbackProps) { - const [voted, setVoted] = useState(null) - const hasVoted = voted !== null + const [votedMap, setVotedMap] = useState>({}) + const voted = votedMap[errorCode] + const hasVoted = voted !== undefined const handleFeedback = useCallback( async (wasHelpful: boolean) => { // Optimistically set feedback state without loading/error states to keep implementation simple - setVoted(wasHelpful) + setVotedMap((prev) => ({ + ...prev, + [errorCode]: wasHelpful, + })) + try { const response = await fetch( `${process.env.__NEXT_ROUTER_BASEPATH || ''}/__nextjs_error_feedback?${new URLSearchParams( @@ -36,35 +41,33 @@ export function ErrorFeedback({ errorCode }: ErrorFeedbackProps) { ) return ( - <> -
- {hasVoted ? ( -

- Thanks for your feedback! -

- ) : ( - <> -

Was this helpful?

- - - - )} -
- +
+ {hasVoted ? ( +

+ Thanks for your feedback! +

+ ) : ( + <> +

Was this helpful?

+ + + + )} +
) } diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.stories.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.stories.tsx index a8f1009825941..04490fa815117 100644 --- a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.stories.tsx +++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.stories.tsx @@ -22,7 +22,9 @@ export const Default: Story = { id: 1, event: { type: ACTION_UNHANDLED_ERROR, - reason: new Error('First error message'), + reason: Object.assign(new Error('First error message'), { + __NEXT_ERROR_CODE: 'E001', + }), componentStackFrames: [ { file: 'app/page.tsx', @@ -47,7 +49,9 @@ export const Default: Story = { id: 2, event: { type: ACTION_UNHANDLED_ERROR, - reason: new Error('Second error message'), + reason: Object.assign(new Error('Second error message'), { + __NEXT_ERROR_CODE: 'E002', + }), frames: [], }, }, @@ -55,7 +59,9 @@ export const Default: Story = { id: 3, event: { type: ACTION_UNHANDLED_ERROR, - reason: new Error('Third error message'), + reason: Object.assign(new Error('Third error message'), { + __NEXT_ERROR_CODE: 'E003', + }), frames: [], }, }, @@ -63,7 +69,9 @@ export const Default: Story = { id: 4, event: { type: ACTION_UNHANDLED_ERROR, - reason: new Error('Fourth error message'), + reason: Object.assign(new Error('Fourth error message'), { + __NEXT_ERROR_CODE: 'E004', + }), frames: [], }, },