[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567
[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567bparrishMines wants to merge 4 commits intoflutter:mainfrom
applicationWillTerminate#11567Conversation
…ar in `a…" This reverts commit 6351fa4.
applicationWillTerminate
There was a problem hiding this comment.
Code Review
This pull request updates the webview_flutter_wkwebview plugin to version 3.24.6, increases the minimum supported SDK versions to Flutter 3.38 and Dart 3.10, and implements logic to tear down the ProxyAPIRegistrar when the application terminates or a scene disconnects on iOS. Review feedback notes that PlatformViewImplTests.swift is referenced in the project file but missing from the PR, warns that sceneDidDisconnect might prematurely destroy state in multi-scene applications, suggests safer handling of optional scenes in tests, and identifies redundant setup calls in the new test file.
| 8F1488FF2D2DE27000191744 /* NavigationActionProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488CB2D2DE27000191744 /* NavigationActionProxyAPITests.swift */; }; | ||
| 8F1489012D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1489002D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift */; }; | ||
| 8F63D06B2F8812E400EC5076 /* WebViewFlutterPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F63D06A2F8812E400EC5076 /* WebViewFlutterPluginTests.swift */; }; | ||
| 8F63D06C2F8812E400EC5076 /* PlatformViewImplTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F63D0692F8812E400EC5076 /* PlatformViewImplTests.swift */; }; |
There was a problem hiding this comment.
| public func sceneDidDisconnect(_ scene: UIScene) { | ||
| tearDownProxyAPIRegistrar() | ||
| } |
There was a problem hiding this comment.
Tearing down the ProxyAPIRegistrar in sceneDidDisconnect may be problematic for applications that support multiple scenes (e.g., on iPad). If one scene is disconnected while others remain active and share the same Flutter engine, the plugin's state will be destroyed for all scenes, potentially breaking the remaining webviews. Since applicationWillTerminate and detachFromEngine already handle cleanup for the app and engine respectively, consider if sceneDidDisconnect is necessary or if it should be removed to avoid side effects in multi-window scenarios.
| expectation.fulfill() | ||
| } | ||
|
|
||
| let scene = UIApplication.shared.connectedScenes.first! |
There was a problem hiding this comment.
Using a forced unwrap on UIApplication.shared.connectedScenes.first can lead to a crash during test execution if the test environment does not have any active scenes. It is safer to use a guard statement or an optional binding to handle cases where no scenes are connected.
| let scene = UIApplication.shared.connectedScenes.first! | |
| guard let scene = UIApplication.shared.connectedScenes.first else { | |
| XCTFail("No connected scenes found.") | |
| return | |
| } |
| #if os(iOS) | ||
| func testInstanceManagerIsDeallocatedInApplicationWillTerminate() { | ||
| let plugin = WebViewFlutterPlugin(binaryMessenger: TestBinaryMessenger()) | ||
| plugin.proxyApiRegistrar!.setUp() |
|
|
||
| func testInstanceManagerIsDeallocatedInSceneDidDisconnect() { | ||
| let plugin = WebViewFlutterPlugin(binaryMessenger: TestBinaryMessenger()) | ||
| plugin.proxyApiRegistrar!.setUp() |
| sdk: ^3.9.0 | ||
| flutter: ">=3.35.0" | ||
| sdk: ^3.10.0 | ||
| flutter: ">=3.38.0" |
There was a problem hiding this comment.
Weren't these added in 3.41, not 3.38?
Relands #11484
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2