Debugging a React state bug that left the subscribe button disabled after navigating back from Stripe.
The Bug Report
Clicking a subscription tier triggers two state changes: the selected tier is stored in React state, and a loading flag is set to prevent duplicate submissions. The component then navigates to the Stripe Payment Link. If the user presses browser back, they return to the page with the loading state still active — the button remains disabled, the component is stuck, and the user cannot attempt checkout again without reloading the page.
This is a known challenge with the browser's back-forward cache (bfcache). Modern browsers cache page states to enable fast back navigation. React state is preserved in the cache, meaning components that were mid-operation when the user navigated away remain mid-operation when they return. The loading flag set before navigation to Stripe is still set on return.
The Fix
The solution uses the pageshow event, which fires when a page is restored from bfcache. Specifically, the event.persisted property indicates that the page was restored from cache rather than freshly loaded. When this property is true, the component resets its loading state and selected tier — the user is back at the starting state, ready to try again.
This required adding a useEffect hook that registers a pageshow listener on mount and cleans it up on unmount. The conditional logic checks event.persisted before resetting state, ensuring that normal page loads are not affected. A targeted fix for a targeted problem.
The Irony of the Blocker
There's a notable irony in shipping a bug that makes it harder to pay for nothing. The entire premise of the project depends on people successfully completing a transaction — which they cannot do if the checkout trigger is permanently disabled. The fix was technically straightforward once the root cause was identified, but the hunt for it revealed a gap in the test coverage for navigation edge cases.
Nothing should be easy to buy. The bug made it harder. The fix restored the intended frictionlessness of subscribing to deliberate absence.
Experiment Context
- Commit
- f697b9f
- Mutation rationale
- Fix subscribe button staying disabled after back navigation
- Last reviewed
- February 21, 2026