Skip to content

[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567

Open
bparrishMines wants to merge 4 commits intoflutter:mainfrom
bparrishMines:wkwebview_terminate2
Open

[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567
bparrishMines wants to merge 4 commits intoflutter:mainfrom
bparrishMines:wkwebview_terminate2

Conversation

@bparrishMines
Copy link
Copy Markdown
Contributor

@bparrishMines bparrishMines commented Apr 22, 2026

Relands #11484

Pre-Review Checklist

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-assist bot 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

  1. 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

@bparrishMines bparrishMines changed the title Wkwebview terminate2 [webview_flutter_wkwebview] Prevent message calls when application will terminate Apr 22, 2026
@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview] Prevent message calls when application will terminate [webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate Apr 22, 2026
@bparrishMines bparrishMines added the CICD Run CI/CD label Apr 22, 2026
@bparrishMines bparrishMines marked this pull request as ready for review April 22, 2026 21:40
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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 */; };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The project file has been updated to include PlatformViewImplTests.swift, but this file is missing from the pull request patches. This will result in a build error in Xcode due to a missing file reference. Please ensure all new test files are included in the commit.

Comment on lines +60 to +62
public func sceneDidDisconnect(_ scene: UIScene) {
tearDownProxyAPIRegistrar()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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!
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The call to plugin.proxyApiRegistrar!.setUp() is redundant because the WebViewFlutterPlugin initializer already calls setUp() on the registrar. This can be removed to avoid unnecessary re-initialization of the ProxyAPI.


func testInstanceManagerIsDeallocatedInSceneDidDisconnect() {
let plugin = WebViewFlutterPlugin(binaryMessenger: TestBinaryMessenger())
plugin.proxyApiRegistrar!.setUp()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The call to plugin.proxyApiRegistrar!.setUp() is redundant here as well, as the plugin's initializer already handles the setup of the registrar.

sdk: ^3.9.0
flutter: ">=3.35.0"
sdk: ^3.10.0
flutter: ">=3.38.0"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Weren't these added in 3.41, not 3.38?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants