Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview][webview_flutter_android] Fixes bug where the WebViews could not be released #6996

Merged
merged 17 commits into from
Jan 31, 2023

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Jan 20, 2023

Fixes flutter/flutter#118579

tldr;
Fixed a bug caused by misusing withWeakRefenceTo. And fixed integration tests that started to stall because of the change.

So, apparently this causes a circular reference:

late final WKWebView _webView = withWeakRefenceTo(this, (
    WeakReference<WebKitWebViewController> weakReference,
  ) {
    return _webKitParams.webKitProxy.createWebView(
      _webKitParams._configuration,
      observeValue: (
        String keyPath,
        NSObject object,
        Map<NSKeyValueChangeKey, Object?> change,
      ) {
        // use weakReference
        }
      },
    );
  });

but this doesn't:

late final WKWebView _webView = _webKitParams.webKitProxy.createWebView(
    _webKitParams._configuration,
    observeValue: withWeakRefenceTo(this, (
      WeakReference<WebKitWebViewController> weakReference,
    ) {
      return (
        String keyPath,
        NSObject object,
        Map<NSKeyValueChangeKey, Object?> change,
      ) {
        // use weakReference
      };
    }),
    instanceManager: _webKitParams._instanceManager,
  );

It seems important that the callback method can't include any references to external values. I should have followed my own example 🤦‍♂️.

It also seems this change affected a bunch of integration tests. My assumption that Android required displaying the WebView to get the onPageFinished callback may have been incorrect. The callback doesn't work consistently unless a widget is loaded. This now happens on iOS AND Android. I was unable to debug why this is the case. It could just be quirk of integration tests. The callbacks still work in the example app when running in debug and release mode, so I don't think it is indicative of another bug.


Also tack on an additional quick fix for Android:

Fixes flutter/flutter#119332

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-ios labels Jan 20, 2023
@bparrishMines bparrishMines changed the title fix and test non disposing webview [webview_flutter_wkwebview] Fixes bug where WKWebView could not be released Jan 20, 2023
@bparrishMines bparrishMines marked this pull request as draft January 23, 2023 18:41
@arifje
Copy link

arifje commented Jan 28, 2023

When will this fix be merged? Need it to get my project working 😁

@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview] Fixes bug where WKWebView could not be released [webview_flutter_wkwebview][webview_flutter_android] Fixes bug where where the WebViews could not be released Jan 29, 2023
@bparrishMines bparrishMines marked this pull request as ready for review January 29, 2023 21:30
@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview][webview_flutter_android] Fixes bug where where the WebViews could not be released [webview_flutter_wkwebview][webview_flutter_android] Fixes bug where the WebViews could not be released Jan 30, 2023
// callback methods remain reachable.
// ignore: unused_field
late AndroidNavigationDelegate _currentNavigationDelegate;
AndroidNavigationDelegate? _currentNavigationDelegate;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making this nullable fixes flutter/flutter#119332

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 31, 2023
@bparrishMines bparrishMines added autosubmit Merge PR when tree becomes green via auto submit App and removed autosubmit Merge PR when tree becomes green via auto submit App labels Jan 31, 2023
@auto-submit auto-submit bot merged commit 1896f10 into flutter:main Jan 31, 2023
@bparrishMines bparrishMines deleted the webview_dispose_ios branch January 31, 2023 13:15
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 31, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 31, 2023
* 90f447313 [ci] Increase timeouts for platform_tests (flutter/plugins#7036)

* f5568e4b1 [google_sign_in] Add doc for iOS auth with SERVER_CLIENT_ID (flutter/plugins#4747)

* 0c05e8d91 Roll Flutter from a815ee6 to 75680ae (58 revisions) (flutter/plugins#7048)

* a4c320902 [camera]: Bump camerax_version from 1.3.0-alpha02 to 1.3.0-alpha03 in /packages/camera/camera_android_camerax/android (flutter/plugins#7061)

* 8f12b27b6 [ci] Add LUCI versions of macOS ARM tests (flutter/plugins#6984)

* 3843b38e2 [tool] Improve main-branch detection (flutter/plugins#7038)

* d39e7569c [in_app_purchase] Prep for more const widgets (flutter/plugins#7030)

* ddb9777ee [ci] Switch remaining macOS host tests to LUCI (flutter/plugins#7063)

* 2edf56324 [ci] Part 1 of swapping iOS platform test arch (flutter/plugins#7064)

* 35f0b1a49 [camerax] Add system services to plugin (flutter/plugins#6986)

* 5dd0f41a2 [webview]: Bump mockito-inline (flutter/plugins#7056)

* 1896f10ca [webview_flutter_wkwebview][webview_flutter_android] Fixes bug where the `WebView`s could not be released (flutter/plugins#6996)

* a494825fa [camerax] Allow instance manager to create identical objects (flutter/plugins#7034)

* 6ef73da26 [ci] Increase heavy workload memory (flutter/plugins#7065)

* 9da327ca3 [various] Update to use sharedDarwinSource (flutter/plugins#7027)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter Edits files for a webview_flutter plugin platform-android platform-ios
Projects
None yet
3 participants