Skip to content

[flutter_tools] Reload widget-preview when data assets change - #193437

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
dcharkes:data-assets-widget-preview
Oct 14, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
dcharkes:data-assets-widget-preview

Conversation

@dcharkes

@dcharkes dcharkes commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Previously, PreviewDetector and LspPreviewDetector ignored modifications to non-Dart files (and Dart files outside the analysis context, such as hook scripts), and FlutterHookResult._wasAnyFileModifiedSince did not treat deleted files (FileSystemEntityType.notFound) as modified.

Bug:

Changes

  • Add onNonDartFileChangeDetected callback to PreviewDetector and LspPreviewDetector, wired up in WidgetPreviewStartCommand to trigger a preview app restart when assetBundle.needsBuild() is true.
  • Treat FileSystemEntityType.notFound as modified in FlutterHookResult._wasAnyFileModifiedSince.
  • Update lsp_preview_detector_test.dart and asset_bundle_test.dart.

PR Stack

# PR Branch Commit
1 #193434 data-assets-empty-pubspec ab37f42
2 #193435 data-assets-flutter-test 4956c97
3 #193436 data-assets-dev-dependencies-release-test 416d09a
4 👉 #193437 (this PR) data-assets-widget-preview 431b96e

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • 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).
  • 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.
  • All existing and new tests are passing.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 28, 2026
@dcharkes
dcharkes force-pushed the data-assets-widget-preview branch from d677123 to 98f1001 Compare September 28, 2026 09:58
@dcharkes dcharkes added the CICD Run CI/CD label Sep 28, 2026
@dcharkes
dcharkes requested a review from bkonyi September 28, 2026 10:27
pull Bot pushed a commit to phamminhphuc/flutter that referenced this pull request Sep 28, 2026
…mpty (flutter#193434)

When `flutterManifest.isEmpty` (for example, a `pubspec.yaml` without a
`flutter:` section), `ManifestAssetBundle.build` previously returned
early with an empty `AssetManifest.bin`, ignoring any data assets
produced by build/link hooks (`flutterHookResult.dataAssets`).

Bug:

* flutter#146264

### Changes
- Only short-circuit with an empty manifest in
`ManifestAssetBundle.build` when both `flutterManifest.isEmpty` and
`flutterHookResult?.dataAssets.isEmpty ?? true`.
- Skip `computeTransitiveDependencies` when `flutterManifest.isEmpty`.
- Add a unit test in `asset_bundle_test.dart` verifying that data assets
from hooks are bundled when `pubspec.yaml` is empty.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| **1** | **👉 flutter#193434 (this PR)**
| `data-assets-empty-pubspec` |
flutter@62199c4
|
| 2 | flutter#193435 |
`data-assets-flutter-test` |
flutter@25be1ab
|
| 3 | flutter#193436 |
`data-assets-dev-dependencies-release-test` |
flutter@79abad9
|
| 4 | flutter#193437 |
`data-assets-widget-preview` |
flutter@98f1001
|

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
@dcharkes
dcharkes force-pushed the data-assets-widget-preview branch 6 times, most recently from 54b2687 to 8d7fa09 Compare October 1, 2026 09:40
mattkae pushed a commit to canonical/flutter that referenced this pull request Oct 1, 2026
…r#193435)

Previously, `flutter test` ran native assets hooks via
`TestCompilerNativeAssetsBuilder.build(buildInfo)`, which only returned
the `NativeAssetsManifest.json` URI and discarded the
`FlutterHookResult` containing hook-generated data assets.

Bug:

* flutter#146264

### Changes
- Add `buildWithHookResult` to `TestCompilerNativeAssetsBuilder`
returning both `nativeAssetsManifest` and `flutterHookResult`.
- Pass `flutterHookResult` to `_buildTestAsset` / `assetBundle.build` in
`TestCommand`.
- Update `TestCommand._needsRebuild` to check if bundled asset files
exist on disk, guard `pub.existsSync()`, and check
`flutterHookResult.dependencies` modification timestamps.
- Add a hermetic test in `test_test.dart` verifying that `flutter test`
bundles data assets from hooks into `build/unit_test_assets`.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| 1 | flutter#193434 |
`data-assets-empty-pubspec` |
flutter@62199c4
|
| **2** | **👉 flutter#193435 (this PR)**
| `data-assets-flutter-test` |
flutter@390c757
|
| 3 | flutter#193436 |
`data-assets-dev-dependencies-release-test` |
flutter@cca04e9
|
| 4 | flutter#193437 |
`data-assets-widget-preview` |
flutter@0a5a8e9
|

> **Note:** This PR is stacked on
flutter#193434. To review only this PR's
diff before the base PR lands, view commit
flutter@390c757.

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
@dcharkes
dcharkes force-pushed the data-assets-widget-preview branch 2 times, most recently from 7ffc4e8 to bd246d9 Compare October 6, 2026 08:15
fxsoulmate pushed a commit to fxsoulmate/flutter that referenced this pull request Oct 12, 2026
…n tests (flutter#193436)

When running release-mode tests (such as `flutter test integration_test
--release`), `createFlutterNativeAssetsBuildRunner` previously set
`includeDevDependencies = !buildMode.isRelease`, which excluded hooks
from `dev_dependencies`.

Bug:

* flutter#146264

### Changes
- Check `_isTestTarget(environment)` (whether `kTargetFile` is under
`integration_test/`, `test_driver/`, or `test/`) so
`includeDevDependencies` is `true` for test targets even in release
mode.
- Add a unit test in `native_assets_test.dart` verifying
`includeDevDependencies` is `false` for `lib/main.dart` in release mode
and `true` for `integration_test/app_test.dart`, `test_driver/app.dart`,
and `test/app_test.dart`.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| 1 | flutter#193434 |
`data-assets-empty-pubspec` |
flutter@ab37f42
|
| 2 | flutter#193435 |
`data-assets-flutter-test` |
flutter@4956c97
|
| **3** | **👉 flutter#193436 (this PR)**
| `data-assets-dev-dependencies-release-test` |
flutter@596124d
|
| 4 | flutter#193437 |
`data-assets-widget-preview` |
flutter@bd246d9
|

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
@dcharkes
dcharkes force-pushed the data-assets-widget-preview branch from bd246d9 to cdc64dd Compare October 12, 2026 13:26
@dcharkes
dcharkes marked this pull request as ready for review October 12, 2026 13:26

@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 adds support for triggering widget preview reloads when non-Dart files are modified by introducing an onNonDartFileChangeDetected callback to PreviewDetector and LspPreviewDetector. Review feedback recommends wrapping the asynchronous restart() call in unawaited to satisfy lint rules, and highlights a discrepancy where LspPreviewDetector fails to trigger the callback for Dart files outside the analysis context, such as hook scripts.

Comment on lines 200 to 203
if (!filePath.isDartFile) {
onNonDartFileChangeDetected?.call(filePath);
return;
}

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.

medium

In LspPreviewDetector, Dart files that are outside the analysis context (such as hook scripts) will bypass the !filePath.isDartFile check and will not trigger onNonDartFileChangeDetected. This is a discrepancy from PreviewDetector (which catches them via StateError on _collection.contextFor(eventPath)). As a result, modifications to hook scripts won't trigger a rebuild/restart when using the LSP preview detector.

@dcharkes dcharkes Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AI response: In LspPreviewDetector._fileAddedOrUpdated, all .dart file changes (including hook scripts) proceed to waitForAnalysis(), fetch dtd.getFlutterWidgetPreviews(), and invoke onChangeDetected(result), which triggers _triggerReload(.hotReload) and rebuilds the asset bundle when assetBundle.needsBuild() is true. PreviewDetector only needed onNonDartFileChangeDetected in its on StateError catch block because _collection.contextFor(eventPath) returns early before onChangeDetected for excluded Dart files.

@dcharkes
dcharkes force-pushed the data-assets-widget-preview branch from cdc64dd to 431b96e Compare October 12, 2026 13:57
bkonyi
bkonyi previously approved these changes Oct 13, 2026
@dcharkes dcharkes added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 14, 2026
Merged via the queue into flutter:master with commit 77d368a Oct 14, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Oct 15, 2026
flutter/flutter@426be96...5c7e45a

2026-10-15 [email protected] [web_paragraph] Honor TextHeightBehavior.leadingDistribution and default to proportional (flutter/flutter#193736)
2026-10-15 [email protected] Roll Skia from 79a00d7c4898 to d131b7789482 (2 revisions) (flutter/flutter#194446)
2026-10-15 [email protected] Roll Dart SDK from b8ffa9233096 to 84686ea04815 (1 revision) (flutter/flutter#194442)
2026-10-15 [email protected] Roll Dart SDK from e81af2dac9d1 to b8ffa9233096 (1 revision) (flutter/flutter#194432)
2026-10-15 [email protected] Roll Skia from ef24b8f87a2a to 79a00d7c4898 (4 revisions) (flutter/flutter#194431)
2026-10-15 [email protected] Roll Skia from 48c51004ee4e to ef24b8f87a2a (1 revision) (flutter/flutter#194427)
2026-10-15 [email protected] Roll Dart SDK from 6b50116630d0 to e81af2dac9d1 (5 revisions) (flutter/flutter#194422)
2026-10-15 [email protected] Roll Skia from b1be97266d3a to 48c51004ee4e (10 revisions) (flutter/flutter#194421)
2026-10-15 [email protected] RawAutocomplete: Fix focusNode listener mismatch in didUpdateWidget/dispose (flutter/flutter#190686)
2026-10-14 [email protected] [flutter_tools] Wait for iOS simulator log stream before launch (flutter/flutter#193142)
2026-10-14 [email protected] Move Material/Cupertino PRs from design triage to framework triage (flutter/flutter#194244)
2026-10-14 [email protected] refactor(flutter_tools): share FlutterCommand options and OptionBundles (flutter/flutter#194356)
2026-10-14 [email protected] Roll pub packages (flutter/flutter#194413)
2026-10-14 [email protected] Add ContextMenuButtonKind (flutter/flutter#193528)
2026-10-14 [email protected] Split SwiftPM plugin into multiple products (flutter/flutter#193521)
2026-10-14 [email protected] Roll Skia from 43d707a3be0e to b1be97266d3a (8 revisions) (flutter/flutter#194392)
2026-10-14 [email protected] Roll pub packages (flutter/flutter#194398)
2026-10-14 [email protected] [flutter_tools] Migrate AndroidSdk and AndroidStudio away from globals (flutter/flutter#193650)
2026-10-14 [email protected] [flutter_tools] Reload widget-preview when data assets change (flutter/flutter#193437)
2026-10-14 [email protected] [flutter tool] suppress sub-tool analytics during first run (flutter/flutter#194320)
2026-10-14 [email protected] Roll Skia from acde3755d2e2 to 43d707a3be0e (1 revision) (flutter/flutter#194385)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…r#193435)

Previously, `flutter test` ran native assets hooks via
`TestCompilerNativeAssetsBuilder.build(buildInfo)`, which only returned
the `NativeAssetsManifest.json` URI and discarded the
`FlutterHookResult` containing hook-generated data assets.

Bug:

* flutter#146264

### Changes
- Add `buildWithHookResult` to `TestCompilerNativeAssetsBuilder`
returning both `nativeAssetsManifest` and `flutterHookResult`.
- Pass `flutterHookResult` to `_buildTestAsset` / `assetBundle.build` in
`TestCommand`.
- Update `TestCommand._needsRebuild` to check if bundled asset files
exist on disk, guard `pub.existsSync()`, and check
`flutterHookResult.dependencies` modification timestamps.
- Add a hermetic test in `test_test.dart` verifying that `flutter test`
bundles data assets from hooks into `build/unit_test_assets`.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| 1 | flutter#193434 |
`data-assets-empty-pubspec` |
flutter@62199c4
|
| **2** | **👉 flutter#193435 (this PR)**
| `data-assets-flutter-test` |
flutter@390c757
|
| 3 | flutter#193436 |
`data-assets-dev-dependencies-release-test` |
flutter@cca04e9
|
| 4 | flutter#193437 |
`data-assets-widget-preview` |
flutter@0a5a8e9
|

> **Note:** This PR is stacked on
flutter#193434. To review only this PR's
diff before the base PR lands, view commit
flutter@390c757.

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…n tests (flutter#193436)

When running release-mode tests (such as `flutter test integration_test
--release`), `createFlutterNativeAssetsBuildRunner` previously set
`includeDevDependencies = !buildMode.isRelease`, which excluded hooks
from `dev_dependencies`.

Bug:

* flutter#146264

### Changes
- Check `_isTestTarget(environment)` (whether `kTargetFile` is under
`integration_test/`, `test_driver/`, or `test/`) so
`includeDevDependencies` is `true` for test targets even in release
mode.
- Add a unit test in `native_assets_test.dart` verifying
`includeDevDependencies` is `false` for `lib/main.dart` in release mode
and `true` for `integration_test/app_test.dart`, `test_driver/app.dart`,
and `test/app_test.dart`.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| 1 | flutter#193434 |
`data-assets-empty-pubspec` |
flutter@ab37f42
|
| 2 | flutter#193435 |
`data-assets-flutter-test` |
flutter@4956c97
|
| **3** | **👉 flutter#193436 (this PR)**
| `data-assets-dev-dependencies-release-test` |
flutter@596124d
|
| 4 | flutter#193437 |
`data-assets-widget-preview` |
flutter@bd246d9
|

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…r#193437)

Previously, `PreviewDetector` and `LspPreviewDetector` ignored
modifications to non-Dart files (and Dart files outside the analysis
context, such as hook scripts), and
`FlutterHookResult._wasAnyFileModifiedSince` did not treat deleted files
(`FileSystemEntityType.notFound`) as modified.

Bug:

* flutter#146264

### Changes
- Add `onNonDartFileChangeDetected` callback to `PreviewDetector` and
`LspPreviewDetector`, wired up in `WidgetPreviewStartCommand` to trigger
a preview app restart when `assetBundle.needsBuild()` is `true`.
- Treat `FileSystemEntityType.notFound` as modified in
`FlutterHookResult._wasAnyFileModifiedSince`.
- Update `lsp_preview_detector_test.dart` and `asset_bundle_test.dart`.

### PR Stack
| # | PR | Branch | Commit |
| :-: | :--- | :--- | :--- |
| 1 | flutter#193434 |
`data-assets-empty-pubspec` |
flutter@ab37f42
|
| 2 | flutter#193435 |
`data-assets-flutter-test` |
flutter@4956c97
|
| 3 | flutter#193436 |
`data-assets-dev-dependencies-release-test` |
flutter@416d09a
|
| **4** | **👉 flutter#193437 (this PR)**
| `data-assets-widget-preview` |
flutter@431b96e
|

## 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
`///`).
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
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.

2 participants