Skip to content

Annotate Checkout Element presentation methods with MainThread - #14351

Open
cttsai-stripe wants to merge 1 commit into
masterfrom
cttsai/checkout-elements-main-thread
Open

Annotate Checkout Element presentation methods with MainThread#14351
cttsai-stripe wants to merge 1 commit into
masterfrom
cttsai/checkout-elements-main-thread

Conversation

@cttsai-stripe

Copy link
Copy Markdown
Contributor

Summary

Annotate Checkout Element presentation methods with @MainThread.

Motivation

PaymentElement.present() and ShippingAddressElement.present() synchronously access UI, lifecycle, Activity Result, and state-holder behavior. This makes the existing caller requirement explicit for static analysis and IDE tooling with AndroidX @MainThread, without changing runtime behavior.

Testing

  • Added tests
  • Modified tests
  • Manually verified

Existing focused PaymentElementTest and ShippingAddressElementTest passed. :paymentsheet:apiDump, :paymentsheet:apiCheck, :paymentsheet:detekt, and git diff --check passed. The push hook also reran :paymentsheet:apiCheck and :paymentsheet:detekt successfully.

Screenshots

Not applicable. This is an annotation-only API contract change with no visual or runtime UI change.

Changelog

No changelog entry. This preview API annotation documents an existing caller contract and does not change runtime behavior.

Committed and created by Codex.

Committed-By-Agent: codex
Co-authored-by: codex <noreply@openai.com>
@@ -56,18 +58,23 @@ class ShippingAddressElement @Inject internal constructor(
}

shippingAddressElementStateHolder.isPresenting = true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SavedStateHandle.set/get is @MainThread

*/
@MainThread
fun present() {
contentHelper.presentPaymentOptions()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could mark out internal implementations as well as a reminder for ourselves.

@cttsai-stripe
cttsai-stripe marked this pull request as ready for review September 2, 2026 23:05
@cttsai-stripe
cttsai-stripe requested review from a team as code owners September 2, 2026 23:05

@jaynewstrom-stripe jaynewstrom-stripe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This feels like we're leaking implementation details. Can we coroutineScope + Dispatchers.Main.immediate these instead?

@cttsai-stripe

Copy link
Copy Markdown
Contributor Author

This feels like we're leaking implementation details. Can we coroutineScope + Dispatchers.Main.immediate these instead?

IIUC, if we do that and present() is called by a background thread, the action would be posted to the main thread, and would not block the thread synchronously. It's a little bit hard to imagine what would happen if a main thread + a background thread call present() at the same time so I chose the annotation to prevent integration issues.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants