Skip to content

Ensure no existing parent is present before adding to container #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

kiftio
Copy link
Contributor

@kiftio kiftio commented Sep 12, 2024

What changes are you making?

CLOSES #127

When preloading is enabled and we fetch the checkout web view from the cache, there are some scenarios where we try to add the fetched view to a parent container when it already has a parent (causing an IllegalStateException).

This can be reproduced by enabling preloading, then calling present() twice without dismissing the modal (there also may be other cases).

This PR looks to ensure the webView has no existing parent before we add it to its container.


Note: When we remove checkout web views from their container, we also look to ensure it's destroyed if we think it will not be used again, to avoid memory leaks. We don't want to do this destroy/cleanup in this case, as the view will be added to the view hierarchy shortly after removing the existing parent and therefore must not be destroyed.


How to test

Add the following below ShopifyCheckoutSheetKit.present(url, activity, eventProcessor) in the MobileBuyIntegration samples CartViewModel to trigger a delayed second present call.

Handler(Looper.getMainLooper()).postDelayed({
     ShopifyCheckoutSheetKit.present(url, activity, eventProcessor)
}, 500)

Repeat on main and on this branch.

Before you merge

Important


Checklist for releasing a new version

Tip

See the Contributing documentation for instructions on how to publish a new version of the library.

@kiftio kiftio force-pushed the dk/ensure-view-has-no-existing-parent branch from 077d15c to 4650ad0 Compare September 25, 2024 10:15
@kiftio kiftio force-pushed the dk/ensure-view-has-no-existing-parent branch from 4650ad0 to 8687c19 Compare September 25, 2024 10:16
@kiftio kiftio marked this pull request as ready for review September 25, 2024 10:23
@kiftio kiftio requested a review from a team as a code owner September 25, 2024 10:23
Copy link
Contributor

@markmur markmur left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@kiftio kiftio merged commit 41f5a58 into main Oct 2, 2024
4 checks passed
@kiftio kiftio deleted the dk/ensure-view-has-no-existing-parent branch October 2, 2024 14:15
@kiftio kiftio mentioned this pull request Oct 28, 2024
7 tasks
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.

addWebViewToContainer throws IllegalStateException
2 participants