Skip to content

[Kotlin]: Prevent stacked sheet presentations - #600

Draft
kieran-osgood-shopify wants to merge 1 commit into
mainfrom
android-duplicate-checkout-crash
Draft

[Kotlin]: Prevent stacked sheet presentations#600
kieran-osgood-shopify wants to merge 1 commit into
mainfrom
android-duplicate-checkout-crash

Conversation

@kieran-osgood-shopify

@kieran-osgood-shopify kieran-osgood-shopify commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What changes are you making?

spamming the checkout button can open multiple checkouts at once

Screen Recording 2026-08-06 at 12.14.21.mov (uploaded via Graphite)

How to test

spam the button and only 1 checkout will open, the getting stuck height is fixed up stack in 601


Before you merge

Important

  • I've added tests to support my implementation
  • I have read and agree with the Contribution Guidelines
  • I have read and agree with the Code of Conduct
  • I've updated the relevant platform README (platforms/swift/README.md and/or platforms/android/README.md)

Releasing a new Swift version?
  • I have bumped the version in ShopifyCheckoutKit.podspec
  • I have bumped the version in platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift
  • I have updated the SwiftPM/CocoaPods version snippets in platforms/swift/README.md (major version only)
Releasing a new Embedded Checkout Protocol version?
  • I have bumped embeddedCheckoutProtocolAndroid in platforms/android/gradle/libs.versions.toml
  • I have updated protocol/languages/kotlin/embedded-checkout-protocol/api/embedded-checkout-protocol.api if the public API changed
Releasing a new Android version?
  • I have bumped checkoutKitAndroid in platforms/android/gradle/libs.versions.toml
  • I have updated the Gradle/Maven version snippets in platforms/android/README.md

Tip

See the Contributing documentation for the full release process per platform.

### TLDR

`present` built a new `CheckoutBottomSheet` on every call, so N taps on a checkout button stacked N dialog windows. A device capture showed 73 `present` calls producing 73 sheets, two of them only 153 ms apart.

### What

`ShopifyCheckoutKit` now tracks the live presentation. A second `present` for the same activity logs a warning and returns the existing `CheckoutHandle` instead of building another sheet. A stored sheet that is no longer showing counts as stale, so the next `present` proceeds normally.

`CheckoutBottomSheet` gains an internal `onDismissFinalized` callback, invoked in `finishDismiss` above the `isShowing` guard, so every dismissal path clears the slot: buyer dismissal, gesture dismissal, programmatic `dismiss`, lifecycle teardown, and `closeCheckoutWithError`.

That callback also removes the per-presentation `DefaultLifecycleObserver`. Before this change the observer was removed only when `start()` failed, so each successful presentation leaked one observer holding a dead sheet.

No public API change. Both new members are private, or internal on an internal class, so `lib/api/lib.api` does not move.

### How to test

Add an item to the cart in the Kotlin sample, then tap Checkout many times quickly.

| | Before | After |
| --- | --- | --- |
| Sheets shown per burst | 5 | 1 |
| Leaked sheet windows after closing | 4 | 0 |

Leaked sheet windows are `androiddemo` entries in `dumpsys window windows` with `ty=APPLICATION gr=BOTTOM`. Before this change two surfaceless sheet windows survived every close, and one of them still held `mCurrentFocus`. The app then drew nothing, without crashing.

`ShopifyCheckoutKitTest.kt` covers the refusal, the returned handle identity, presenting again after a dismissal, and the observer count returning to its starting value.

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot added the #gsd:50662 Rebase Checkout Kit on UCP label Aug 6, 2026
@kieran-osgood-shopify kieran-osgood-shopify changed the title fix(android): ignore a second checkout presentation while one is showing [Kotlin]: Prevent duplicate sheet presentations Aug 7, 2026
@kieran-osgood-shopify kieran-osgood-shopify changed the title [Kotlin]: Prevent duplicate sheet presentations [Kotlin]: Prevent stacked sheet presentations Aug 7, 2026
private val activity: ComponentActivity,
val handle: CheckoutHandle,
) {
fun isShowingFor(context: ComponentActivity): Boolean = activity === context && sheet.isShowing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering here if the activity === context `check is needed?

Could we still stack if presenting from a separate activity? Is that problematic?

fun isShowing(): Boolean = sheet.isShowing

or directly without the function

val alreadyPresented = livePresentation?.takeIf { it.sheet.isShowing }

Maybe with docs to say only one checkout can be presented per SDK process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#gsd:50662 Rebase Checkout Kit on UCP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants