Skip to content
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

fix(Android): Apply WebView settings before loading content #2766

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

TheAlmightyBob
Copy link
Collaborator

@TheAlmightyBob TheAlmightyBob commented Dec 2, 2022

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
Copy link
Collaborator Author

@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)

@Titozzz
Copy link
Collaborator

Titozzz commented Dec 9, 2022

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

@TheAlmightyBob
Copy link
Collaborator Author

TheAlmightyBob commented Dec 9, 2022

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

@github-actions
Copy link

github-actions bot commented Mar 7, 2023

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 github-actions bot added the Stale label Mar 7, 2023
@TheAlmightyBob
Copy link
Collaborator Author

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

@github-actions github-actions bot removed the Stale label Mar 8, 2023
@github-actions
Copy link

github-actions bot commented May 9, 2023

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

…guish the "require(...)" case from the "uri: 'file://...'" case

(saying "import" instead of "require" just because "require" is too vague a word...)
…WebView on Android, because otherwise we start loading the content before relevant WebView settings have been applied (for example, allowFileAccess, meaning that initial loading of local files would fail)

(this is not an Android-specific requirement, but "source" was already at the end for other platforms)
(was broken by changes to react-native-test-app)
@TheAlmightyBob
Copy link
Collaborator Author

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
Copy link
Collaborator Author

TheAlmightyBob commented Jun 3, 2023

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

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

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 github-actions bot added the Stale label Aug 3, 2023
@TheAlmightyBob
Copy link
Collaborator Author

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

@github-actions github-actions bot removed the Stale label Aug 5, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

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 github-actions bot added the Stale label Oct 5, 2023
@github-actions github-actions bot closed this Oct 13, 2023
@ArGeoph
Copy link

ArGeoph commented Oct 24, 2023

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.

@TheAlmightyBob
Copy link
Collaborator Author

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

@ArGeoph
Copy link

ArGeoph commented Nov 17, 2023

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

Copy link

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loading local files broken since 11.22.0 on Android (net::ERR_ACCESS_DENIED)
3 participants