From 025dc64bd09b09c144b424820e2f0c8b60c03423 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 15 Apr 2024 16:42:52 +0700 Subject: [PATCH] fix jest test --- src/pages/home/report/UserTypingEventListener.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 5aa9a0371840..45e56cfe7ff1 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -29,7 +29,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe if (route?.params?.reportID !== reportID) { return; } - + let interactionTask: ReturnType | null = null; if (isFocused) { // Ensures subscription event succeeds when the report/workspace room is created optimistically. // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming @@ -38,7 +38,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { - InteractionManager.runAfterInteractions(() => { + interactionTask = InteractionManager.runAfterInteractions(() => { Report.subscribeToReportTypingEvents(reportID); didSubscribeToReportTypingEvents.current = true; }); @@ -53,6 +53,12 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe }); } } + return () => { + if (!interactionTask) { + return; + } + interactionTask.cancel(); + }; }, [isFocused, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); return null;