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.
Description
This PR introduces a
vite:afterUpdate
event to mirror thevite:beforeUpdate
event. The intention is to be able to run logic that depends on the new modules being available. ThebeforeUpdate
event triggers rather early - before the modules have even been downloaded. TheafterUpdate
event triggers after the CSS has fired anonload
/onerror
event, and after other modules has been imported usingfetchUpdate()
.One example usage of this event is to trigger updates to modules/state that do not directly depend on the modified files. As an example; an error boundary in React might take arbitrary children - catching any error they throw, and set the error to state. When you modify a file that is a child of this error boundary, the boundary doesn't know that it should throw away the error and attempt re-rendering its children. Of course, this particular example won't work out of the box, since there is a bit of debouncing and a deferred rendering cycle in React - but at the very least you know the modules have been loaded and will trigger a rerender.
Another use-case would be to display a loading state while the modules are being refetched (usually not a long wait, but theoretically over the network to another device, it might).
Closes #6379
Additional context
I've moved the hmr reload message for CSS into the onload/onerror callback. This matches the other module behavior in that it emits when it is loaded, not when it is about to load. Additionally, I've modified one test that was failing due to the order of the CSS/JS potentially not being the same because of this asynchronous console output. Instead it now asserts that both messages are there, rather than the exact order of them.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).