From c69138dadab50a02fb16c1b2d33987d326251c54 Mon Sep 17 00:00:00 2001 From: nicholas Date: Thu, 5 Dec 2024 10:02:21 +0100 Subject: [PATCH] Don't define window.klarnaAsyncCallback, and always detect script load locally --- .../components/KlarnaWidget/KlarnaWidget.tsx | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx b/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx index 0d2fc60df9..db8462100c 100644 --- a/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx +++ b/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx @@ -86,29 +86,12 @@ export function KlarnaWidget({ sdkData, paymentMethodType, payButton, ...props } // Add Klarna Payments Widget SDK useEffect(() => { - /** - * If the callback has already been defined by another instance of the widget, then it will not be called again by any second instance. - * So we set a boolean telling us to initialise the widget ourselves once the script is loaded - * - * Alternatively, we *never* define the callback function; and *always* initialise the widget ourselves once the script is loaded - * (Checking with Klarna on whether defining this callback is advised/mandatory) - */ - const initOnLoad = !!window.klarnaAsyncCallback; - - window.klarnaAsyncCallback = function () { - console.log('### KlarnaWidget::klarnaWidget:: klarna async function called'); - initializeKlarnaWidget(); - }; - console.log('\n### KlarnaWidget:::: useEffect sdkData.payment_method_category=', sdkData.payment_method_category); const script = new Script(KLARNA_WIDGET_URL); void script.load()?.then(() => { console.log('### KlarnaWidget:::: useEffect script: LOADED '); - if (initOnLoad) { - console.log('### KlarnaWidget:::: manually init widget'); - initializeKlarnaWidget(); - } + initializeKlarnaWidget(); }); return () => {