@@ -9,7 +9,7 @@ import { parseWithZod } from "@conform-to/zod";
99import { InformationCircleIcon , ArrowUpCircleIcon } from "@heroicons/react/20/solid" ;
1010import { EnvelopeIcon , ShieldCheckIcon } from "@heroicons/react/24/solid" ;
1111import { Form , useActionData , useLocation , useNavigation , useSearchParams } from "@remix-run/react" ;
12- import { type ReactNode , useEffect , useState } from "react" ;
12+ import { type ReactNode , useEffect , useRef , useState } from "react" ;
1313import { type FeedbackType , feedbackTypes , schema } from "~/routes/resources.feedback" ;
1414import { Button } from "./primitives/Buttons" ;
1515import { Dialog , DialogContent , DialogHeader , DialogTrigger } from "./primitives/Dialog" ;
@@ -85,6 +85,18 @@ export function Feedback({
8585 }
8686 } , [ searchParams ] ) ;
8787
88+ // Reset the topic to the default once the dialog closes, so reopening always starts fresh. The
89+ // dialog is now persistently mounted (hosted outside the popover), so without this it would keep
90+ // the previously chosen topic selected and risk filing feedback under the wrong category. Keyed
91+ // on the close transition (not just `!open`) so the ?feedbackPanel= open path isn't clobbered.
92+ const wasOpen = useRef ( open ) ;
93+ useEffect ( ( ) => {
94+ if ( wasOpen . current && ! open ) {
95+ setType ( defaultValue ) ;
96+ }
97+ wasOpen . current = open ;
98+ } , [ open , defaultValue ] ) ;
99+
88100 const handleOpenChange = ( value : boolean ) => {
89101 setOpen ( value ) ;
90102 onOpenChange ?.( value ) ;
0 commit comments