Repository navigation
Conversation
A relative engine assetBase (e.g. '/static/companion/flutter/', which the engine documents for embedded apps) or a relative custom baseUrl made versionJsonUrl call Uri.origin on a URI without a scheme. The StateError escaped getAll, so fromPlatform threw instead of trying the next location. Resolve the base URL against document.baseURI first, the same base the browser uses for the engine's relative asset requests. Fixes fluttercommunity#4005
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
On web,
versionJsonUrlparses the base URL and reads its origin. When the base URL is relative,Uri.originthrowsStateError: Cannot use origin without a scheme. This happens with:assetBase, such as'/static/companion/flutter/', which the engine documents for apps embedded in another page.AssetManager.getAssetUrl('')then returns a relative URL;baseUrlpassed tofromPlatform().The exception escapes the
??chain ingetAll, sofromPlatform()throws instead of trying the next location.This PR resolves the base URL against
document.baseURIbefore the rest ofversionJsonUrlruns. That is the same base the browser uses for the engine's relative asset requests. Absolute base URLs (http/https,chrome-extension://,file://) resolve to themselves, so their behaviour is unchanged.Tests added to
example/integration_test/package_info_plus_web_test.dart:Get correct versionJsonUrl for relative base URLs: root-relative and path-relative bases.Get correct values when the AssetManager baseUrl is relative:getAll()with anAssetManagerthat returns/static/companion/flutter/assets/.Both fail on
mainwith theStateErrorand pass with the fix.How I ran them: Chrome 155, Flutter 3.47.4, local path overrides like
melos bootstrapsets up. I didn't have ChromeDriver, so I ran the web test file withflutter test --platform chrome(a temporary copy underexample/test/) instead offlutter drive. All 11 tests in the twoPackage Info Webgroups pass. The sharedfromPlatformtest imported frompackage_info_plus_test.dartneeds the served example app, so I left it to CI'sflutter driverun.flutter analyzeis clean in the package and the example.flutter testin the package passes (8 tests).Related Issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
!in the title as explained in Conventional Commits).