Skip to content

[webview_flutter_wkwebview] Fixes inspectable compile-time error and crash from equal NSURLs #4340

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

Merged
merged 9 commits into from
Jul 3, 2023

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Jun 28, 2023

Fixes flutter/flutter#128422 by using pointer equality in the NSMapTable. From my understanding and testing it seems that the default mode for NSMapTable is to copy objects that implement NSCopyable. The only class we wrap that does seems to implement NSCopyable is NSURL so this class eventually led to a race condition where adding an NSURL that was equivalent to an already added one would replace the original.

Note that we should probably now add an error when adding an already present instance. However, a clear method needs to be added to the InstanceManager first so that hot reload will continue working. This is the current solution on Android.

Fixes flutter/flutter#129587 by adding a compile-time check around the use of WKWebView.inspectable. Solution used from:

https://stackoverflow.com/questions/76216183/how-to-debug-wkwebview-in-ios-16-4-1-using-xcode-14-2

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/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package 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.

@bparrishMines bparrishMines changed the title add some fixes [webview_flutter_wkwebview] Fixes inspectable compile-time error and crash from equal NSURLs Jun 28, 2023
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

@@ -201,7 +201,10 @@ - (void)setInspectableForWebViewWithIdentifier:(NSNumber *)identifier
inspectable:(NSNumber *)inspectable
error:(FlutterError *_Nullable *_Nonnull)error {
if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 160400
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not add tvOS checks, since we don't support tvOS, or have any plans to.

@@ -465,6 +465,8 @@ - (void)testContentInsetsSumAlwaysZeroAfterSetFrame {
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100)));
}

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 || \
__TV_OS_VERSION_MAX_ALLOWED >= 160400
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't need this check on tests, since most clients aren't running our native tests, and it's fine for us to require a new Xcode for development.

@bparrishMines
Copy link
Contributor Author

@cyanglaz @stuartmorgan Have you seen this error before?

/Volumes/Work/s/w/ir/x/w/packages/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 11.0 to 16.4.99. (in target 'OCMock' from project 'Pods')

Test session results, code coverage, and logs:
	/Users/chrome-bot/Library/Developer/Xcode/DerivedData/Runner-gobtbkgsitlgxgbndnnohkiqixxx/Logs/Test/Test-Runner-2023.06.28_13-50-12--0700.xcresult

2023-06-28 13:50:12.712 xcodebuild[80036:429328] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:iOS Simulator, id:FE4856FB-F70D-4B05-8DEA-BA4592F486A7, OS:16.4, name:iPhone 14 }
{ platform:iOS Simulator, id:FE4856FB-F70D-4B05-8DEA-BA4592F486A7, OS:16.4, name:iPhone 14 }
Testing failed:
	Null passed to a callee that requires a non-null argument
	Testing cancelled because the build failed.

** TEST FAILED **

Everything runs and builds locally. Is the warning the source of the build failure?

@stuartmorgan-g
Copy link
Contributor

Testing failed:
Null passed to a callee that requires a non-null argument
Testing cancelled because the build failed.

This warning is the cause of the build failure; if you scroll up further you can find the original in context.

You're passing nil in a non-nullable callback; you need to pass a no-op block instead.

@@ -201,7 +201,9 @@ - (void)setInspectableForWebViewWithIdentifier:(NSNumber *)identifier
inspectable:(NSNumber *)inspectable
error:(FlutterError *_Nullable *_Nonnull)error {
if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Jul 1, 2023

Choose a reason for hiding this comment

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

Hm, looking at this again: do @available checks evaluate to false automatically when the compile SDK is lower than the available version? I'm not sure they do, and if they don't then this would, if compiled with an SDK < 16.4 but run on 16.4, silently no-op.

I guess that's not that big a deal for this particular case, but we should investigate before using this pattern again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure they do, and if they don't then this would, if compiled with an SDK < 16.4, but run on 16.4, silently no-op.

Yea, I think you're correct. This could probably use an additional #ifelse that also returns a FlutterError. I didn't quite understand this until after I autosubmitted.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@jpeace-pro
Copy link

Hi there, could anyone help provide an update on when this will be released?

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 3, 2023
@auto-submit auto-submit bot merged commit a03b900 into flutter:main Jul 3, 2023
@bparrishMines bparrishMines deleted the fix_wkwebview branch July 3, 2023 23:52
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 4, 2023
flutter/packages@cdae854...a03b900

2023-07-03 [email protected] [webview_flutter_wkwebview] Fixes inspectable compile-time error and crash from equal `NSURL`s (flutter/packages#4340)

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 [email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter platform-ios
Projects
None yet
4 participants