Skip to content

[ Tool ] Stop generating widget preview scaffold under $TMP#186476

Merged
auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:widget_preview_dir
May 22, 2026
Merged

[ Tool ] Stop generating widget preview scaffold under $TMP#186476
auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:widget_preview_dir

Conversation

@bkonyi
Copy link
Copy Markdown
Contributor

@bkonyi bkonyi commented May 13, 2026

Previously, the widget_preview_scaffold project was generated under the system temporary directory ($TMP) to work around issues with flutter clean. However, generating the scaffold in $TMP meant that the project was recreated on every run or could be lost, leading to unnecessary regeneration overhead and tracking issues.

Move the generated widget_preview_scaffold project from $TMP to a .widget_preview directory located directly under the project root. To support this change, WidgetPreviewGitignoreMigration is introduced to automatically add .widget_preview/ to the host project's .gitignore. In addition, kProjectRootPath is passed via DTD connection info to ensure WidgetInspectorService correctly adds the project root to pub root directories. Finally, file watchers (LspPreviewDetector and PreviewDetector) are updated to ignore the new .widget_preview directory.

Fixes #179036

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 13, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 moves the widgetPreviewScaffold from a temporary directory to a local .widget_preview directory and adds a migration to update .gitignore. It also updates the WidgetPreviewScaffoldInspectorService to register the project root directory. Review feedback highlights that the string check for .widget_preview is too broad and may cause false positives. Additionally, there are suggestions to lower the logging level for the gitignore migration and to resolve inconsistencies between the migration logic and the project template regarding the exclusion of the bin/ directory from .gitignore.

Comment thread packages/flutter_tools/lib/src/widget_preview/utils.dart Outdated
Comment thread packages/flutter_tools/lib/src/migrations/widget_preview_gitignore_migration.dart Outdated
Comment thread packages/flutter_tools/templates/app/.gitignore.tmpl Outdated
Previously, the `widget_preview_scaffold` project was generated under the system temporary directory (`$TMP`) to work around issues with `flutter clean`. However, generating the scaffold in `$TMP` meant that the project was recreated on every run or could be lost, leading to unnecessary regeneration overhead and tracking issues.

Move the generated `widget_preview_scaffold` project from `$TMP` to a `.widget_preview` directory located directly under the project root. To support this change, `WidgetPreviewGitignoreMigration` is introduced to automatically add `.widget_preview/` to the host project's `.gitignore`. In addition, `kProjectRootPath` is passed via DTD connection info to ensure `WidgetInspectorService` correctly adds the project root to pub root directories. Finally, file watchers (`LspPreviewDetector` and `PreviewDetector`) are updated to ignore the new `.widget_preview` directory.

Fixes flutter#179036
@bkonyi bkonyi force-pushed the widget_preview_dir branch from b3d5624 to 408819b Compare May 13, 2026 22:02
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026
The template previously ignored `.widget_preview/*` but explicitly allowed `!.widget_preview/bin/*`. Since `.widget_preview` is a generated, ephemeral scaffold project for hosting widget previews, tracking any part of it in the host project repository is unnecessary and inconsistent with the migrator logic.

Update `packages/flutter_tools/templates/app/.gitignore.tmpl` to ignore the entire `.widget_preview/` directory, aligning it with `WidgetPreviewGitignoreMigration`.

Fixes flutter#179036
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
bkonyi added 2 commits May 13, 2026 20:39
- Make `.widget_preview` check in `utils.dart` more specific by checking path segments to avoid false positives.
- Lower logging level in `WidgetPreviewGitignoreMigration` from warning to trace.
- Update tests to expect trace output.

Fixes flutter#179036
The template `widget_preview_inspector_service.dart.tmpl` references `kProjectRootPath`, but `dtd_connection_info.dart.tmpl` was missing its definition. This caused analysis failures when the template or dummy project was analyzed.

Added `const String kProjectRootPath = '';` to the template to resolve the error.

Fixes flutter#179036
@github-actions github-actions Bot removed the CICD Run CI/CD label May 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 14, 2026
Updates kProjectRootPath generation in PreviewCodeGenerator to produce a raw string (r'...'), ensuring that absolute file paths (especially on Windows) are correctly represented without escape sequence errors. Also updates the initial constant definition in the scaffold template and inflated file to be a raw string.

Fixes flutter#179036
@github-actions github-actions Bot removed the CICD Run CI/CD label May 15, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 15, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 19, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026
@bkonyi bkonyi added CICD Run CI/CD and removed tool Affects the "flutter" command-line tool. See also t: labels. labels May 19, 2026
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. and removed CICD Run CI/CD labels May 19, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 19, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 20, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 20, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 20, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 20, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 20, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 20, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 20, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 20, 2026
@bkonyi bkonyi requested a review from srawlins May 21, 2026 14:59
srawlins
srawlins previously approved these changes May 21, 2026
Copy link
Copy Markdown
Contributor

@srawlins srawlins left a comment

Choose a reason for hiding this comment

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

Nice feature

return;
}
await _analysisServer?.waitForAnalysis();
await _analysisServer?.waitForAnalysis(delay: const Duration(seconds: 5));
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.

Why the new 5 second wait?

bool get isDartFile => endsWith('.dart');
bool get isPubspec => endsWith('pubspec.yaml');
bool get doesContainDartTool => contains('.dart_tool');
bool get doesContainWidgetPreview => split(RegExp(r'[/\\]')).contains('.widget_preview');
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.

Can we extract out this RegExp into a static field so it is not constructed every time the getter is called?

- Extract path separator RegExp to a static field in StringExtension to avoid recreation.

- Revert the custom delay for waitForAnalysis in LspPreviewDetector to the default to see if it is still needed.
@github-actions github-actions Bot removed the CICD Run CI/CD label May 21, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 21, 2026
@bkonyi bkonyi requested a review from srawlins May 21, 2026 22:38
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 22, 2026
Merged via the queue into flutter:master with commit c4ef98f May 22, 2026
175 of 176 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2026
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 Preview ] Stop generating scaffold under $TMP

3 participants