react-native-webview icon indicating copy to clipboard operation
react-native-webview copied to clipboard

fix(Android): Apply WebView settings before loading content

Open TheAlmightyBob opened this issue 3 years ago • 16 comments

Fixes #2723. As mentioned in that issue, the problem was that the 11.22.0 refactor moved the source property before others when rendering NativeWebView on Android, which meant that allowFileAccess was not set until after the WebView was already trying (and failing) to load a local file. Other platforms were unaffected because the source property was not moved in those files.

Added example from @jacobpenny. Modified to use react-native-blob-util instead of react-native-file-access to populate the local filesystem because the latter broke the macOS build. The former does not support macOS or Windows, so the example is disabled on those platforms, but at least it doesn't break the build (it did require a tweak to the build.gradle file for Android, related to this issue again... I'm guessing react-native-blob-util needs to update its React Native dependency, but I'm not 100% certain...)

(The podfile.lock change is just because that's been getting updated any time I run pod install on the example project for a long time now so I finally decided maybe I should actually commit the updated version)

To be extra-clear: The actual fix here is just a tiny change in WebView.android.tsx. Everything else is just about adding the example.

TheAlmightyBob avatar Dec 02 '22 04:12 TheAlmightyBob

@Titozzz @jamonholmgren Could I get a quick approval on this small bug fix? Can't approve my own PRs.

(as noted in the description, the actual fix is just moving one line in one file.. the rest is about adding an example... though if you have concerns about that I welcome you to share them)

TheAlmightyBob avatar Dec 09 '22 20:12 TheAlmightyBob

Do you have discord ? I'd like to chat about the changes 🙂

Titozzz avatar Dec 09 '22 21:12 Titozzz

@Titozzz I don't. I'm in the Infinite Red React Native Slack though (and, more specifically, in the React Native Webview channel)? And I'm not opposed to Discord, I just don't currently use it.

TheAlmightyBob avatar Dec 09 '22 23:12 TheAlmightyBob

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Mar 07 '23 00:03 github-actions[bot]

Hello bot yes that's a mistake please keep this open

TheAlmightyBob avatar Mar 07 '23 02:03 TheAlmightyBob

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar May 09 '23 00:05 github-actions[bot]

Welp, after merging the new architecture changes, I'm no longer seeing this change fix the issue (that is, even with source moved to the end of the props list, it is being applied before allowFileAccess and thus access is being denied). The test still sure seems useful though!

(I'm not 100% certain if the new arch changes are related or a coincidence, but if I revert to before those changes it works as expected... it's possible that this was a change in React Native itself and just upgrading that as part of the new arch work made the difference...)

At this point, my best guess for a "proper" fix would be to override updateProperties or onAfterUpdateTransaction so that we only try to load the URL after all other properties are applied (e.g., setSource would just store a "pending" source, but no loading would happen until after all properties are updated).

TheAlmightyBob avatar May 30 '23 08:05 TheAlmightyBob

Hm. The Windows CI failure is:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 10.0.18362.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:\a\react-native-webview\react-native-webview\node_modules\react-native-blob-util\windows\ReactNativeBlobUtil\ReactNativeBlobUtil.vcxproj] Done Building Project "D:\a\react-native-webview\react-native-webview\node_modules\react-native-blob-util\windows\ReactNativeBlobUtil\ReactNativeBlobUtil.vcxproj" (default targets) -- FAILED.

It worked before, so I'm guessing this is because the Windows CI was updated to target newer versions as part of the new architecture changes, and react-native-blob-util is depending on an older version...

TheAlmightyBob avatar Jun 03 '23 18:06 TheAlmightyBob

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Aug 03 '23 00:08 github-actions[bot]

Hi bot please keep open... for now...

TheAlmightyBob avatar Aug 04 '23 01:08 TheAlmightyBob

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Oct 05 '23 00:10 github-actions[bot]

Can you please reopen this one? We're still facing this bug with Fabric enabled in the current latest version of react-native-webview (13.6.2), so it's blocking us from enabling the new architecture in production.

ArGeoph avatar Oct 24 '23 15:10 ArGeoph

@ArGeoph I'll reopen, but your comment that you're seeing a bug "with Fabric enabled" tells me that this PR won't help, at least in its current state. This bug predates the new architecture work (so is not specific to Fabric being enabled), and my last update was that the changes here no longer seem to help after rebasing on the new architecture changes. Unfortunately I think there's still a lot of work to do here...

TheAlmightyBob avatar Oct 31 '23 02:10 TheAlmightyBob

@ArGeoph I'll reopen, but your comment that you're seeing a bug "with Fabric enabled" tells me that this PR won't help, at least in its current state. This bug predates the new architecture work (so is not specific to Fabric being enabled), and my last update was that the changes here no longer seem to help after rebasing on the new architecture changes. Unfortunately I think there's still a lot of work to do here...

Thanks for the reply! I'll see if I can do anything to fix this issue and open a PR if I find a solution.

ArGeoph avatar Nov 17 '23 17:11 ArGeoph

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Jan 17 '24 00:01 github-actions[bot]

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Mar 24 '24 00:03 github-actions[bot]

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

github-actions[bot] avatar Jun 18 '24 00:06 github-actions[bot]