From 37f08390794c35bd02cd1256d609c4a53977bd32 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Tue, 8 Oct 2024 23:50:03 -0400 Subject: [PATCH] Hacky workaround for double firing of pull request --- src/components/Pacs/PacsController.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Pacs/PacsController.tsx b/src/components/Pacs/PacsController.tsx index 705858005..f4ec534d2 100644 --- a/src/components/Pacs/PacsController.tsx +++ b/src/components/Pacs/PacsController.tsx @@ -495,6 +495,8 @@ const PacsController: React.FC = ({ const onRetrieve = React.useCallback( (service: string, query: PACSqueryCore) => { expandStudiesFor(service, query); + // N.B.: immer bug here + // https://github.com/immerjs/use-immer/issues/139 setPullRequests((draft) => { // indicate that the user requests for something to be retrieved. draft.push({ @@ -594,10 +596,19 @@ const PacsController: React.FC = ({ updatePullRequestState(service, query, { state: RequestState.REQUESTED }), }); + // FIXME idk why the effect is firing twice... + const badWorkaroundToPreventDuplicatePull = React.useRef< + Set + >(new Set()); + React.useEffect(() => { pullRequests .filter(shouldSendPullRequest) - .forEach((pr) => pullFromPacs.mutate(pr)); + .filter((pr) => !badWorkaroundToPreventDuplicatePull.current.has(pr)) + .forEach((pr) => { + badWorkaroundToPreventDuplicatePull.current.add(pr); + pullFromPacs.mutate(pr); + }); }, [pullRequests, shouldSendPullRequest]); // ========================================