Skip to content

[flutter_tools] serialize and gate widget preview hot reloads - #192325

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:issue-192134
Oct 3, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:issue-192134

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Serializes widget preview startup and hot reload/restart operations using PreviewDetectorMutex, and coalesces concurrent reload requests while a reload or initial connection is in progress. Also guards ResidentWebRunner.restart() against overlapping calls or calls after the app has exited.

Fixes #192134

Pre-launch Checklist

Fixes an issue where rapid file modifications trigger concurrent hot
reloads in widget preview mode, causing the browser debug connection to
drop and leaving the reload progress indicator hanging indefinitely.

Also fixes a race condition where file modification events that occur
while the browser is still launching and connecting trigger premature
incremental compilation on ResidentWebRunner, causing subsequent isolate
verification calls to crash the Dart frontend compiler with a null-check
failure on lastKnownGoodResult.

Resolves this by:
- Gating widget preview reloads and restarts until the preview runner is
  fully connected and ready.
- Serializing all in-flight restart operations and coalescing rapid
  incoming change notifications into a single subsequent restart.
- Guarding ResidentWebRunner.restart against concurrent execution and
  exited state, and catching errors in restart() to ensure progress status
  is always stopped cleanly.
- Ignoring subsequent change notifications once the runner has completed
  or during shutdown.

Fixes flutter#192134
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 4, 2026
@bkonyi
bkonyi marked this pull request as ready for review September 29, 2026 14:47

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces state tracking and orchestration to serialize hot restarts and reloads within the widget previewer and ResidentWebRunner, preventing concurrent execution, deferring restarts until the app connection is established, and coalescing rapid file changes. Comprehensive unit tests are added to verify these synchronization behaviors. I have no feedback to provide as there are no review comments to evaluate.

bkonyi added 3 commits October 1, 2026 16:50
…viewDetectorMutex

Replaces the 5 boolean flags (`_previewAppReady`, `_isRestarting`, `_pendingRestart`, `_pendingFullRestart`, `_appFinished`) and `do / while` loop in `WidgetPreviewStartCommand` with `PreviewDetectorMutex` (`_reloadMutex`) and a `_PendingReload` enum (`_pendingReload`).
…estart tests

Consolidates the 3 sequential reload orchestration tests in `widget_preview_test.dart` into a single `serializes, coalesces, and gates reloads across previewer lifecycle` test with a shared `triggerChange()` helper, and merges the failed-recompile `_isRestarting` reset check into `Does not allow concurrent restarts` in `resident_web_runner_test.dart`.
@bkonyi
bkonyi requested a review from srawlins October 2, 2026 17:42

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

Foof big change. It's all readable though; no red flags, nice effort on the tests. LGTM

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 2, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 2, 2026
Merged via the queue into flutter:master with commit 243d5f0 Oct 3, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 3, 2026
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…r#192325)

Serializes widget preview startup and hot reload/restart operations
using `PreviewDetectorMutex`, and coalesces concurrent reload requests
while a reload or initial connection is in progress. Also guards
`ResidentWebRunner.restart()` against overlapping calls or calls after
the app has exited.

Fixes flutter#192134

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [ ] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[widget previews][Windows] Sometimes the widget previewer fails to hot reload and then crashes after restarting the process

2 participants