Skip to content

fix(package_info_plus): resolve relative web base URLs - #4006

Open
nmloc wants to merge 1 commit into
fluttercommunity:mainfrom
nmloc:fix/package-info-relative-asset-base
Open

nmloc wants to merge 1 commit into
fluttercommunity:mainfrom
nmloc:fix/package-info-relative-asset-base

Conversation

@nmloc

@nmloc nmloc commented Oct 18, 2026

Copy link
Copy Markdown

Description

On web, versionJsonUrl parses the base URL and reads its origin. When the base URL is relative, Uri.origin throws StateError: Cannot use origin without a scheme. This happens with:

  • a relative engine assetBase, such as '/static/companion/flutter/', which the engine documents for apps embedded in another page. AssetManager.getAssetUrl('') then returns a relative URL;
  • a relative baseUrl passed to fromPlatform().

The exception escapes the ?? chain in getAll, so fromPlatform() throws instead of trying the next location.

This PR resolves the base URL against document.baseURI before the rest of versionJsonUrl runs. 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 an AssetManager that returns /static/companion/flutter/assets/.

Both fail on main with the StateError and pass with the fix.

How I ran them: Chrome 155, Flutter 3.47.4, local path overrides like melos bootstrap sets up. I didn't have ChromeDriver, so I ran the web test file with flutter test --platform chrome (a temporary copy under example/test/) instead of flutter drive. All 11 tests in the two Package Info Web groups pass. The shared fromPlatform test imported from package_info_plus_test.dart needs the served example app, so I left it to CI's flutter drive run. flutter analyze is clean in the package and the example. flutter test in the package passes (8 tests).

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (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?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

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

[Bug]: package_info_plus web throws StateError when the engine assetBase is relative

1 participant