[Theme] Delay watcher events until file is fully written #4806
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
A bit of a shot in the dark but might help in #4764
Tailwind seems to be clearing the output file first, then building its CSS, then writing the actual output content. In this scenario, we'd be emitting an event for the empty file first, then another one every time the file is written (could be in multiple chunks, unsure). Perhaps the latter events are lost or throttled down the line.
WHAT is this pull request doing?
This delays the watcher events until a safe period of time passes without file size changes. It delays all events, but it's a short period that might not be very noticeable.
The alternative would be adding some sort of debouncing logic before calling
bulkUploadThemeAssets
, or canceling in-flight fetch calls and sending new again as they come. These approaches seemed more complex that delaying the watcher events directly.If the current solutions works in #4764, we might want to set a sensible default (e.g. 400ms) or introduce a flag / env variable to customize this for situations where there are big files.
How to test your changes?
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist