Repository navigation
[flutter_tools] serialize and gate widget preview hot reloads - #192325
Merged
Merged
Conversation
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
Merged
9 tasks done
bkonyi
marked this pull request as ready for review
September 29, 2026 14:47
Contributor
There was a problem hiding this comment.
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.
…formatting in widget_preview.dart
…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`.
srawlins
approved these changes
Oct 2, 2026
srawlins
left a comment
Contributor
There was a problem hiding this comment.
Foof big change. It's all readable though; no red flags, nice effort on the tests. LGTM
This was referenced 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
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.
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 guardsResidentWebRunner.restart()against overlapping calls or calls after the app has exited.Fixes #192134
Pre-launch Checklist
///).