Skip to content

fix(web): guard URL strategy import on js_interop, not html - #537

Merged
richardthe3rd merged 1 commit into
mainfrom
fix/525-wasm-url-strategy
Aug 10, 2026
Merged

fix(web): guard URL strategy import on js_interop, not html#537
richardthe3rd merged 1 commit into
mainfrom
fix/525-wasm-url-strategy

Conversation

@richardthe3rd

Copy link
Copy Markdown
Owner

Fixes #525

What changed

lib/main.dart — the URL-strategy conditional import is now guarded on dart.library.js_interop instead of dart.library.html.

dart:html is only provided by dart2js. Under dart2wasm the condition is false, so usePathUrlStrategy() resolved to the no-op in lib/url_strategy_stub.dart and 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_interop is the supported "compiling for the web" condition on both backends (Flutter's recommendation since 3.22). kIsWeb already 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:

Compiler dart.library.html dart.library.js_interop
dart2js real branch ✅ real branch ✅
dart2wasm stub branch ❌ real branch ✅

That 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 check passes (1309 tests, analyzer clean) and ./bin/mise run build:web succeeds.

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

`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
Copilot AI lite review requested due to automatic review settings August 10, 2026 18:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.html to dart.library.js_interop for web URL strategy.
  • Add an explanatory comment documenting the dart2wasm failure mode and linking to ADR/issue context.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Cloudflare Pages Preview

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

@richardthe3rd
richardthe3rd merged commit 280bf29 into main Aug 10, 2026
16 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 10, 2026
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.

Conditional import guard silently drops path URLs in a Wasm web build

3 participants