From 439fc164026ff21e2eda1407a43649d5186805ec Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Mon, 3 Aug 2026 18:13:36 +0100 Subject: [PATCH] Fix sticky Square SDK rejection and clean up script element on failure A load that resolved the script tag but failed to expose window.Square (or timed out) permanently cached a rejected promise, bricking card entry until reload. sdkPromise now resets and the injected script element is removed on every failure path so later calls retry fresh. --- frontend/src/lib/square/square.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/square/square.ts b/frontend/src/lib/square/square.ts index 0a5483d..73dcf19 100644 --- a/frontend/src/lib/square/square.ts +++ b/frontend/src/lib/square/square.ts @@ -70,16 +70,28 @@ export function loadSquareSdk(): Promise { script.src = sdkUrl(); script.async = true; script.dataset.squareSdk = 'true'; + + // Non-sticky-rejection invariant: a FAILED load attempt must never poison + // the cached promise. Concurrent callers during one attempt share the same + // in-flight promise (good — single script load), but a REJECTED promise is + // cleared here so the next getSquarePayments() call starts a fresh attempt + // instead of returning the same error forever. The dead