eleventy
eleventy copied to clipboard
The `eleventy.after` event should not fire its handlers in parallel
Operating system
macOS Sonoma 14.6.1
Eleventy
3.0.0-beta.1
Describe the bug
Eleventy should not fire its eleventy.after (and probably also not its eleventy.before) event handlers in parallel. This is an issue, because any plugin that manipulates files asynchronously now directly conflicts with another, introducting race conditions and potential flaky error scenarios.
For example, I have written a plugin that adds hash parameters to referenced asset URLs. If I were to use it in combination with any plugin that moves or renames files, the ouput would be a mangled mess of half-combinations of files that have moved, some with hash parameters, some without, and potentially duplicate files because one plugin wrote to a file that the other has just moved.
In a nutshell, the AsyncEventEmitter should use a simple for-loop instead of Promise.all() to run the handlers sequentially, though potentially we'd want an (internal) option for it to determine whether to run handlers in parallel or not for each individual event type.
Hmm! I think I’m okay with this but it’s too late for this default to ship with 3.0. We could do a temporary feature flag to ease into it.
Cool, I'll draft up a PR for it!