[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567
Conversation
…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() |
There was a problem hiding this comment.
I just noticed that this is being added to the iOS project but not the macOS project, even though it sounds generic. Someone will almost certainly add tests here in the future thinking they will run on macOS, so the file should be added to both.
There was a problem hiding this comment.
I went ahead and added all the tests files not added on macOS.
…r#185897) flutter/packages@cde5b36...daf30f8 2026-04-30 mdebbar@google.com [url_launcher_web] Re-enable flaky test (not flaky anymore) (flutter/packages#11478) 2026-04-30 stuartmorgan@google.com [in_app_purchase] Switch to Kotlin Pigeon (flutter/packages#11608) 2026-04-29 katelovett@google.com [two_dimensional_scrollables] Fix mouse event loop when calling setState in TableSpan.onEnter (flutter/packages#11606) 2026-04-29 katelovett@google.com [two_dimensional_scrollables] trailing pinned row/col for TableView (flutter/packages#11519) 2026-04-29 10687576+bparrishMines@users.noreply.github.com [webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in `applicationWillTerminate` (flutter/packages#11567) 2026-04-29 stuartmorgan@google.com [google_maps_flutter] Replace use of zIndex in examples and tests (flutter/packages#11572) 2026-04-29 stuartmorgan@google.com [tool] Remove --against-pub flag (flutter/packages#11550) 2026-04-29 47866232+chunhtai@users.noreply.github.com [ci] Update branch management for batch release (flutter/packages#11575) 2026-04-29 spkhalad@gmail.com [webview_flutter] Platform implementations for getCookies flutter#11037 (flutter/packages#11386) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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