fix(web): guard URL strategy import on js_interop, not html - #537
Merged
Conversation
`dart:html` is only provided by dart2js, so under dart2wasm the conditional import fell through to the no-op stub and path-based URLs silently reverted to hash routing — the outcome ADR 0004 rejected. There was no compile error and no runtime warning. `dart.library.js_interop` is the supported "compiling for the web" condition on both dart2js and dart2wasm (Flutter's recommendation since 3.22), so the guard now holds on either compiler. `kIsWeb` already gates the call itself, so nothing else changes. Verified with a conditional-import probe compiled by both backends: under dart2wasm `dart.library.html` resolves to the stub while `dart.library.js_interop` resolves to the real implementation; under dart2js both resolve to the real implementation, so the current release path is unaffected. Fixes #525
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Flutter web URL-strategy conditional import in main.dart so path-based URLs are enabled under both dart2js and dart2wasm web builds, preventing a silent fallback to hash routing.
Changes:
- Switch the conditional-import guard from
dart.library.htmltodart.library.js_interopfor web URL strategy. - Add an explanatory comment documenting the
dart2wasmfailure mode and linking to ADR/issue context.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
🚀 Cloudflare Pages PreviewYour preview deployment is ready! Preview URL: https://fix-525-wasm-url-strategy.staging-cambeerfestival.pages.dev This preview will be automatically updated when you push new commits to this PR. |
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.
Fixes #525
What changed
lib/main.dart— the URL-strategy conditional import is now guarded ondart.library.js_interopinstead ofdart.library.html.dart:htmlis only provided by dart2js. Under dart2wasm the condition is false, sousePathUrlStrategy()resolved to the no-op inlib/url_strategy_stub.dartand path-based URLs silently reverted to hash routing — the outcome ADR 0004 rejected. No compile error, no runtime warning; the first symptom would be#-prefixed URLs in production.dart.library.js_interopis the supported "compiling for the web" condition on both backends (Flutter's recommendation since 3.22).kIsWebalready gates the call itself, so nothing else changes.Verification
A conditional-import probe compiled by both backends, resolving the same two guards against distinguishable marker libraries:
dart.library.htmldart.library.js_interopThat reproduces the reported bug and confirms the fix. The dart2js row also shows the change is a no-op on the current release path.
./bin/mise run checkpasses (1309 tests, analyzer clean) and./bin/mise run build:websucceeds.Not verified here: a live browser check of the served build. Flutter's CDN assets are blocked by this environment's network policy, so the engine cannot boot headlessly — the Playwright routing suite (which asserts exact
#-free URLs) will exercise this in CI.Generated by Claude Code