fix(legacy)!: remove location.protocol!="file:"
condition for modern android webview
#20179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I'm packaging a static website generated by Vite into an Android app. I used plugin-legacy to support older Android phones. However, in modern WebViews, this causes both modern chunks and legacy chunks to be loaded, resulting in unexpected behavior.
Reproduction Steps
base: './'
console.log('App initializing...')
inmain.js
to track its executionmWebView.loadUrl("file:///android_asset/index.html");
Root Cause
The
index.html
generated by Vite build contains the following code:This means
__vite_is_modern_browser
is only set totrue
whenlocation.protocol!="file:"
. As a result, even if the modern chunk loads successfully, the legacy chunk is still loaded.Solution
This pull request essentially reverts #8524.
Determining whether a browser is modern should only depend on the browser's capabilities. There's no causal relationship between checking if the protocol is
file:
and whether the browser is modern.I read the original pull request. Their core requirement was to use only legacy chunks (and skip modern chunks) in a specific scenario (in this case, when loading via the
file:
protocol). Now, plugin-legacy already has therenderModernChunks
option to meet their needs.