Skip to content

Commit

Permalink
clear timeout after initialised
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesgodi committed Aug 6, 2024
1 parent 258f14b commit afa8ce6
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface LoadingHandoverProps {
export function CheckoutAppIframe() {
const { t } = useTranslation();
const iframeRef = useRef<HTMLIFrameElement>(null);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
const [loadingError, setLoadingError] = useState<boolean>(false);
const [initialised, setInitialised] = useState<boolean>(false);
const [
Expand Down Expand Up @@ -76,20 +77,21 @@ export function CheckoutAppIframe() {
// check if the widget has been initialised
if (event.detail.type === CheckoutEventType.INITIALISED) {
setInitialised(true);
clearTimeout(timeoutRef.current!);
}
});

// check if loaded correctly
const timeoutId = setTimeout(() => {
timeoutRef.current = setTimeout(() => {
if (!initialised) {
setLoadingError(true);
clearTimeout(timeoutId);
clearTimeout(timeoutRef.current!);
}
}, IFRAME_INIT_TIMEOUT_MS);

return () => {
postMessageHandler.destroy();
clearTimeout(timeoutId);
clearTimeout(timeoutRef.current!);
};
}, [postMessageHandler]);

Expand Down

0 comments on commit afa8ce6

Please sign in to comment.