Repository navigation
[stable] [tool] Fix Windows hot reload mtime truncation issue - #191599
Conversation
On Windows, `dart:io` reports `FileStat.modified` truncated to second precision (via `GetFileAttributesExW`). When `ProjectFileInvalidator.findInvalidated` compares file modification times with `lastCompiled` (which is recorded with millisecond precision), files edited in the same second as the previous compilation are ignored because `updatedAt.isAfter(lastCompiled)` returns `false`. This PR fixes the issue by truncating `lastCompiled` to second precision on Windows and using `!updatedAt.isBefore(lastCompiledTruncated)` to ensure files modified within the same second as the compilation start time are marked as invalidated. Fixes flutter#191198 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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 documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] 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 [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/ [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Loïc Sharma <[email protected]>
|
@bkonyi please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request updates ProjectFileInvalidator to address file modification time truncation on Windows. On Windows, lastCompiled is truncated to second precision to match FileStat.modified, and files are invalidated if their modification time is not before this truncated timestamp. On other platforms, the original millisecond-precision comparison is preserved. Unit tests have been added to verify this platform-specific invalidation logic. There are no review comments, and I have no feedback to provide.
2c72122
into
flutter:flutter-3.47-candidate.0
Issue Link:
#191198
Impact Description:
On Windows, file modification timestamps (mtime) reported by
dart:ioare truncated to whole-second precision. When files are edited rapidly (e.g. IDE format/save on change or quick successive edits within the same wall-clock second as the previous compilation),ProjectFileInvalidator.findInvalidatedcompares milliseconds against truncated seconds and falsely concludes that zero files have changed. Hot reload/restart silently skips compiling the changes, leaving running apps on stale code.Changelog Description:
[flutter/191198] On Windows, truncate
lastCompiledtimestamp to whole seconds inProjectFileInvalidatorso rapid consecutive file modifications within the same second are not silently ignored by hot reload.Workaround:
Wait at least 1-2 seconds after saving before triggering hot reload or hot restart.
Risk:
Test Coverage:
Validation Steps:
flutter run.lib/main.dartand trigger hot reload.lib/main.dartagain within < 1 second and trigger hot reload.Compiling dart to kernel with 0 updated files.