Skip to content

[Android] Scope preloads to activity - #460

Draft
kiftio wants to merge 1 commit into
mainfrom
07-14-scope_preloads_to_activity
Draft

[Android] Scope preloads to activity#460
kiftio wants to merge 1 commit into
mainfrom
07-14-scope_preloads_to_activity

Conversation

@kiftio

@kiftio kiftio commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What changes are you making?

A preloaded CheckoutWebView is now only reused when the Context passed to checkoutViewFor resolves to the same Activity instance that was used during ShopifyCheckoutKit.preload. Previously, the cache matched solely on URL, meaning a preloaded view could be handed to a different Activity, leading to potential context mismatches and memory leaks.

The PreloadCache now stores the Activity alongside the cached entry and performs a referential equality check (===) on take. A new findActivity() extension unwraps ContextWrapper chains to locate the backing Activity, so callers passing wrapped contexts (e.g. theme wrappers) continue to benefit from the preload cache. If the resolved Activity differs from the one used during preload, or if the context has no backing Activity at all, the cached view is discarded and checkout loads normally.

How to test

  1. Preload a checkout URL from ActivityA, then present it from the same ActivityA — the cached WebView should be reused.
  2. Preload a checkout URL from ActivityA, then present it from a different ActivityB — the cached WebView should be discarded and a fresh load should occur.
  3. Preload a checkout URL, then present it using a ContextWrapper wrapping the same activity — the cached WebView should still be reused.
  4. Preload a checkout URL, then present it using an application context (no backing Activity) — the cached WebView should be discarded.
  5. Run the new unit tests: checkout view consumes cached preload when context wraps preload activity, checkout view discards cached preload created by a different activity, and checkout view discards cached preload when context has no activity.

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.

@github-actions github-actions Bot added the #gsd:50662 Rebase Checkout Kit on UCP label Jul 14, 2026

kiftio commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 5143f47 to 371913c Compare July 14, 2026 13:40
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch from e57bb1d to 57b2d1f Compare July 14, 2026 13:40
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 371913c to 6a739e7 Compare July 14, 2026 14:44
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch from 57b2d1f to 020fa96 Compare July 14, 2026 14:44
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 6a739e7 to f955794 Compare July 14, 2026 15:07
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch 2 times, most recently from c9f2ff4 to 582e6c7 Compare July 14, 2026 15:35
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from f955794 to 39b0282 Compare July 14, 2026 15:35
@kiftio kiftio changed the title scope_preloads_to_activity [Android] Scope preloads to activity Jul 15, 2026
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch 2 times, most recently from 82a6c36 to d89b765 Compare July 15, 2026 08:20
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch from 582e6c7 to 88c5f9e Compare July 15, 2026 08:20
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from d89b765 to 25dff17 Compare July 15, 2026 12:28
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch from 88c5f9e to d00a27b Compare July 15, 2026 12:28
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 25dff17 to 221cab6 Compare July 16, 2026 09:32
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch 2 times, most recently from 10c41e2 to 96b3980 Compare July 16, 2026 09:42
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch 2 times, most recently from d87d947 to 555da85 Compare July 16, 2026 10:23
@kiftio
kiftio force-pushed the 07-14-dogfood_checkoutview_in_sample branch from 96b3980 to 67639e6 Compare July 16, 2026 10:23
@kiftio
kiftio changed the base branch from 07-14-dogfood_checkoutview_in_sample to graphite-base/460 July 16, 2026 10:33
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 555da85 to 5a90626 Compare July 16, 2026 10:41
@kiftio
kiftio force-pushed the graphite-base/460 branch from 67639e6 to 8e2c198 Compare July 16, 2026 10:41
@graphite-app
graphite-app Bot changed the base branch from graphite-base/460 to main July 16, 2026 10:42
@kiftio
kiftio force-pushed the 07-14-scope_preloads_to_activity branch from 5a90626 to dc9b0a1 Compare July 16, 2026 10:42
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.

1 participant