Repository navigation
Conversation
d677123 to
98f1001
Compare
…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.
54b2687 to
8d7fa09
Compare
…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.
7ffc4e8 to
bd246d9
Compare
…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.
bd246d9 to
cdc64dd
Compare
There was a problem hiding this comment.
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.
| void _onNonDartFileChangeDetected(String path) { | ||
| if (_widgetPreviewApp?.assetBundle.needsBuild() ?? false) { | ||
| logger.printStatus('Triggering reload based on update to asset: $path'); | ||
| _widgetPreviewApp?.restart(); | ||
| } | ||
| } |
There was a problem hiding this comment.
The restart() method on _widgetPreviewApp is asynchronous and returns a Future. To prevent unawaited futures and adhere to the project's lint rules (such as unawaited_futures), please wrap the call in unawaited.
| void _onNonDartFileChangeDetected(String path) { | |
| if (_widgetPreviewApp?.assetBundle.needsBuild() ?? false) { | |
| logger.printStatus('Triggering reload based on update to asset: $path'); | |
| _widgetPreviewApp?.restart(); | |
| } | |
| } | |
| void _onNonDartFileChangeDetected(String path) { | |
| if (_widgetPreviewApp?.assetBundle.needsBuild() ?? false) { | |
| logger.printStatus('Triggering reload based on update to asset: $path'); | |
| unawaited(_widgetPreviewApp?.restart()); | |
| } | |
| } |
There was a problem hiding this comment.
Done — switched to unawaited(_triggerReload(.hotReload)); to match the other reload callbacks.
| if (!filePath.isDartFile) { | ||
| onNonDartFileChangeDetected?.call(filePath); | ||
| return; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cdc64dd to
431b96e
Compare
Previously,
PreviewDetectorandLspPreviewDetectorignored modifications to non-Dart files (and Dart files outside the analysis context, such as hook scripts), andFlutterHookResult._wasAnyFileModifiedSincedid not treat deleted files (FileSystemEntityType.notFound) as modified.Bug:
hook/build.dartData assets support #146264Changes
onNonDartFileChangeDetectedcallback toPreviewDetectorandLspPreviewDetector, wired up inWidgetPreviewStartCommandto trigger a preview app restart whenassetBundle.needsBuild()istrue.FileSystemEntityType.notFoundas modified inFlutterHookResult._wasAnyFileModifiedSince.lsp_preview_detector_test.dartandasset_bundle_test.dart.PR Stack
data-assets-empty-pubspecdata-assets-flutter-testdata-assets-dev-dependencies-release-testdata-assets-widget-previewPre-launch Checklist
///).