Ensure no existing parent is present before adding to container #128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 samplesCartViewModel
to trigger a delayed second present call.Repeat on main and on this branch.
Before you merge
Important
Checklist for releasing a new version
build.gradle
fileTip
See the Contributing documentation for instructions on how to publish a new version of the library.