From 235f36b4915177da4b2a7a438cc2a29b79a376c5 Mon Sep 17 00:00:00 2001 From: Rasmy Nguyen Date: Tue, 10 Sep 2024 08:25:05 +0900 Subject: [PATCH] fix: verify delayed prompt can still be displayed before showing (#1344) This PR adds a check to delayed prompts to ensure readers still match the segment before unhiding. --- src/view/segmentation.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/view/segmentation.js b/src/view/segmentation.js index 69b72a3c..3a372508 100644 --- a/src/view/segmentation.js +++ b/src/view/segmentation.js @@ -54,6 +54,12 @@ export const handleSegmentation = prompts => { setTimeout( unhide, delay ); } const unhide = () => { + // Conditions may have changed since the prompt was delayed. + // Verify whether the prompt can still be displayed. + const updatedMatchingSegment = getBestPrioritySegment( segments ); + if ( ! shouldPromptBeDisplayed( prompt, updatedMatchingSegment, ras, override ) ) { + return; + } // Prioritize RAS overlays. If there are any reinitiate the delay and return early. if ( ras?.overlays && ras.overlays.get().length ) { delayPrompt();