Handle deleted files gracefully during Vite HMR compilation#19776
Handle deleted files gracefully during Vite HMR compilation#19776mvanhorn wants to merge 1 commit intotailwindlabs:mainfrom
Conversation
When a file that Tailwind is watching (e.g. an SVG asset) gets deleted during HMR, the compile step fails with ENOENT because it tries to read a file that no longer exists. This wraps the compile call with a try-catch that specifically handles ENOENT errors by invalidating the compiler/scanner state and returning false, allowing the next rebuild cycle to proceed without the deleted file. Fixes tailwindlabs#17532 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe Tailwind CSS Vite plugin's root setup process now includes error handling for the compiler invocation. When an ENOENT error occurs—typically from missing dependency files during hot module replacement—the compiler and scanner are invalidated and the setup returns false to trigger a rebuild. This prevents error propagation in scenarios where files may be deleted during development. The dependency watching and build flow remain unchanged, with the error handling path providing an alternative resolution route without affecting normal operation. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #17532
When a file that Tailwind is scanning (e.g., an SVG asset) gets deleted while the Vite dev server is running, the
compile()call crashes with an ENOENT error because it tries to read the deleted file. This kills the HMR connection and requires a server restart.The fix wraps the
compile()call inRoot.generate()with a try-catch that specifically handles ENOENT errors. When a dependency file has been deleted:false, signaling the root should be re-evaluatedNon-ENOENT errors are re-thrown to preserve normal error handling.
Test plan
pnpm build && pnpm testpassesThis contribution was developed with AI assistance (Claude Code).