Skip to content

Commit 6a5748e

Browse files
authored
Fix tool feedback survey (#945)
fix(tool-feedback): guard setSurveyData with mounted ref instead of unsubscribing Unsubscribing posthog.onFeatureFlags on cleanup removed the handler before it could fire, leaving surveyData null and the page stuck at "Loading...". Keep the handler registered (so it fires when flags load) and gate the setState call on a mounted flag to avoid stale updates after unmount.
1 parent 404be69 commit 6a5748e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

app/_components/tool-feedback-survey.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ export const ToolFeedbackSurvey = () => {
1111
const [completed, setCompleted] = useState(false);
1212

1313
useEffect(() => {
14-
const unsubscribe = posthog.onFeatureFlags(() => {
14+
let mounted = true;
15+
posthog.onFeatureFlags(() => {
1516
posthog.getSurveys((surveys) => {
17+
if (!mounted) {
18+
return;
19+
}
1620
const survey = surveys.find((s) => s.id === SURVEY_ID);
1721
if (survey) {
1822
setSurveyData(survey);
1923
}
2024
}, true);
2125
});
22-
return unsubscribe;
26+
return () => {
27+
mounted = false;
28+
};
2329
}, []);
2430

2531
const handleSurveyComplete = () => {

0 commit comments

Comments
 (0)