Fix HMR for action files during development by fkatsuhiro · Pull Request #16932 · withastro/astro · GitHub
Skip to content

Fix HMR for action files during development#16932

Merged
ematipico merged 4 commits into
withastro:mainfrom
fkatsuhiro:fix/actions-hmr-invalidate
Jun 25, 2026
Merged

Fix HMR for action files during development#16932
ematipico merged 4 commits into
withastro:mainfrom
fkatsuhiro:fix/actions-hmr-invalidate

Conversation

@fkatsuhiro

@fkatsuhiro fkatsuhiro commented May 31, 2026

Copy link
Copy Markdown
Contributor

This PR fix ci error which cause type error from #16929

-------- Following content is cloned from #16929 --------

Changes

  • Fixes HMR for action files during development. Editing files in src/actions/ now takes effect immediately without requiring a dev server restart.
  • Adds clearActions() method to dev-specific pipelines (RunnablePipeline and NonRunnablePipeline) to reset the cached resolved actions, matching the existing clearMiddleware() pattern while ensuring production paths remain completely untouched.
  • Wires up file change detection in the actions Vite plugin to invalidate the virtual module and send an astro:actions-updated HMR event when action files are modified.
  • Adds HMR listeners in both dev app entrypoints to clear the actions cache when the event fires.

Testing

  • Added unit tests in packages/astro/test/units/actions/actions-hmr.test.ts covering cache invalidation behavior.
  • Verified the fix resolves the issue reported in HMR broken with actions #16913 where action endpoint returned stale values after file edits.
  • Confirmed by @fkatsuhiro that the fix works as expected.

Docs

  • No docs update needed, this restores expected HMR behavior for action files.

Closes #16913

@changeset-bot

changeset-bot Bot commented May 31, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label May 31, 2026
@fkatsuhiro fkatsuhiro mentioned this pull request May 31, 2026
1 task
@codspeed-hq

codspeed-hq Bot commented May 31, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 37.93%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 17 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Rendering: streaming [false], .md file 1.7 ms 1.2 ms +37.93%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fkatsuhiro:fix/actions-hmr-invalidate (3a5bc27) with main (dc45246)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (171cbe3) during the generation of this report, so dc45246 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The clearing of the actions is correct, but it shouldn't happen in prroduction

Comment on lines +93 to +99

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This something that shouldn't happen in production. Clearing actions in production is incorrect.

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.

I understood. That's make sense. Let me update it. Thank you.

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.

I've updated this.
Moved clearActions() from Pipeline to NonRunnablePipeline and RunnablePipeline to ensure it isn't used in the production environment.

@fkatsuhiro fkatsuhiro force-pushed the fix/actions-hmr-invalidate branch from dbbbc4e to 4cfc87d Compare June 9, 2026 16:54
@ematipico ematipico merged commit 8f4a3db into withastro:main Jun 25, 2026
29 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HMR broken with actions

3 participants