-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[url_launcher] When not fully loaded, clicking close causes the callback to not be triggered correctly. #8582
base: main
Are you sure you want to change the base?
Conversation
…allback to not be triggered correctly.
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
This comment was marked as resolved.
This comment was marked as resolved.
This should be testable with native unit tests that directly drive calls to the |
@@ -12,6 +12,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { | |||
|
|||
private let completion: OpenInSafariCompletionHandler | |||
private let url: URL | |||
private var isLoadCompleted: Bool? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nullable boolean should only be used when there are three conceptually different states. The code in this PR only actually recognizes two.
This comment was marked as resolved.
This comment was marked as resolved.
That's a Dart unit test, which does not run the code you changed; native unit tests are here, as described in our contributor docs. |
(Marking as Draft pending the test, so it doesn't show up in review queues.) |
Oh, my God. I forgot. Thanks for the reminder. I’ve added the test. If you have time, you can continue review |
} | ||
|
||
/// Called when the user finishes using the Safari view controller. | ||
/// | ||
/// - Parameter controller: The Safari view controller. | ||
func safariViewControllerDidFinish(_ controller: SFSafariViewController) { | ||
if !isLoadCompleted { | ||
completion(.success(.failedToLoad)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .failedToLoad
the correct result here? Or we should add a new InAppLoadResult.dismissed
result?
If this is the correct result, should we update this comment to indicate this case can happen if the user dismisses the Safari view before the initial load completes?
packages/packages/url_launcher/url_launcher_ios/pigeons/messages.dart
Lines 30 to 31 in fd53793
/// The URL did not load successfully. | |
failedToLoad, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I did consider adding a new InAppLoadResult to describe the close action, but it seems it could lead to confusion among developers. This is because, currently, after a successful load, clicking the close button does not trigger any callback.
Additionally, when the user clicks close before the loading is complete, triggering the failedToLoad callback seems reasonable in a broader sense, as the interruption of the loading process can be considered a loading failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the correct result, should we update this comment to indicate this case can happen if the user dismisses the Safari view before the initial load completes?
Do you think it’s possible to modify the comment like this:
// The URL did not load successfully (or close the SFSafariViewController earlier)
packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift
Show resolved
Hide resolved
packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift
Show resolved
Hide resolved
@loic-sharma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks for the contribution!
@stuartmorgan |
When SFSafariViewController is loading a webpage, if the close button is clicked during the loading process, it can prevent the callback from being triggered correctly.
List which issues are fixed by this PR. You must list at least one issue.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].CHANGELOG.md
to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].///
).