Skip to content

fix(build): keep web apps on path routing through boot (no /#/, deep links survive)#6639

Merged
FeodorFitsner merged 2 commits into
flet-0.86from
fix/web-path-url-strategy-before-runapp
Jul 4, 2026
Merged

fix(build): keep web apps on path routing through boot (no /#/, deep links survive)#6639
FeodorFitsner merged 2 commits into
flet-0.86from
fix/web-path-url-strategy-before-runapp

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two web-routing regressions in the flet build web boot template introduced by the 0.86 boot-screen rework (#6616). Both worked in 0.85.3. Symptoms in a path-routed web app:

  1. Running URLs carried a /#/ fragment (e.g. /#/apps/<id>) instead of clean path URLs.
  2. A cold-start deep link reset to / — opening/refreshing /gallery or /apps/<id> bounced to the app root.

Root causes

1. URL strategy applied too late. usePathUrlStrategy() was called from prepareApp(), which runs after the boot UI mounts (BootHost._boot / the FLET_TEST FutureBuilder). By then Flutter's web routing had already initialized under the default hash strategy. → moved the strategy selection to the first statement in main(), before FletDeepLinkingBootstrap.install() (which calls ensureInitialized()) and any runApp(). Matches the before-boot ordering already used in client/lib/main.dart. usePathUrlStrategy() only sets ui_web.urlStrategy, so it's safe before ensureInitialized().

2. Boot-screen MaterialApp clobbered the deep link. The boot overlay wrapped the boot screen in MaterialApp(home: …). A MaterialApp with home builds its Navigator with reportsRouteUpdateToEngine: true, so on web it pushes the home route / to the browser URL the moment it mounts — during boot, before FletApp's real router reads the location. → render the boot screen via builder: instead of home:. With no home/routes/onGenerateRoute, WidgetsApp creates no Navigator (per its own docs) and reports nothing to the engine, so the deep link survives. The overlay never navigates, so it needs no Navigator. In 0.85.3 the boot phase rendered a bare SizedBox, which reported nothing.

Both fixes are required: (1) restores path routing; (2) preserves cold-start deep links.

Verification

Built a path-routed web app and drove it with headless Chromium against a static server:

Cold load Before After
/gallery reset to / ~1.7s after "Flutter app loaded" (before the Python worker ran) holds /gallery
/apps/testid123 reset to / holds
/ ok ok

Boot screen still renders and the app boots normally with builder:.

Files

  • sdk/python/templates/build/{{cookiecutter.out_dir}}/lib/main.dart

Summary by Sourcery

Ensure web builds use path-based URL routing from application startup and prevent the boot screen from overwriting deep-link URLs.

Bug Fixes:

  • Fix web builds incorrectly using hash-based URLs instead of clean path URLs when path routing is configured.
  • Preserve cold-start deep links in path-routed web apps by preventing the boot overlay from resetting the browser URL to the root path.

The build template called usePathUrlStrategy() from prepareApp(), which runs
after the boot UI mounts. By then Flutter's web routing had already initialized
under the default hash strategy, so path-routed web apps got /#/... URLs. Move
the strategy selection to the first statement in main(), before
FletDeepLinkingBootstrap.install() (which calls ensureInitialized) and any
runApp() — matching the before-boot ordering already used in client/lib/main.dart.

Necessary for path routing but not sufficient for cold-start deep links; see the
follow-up boot-overlay fix.
… the browser

The boot overlay wrapped the boot screen in MaterialApp(home: ...). A MaterialApp
with `home` builds its Navigator with reportsRouteUpdateToEngine: true, so on web
it pushes the home route '/' to the browser URL the moment it mounts — during
boot, before FletApp's real router reads the location. A cold-start deep link
like /gallery or /apps/<id> was therefore overwritten to '/'.

Verified with a headless-Chromium probe: pre-fix the URL reset /gallery -> /
~1.7s after 'Flutter app loaded' (before the Python worker even ran); post-fix
/gallery holds.

Render the boot screen via `builder:` instead of `home:`. With no
home/routes/onGenerateRoute, WidgetsApp creates no Navigator (per its own docs)
and reports nothing to the engine, so the deep link survives until the app's
router takes over. The overlay never navigates, so it needs no Navigator.

Regression from the 0.86 boot-screen rework (#6616); 0.85.3 rendered a bare
SizedBox during boot, which reported nothing.

@sourcery-ai sourcery-ai Bot 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.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 44476cf
Status: ✅  Deploy successful!
Preview URL: https://0b67b4c4.flet-website-v2.pages.dev
Branch Preview URL: https://fix-web-path-url-strategy-be.flet-website-v2.pages.dev

View logs

@FeodorFitsner FeodorFitsner merged commit 4645958 into flet-0.86 Jul 4, 2026
58 checks passed
@FeodorFitsner FeodorFitsner deleted the fix/web-path-url-strategy-before-runapp branch July 4, 2026 18:46
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.

1 participant