Add proactive Flutter hot reload rule - #228
Conversation
dart-lang/ai#498 Adds proactive Flutter hot reload rules (rules/flutter-hot-reload.md and rules/flutter-hot-reload.mdc) to automatically trigger hot reload or hot restart when Dart and Flutter files are modified during agent sessions. Problem: During AI-driven development workflows: - Out-of-Sync Execution: Agents modify source code on disk but do not update the active running session, leaving the simulator/device screen stale. - Context Switching Friction: Users must leave the chat interface to manually initiate a reload ('r'/'R') in the terminal or IDE. Solution: - Adds a glob-triggered rule on `**/*.dart` that instructs agents to discover running apps via DTD and execute hot reload (for widget/UI changes) or hot restart (for fundamental logic/state initialization). - Defines skip criteria for test files and comment/doc-only edits.
There was a problem hiding this comment.
Code Review
This pull request replaces the old Flutter hot reload rules with updated versions in .md and .mdc formats. The review feedback suggests removing the unsupported trigger: glob frontmatter key from the .mdc file to prevent parsing issues, and refining the guidelines to avoid overly aggressive hot restarts when modifying stateful widgets, as hot reload is typically sufficient and preserves application state.
| --- | ||
| description: Proactively connect to running Dart/Flutter apps and trigger hot reload or hot restart upon editing .dart files. | ||
| trigger: glob | ||
| globs: "**/*.dart" | ||
| alwaysApply: false | ||
| --- |
There was a problem hiding this comment.
The trigger: glob field is not a standard or supported frontmatter key for Cursor .mdc files. Cursor rules only support description, globs, and alwaysApply. Keeping unsupported fields can cause parsing issues or be ignored by the Cursor editor.
---
description: Proactively connect to running Dart/Flutter apps and trigger hot reload or hot restart upon editing .dart files.
globs: "**/*.dart"
alwaysApply: false
---
| - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. | ||
| - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. |
There was a problem hiding this comment.
Forcing a hot_restart for any change to a stateful widget or logic affecting variables they use is overly aggressive. Flutter's hot reload is designed to preserve state and works perfectly fine for most changes inside stateful widgets (including their build methods). A hot restart should only be triggered for structural changes, state initialization (initState), global/static state, or main() modifications. Unnecessary hot restarts wipe out the app's current state (navigation, inputs, etc.), which slows down the development loop.
| - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. | |
| - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. | |
| - Execute hot_reload immediately after making changes to UI widgets (including build methods of stateful widgets) or simple methods. | |
| - Execute hot_restart if fundamental logic, state initialization (e.g., initState), global/static state, or main() was modified. |
| - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. | ||
| - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. |
There was a problem hiding this comment.
Forcing a hot_restart for any change to a stateful widget or logic affecting variables they use is overly aggressive. Flutter's hot reload is designed to preserve state and works perfectly fine for most changes inside stateful widgets (including their build methods). A hot restart should only be triggered for structural changes, state initialization (initState), global/static state, or main() modifications. Unnecessary hot restarts wipe out the app's current state (navigation, inputs, etc.), which slows down the development loop.
- Execute hot_reload immediately after making changes to UI widgets (including build methods of stateful widgets) or simple methods.
- Execute hot_restart if fundamental logic, state initialization (e.g., initState), global/static state, or main() was modified.
…tter - Remove unsupported `trigger: glob` key from `flutter-hot-reload.mdc`. - Refine reload vs. restart rules to allow hot reload on stateful widget build methods and restrict hot restart to state initialization, global state, and root lifecycle changes.
dart-lang/ai#498
Adds proactive Flutter hot reload rules (rules/flutter-hot-reload.md and rules/flutter-hot-reload.mdc) to automatically trigger hot reload or hot restart when Dart and Flutter files are modified during agent sessions. Problem:
During AI-driven development workflows:
**/*.dartthat instructs agents to discover running apps via DTD and execute hot reload (for widget/UI changes) or hot restart (for fundamental logic/state initialization).