Skip to content

Add proactive Flutter hot reload rule - #228

Open
jwren wants to merge 2 commits into
mainfrom
rule-flutter-hot-reload
Open

Add proactive Flutter hot reload rule#228
jwren wants to merge 2 commits into
mainfrom
rule-flutter-hot-reload

Conversation

@jwren

@jwren jwren commented Aug 28, 2026

Copy link
Copy Markdown
Member

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.

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.

@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 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.

Comment on lines +1 to +6
---
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
---

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

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
---

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread rules/flutter-hot-reload.md Outdated
Comment on lines +19 to +20
- 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.

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

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.

Suggested change
- 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

Comment thread rules/flutter-hot-reload.mdc Outdated
Comment on lines +20 to +21
- 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.

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

…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.
@jwren
jwren requested a review from kenzieschmoll August 28, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant