fix(cli): avoid clearing cache early to prevent race condition in watch mode#5054
fix(cli): avoid clearing cache early to prevent race condition in watch mode#5054
Conversation
✅ Deploy Preview for unocss ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in watch mode by deferring cache clearing until after new data is populated. Previously, clearing the cache at the start of parseEntries could cause concurrent reads during async file operations to see an empty cache.
Key changes:
- Changed cache update strategy from clear-then-populate to build-new-then-swap
- Cache now remains valid throughout the async file reading operations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cache.clear() | ||
| for (const [key, value] of newCache) | ||
| cache.set(key, value) |
There was a problem hiding this comment.
Consider adding a test that verifies the race condition fix by simulating concurrent access to the cache during watch mode updates. The test should ensure that the cache remains accessible with valid data while parseEntries is executing, particularly during the file reading operations between lines 99-105.
|
commit: |
fixed #5038