Implementation in HMR event, 'vite:afterUpdate'
See original GitHub issueClear and concise description of the problem
The problem is that I cannot precisely handle HMR events
, specifically ‘after update’.
According to rollup.js, there is feature like below:
import.meta.hot.afterUpdate(() => {
// after update called
})
and other bundlers have similar features, such as wepack.addStatus('idle', () => { //... })
.
Suggested solution
Abstract implementation is somehow like below:
Add notifyListeners('vite:afterUpdate')
after payload.updates.forEach
loop ends.
async function handleMessage(payload: HMRPayload) {
switch (payload.type) {
case 'update':
notifyListeners('vite:beforeUpdate', payload)
payload.updates.forEach((update) => {
// ... js and cs updates
})
notifyListeners('vite:afterUpdate') // ⭐️ fire events 'vite:afterUpdate'
break;
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (2 by maintainers)
Top Results From Across the Web
HMR API - Vite
The following HMR events are dispatched by Vite automatically: 'vite:beforeUpdate' when an update is about to be applied (e.g. a module will be...
Read more >Vite Hot Module Replacement - A Complete Example
This article explains how to set up hot module replacement (HMR) with Vite for a vanilla JS project. The goal is to be...
Read more >Development: Hot Module Replacement
To implement HMR your element or element's base class should implement one of the hotReplacedCallback methods. In your method you can do custom...
Read more >What are the new Features and Updates of Vite 4.0? - Radixweb
The implementation of React Fast Refresh is what makes SWC a popular option for some projects rather than Babel. Moreover, Vite 4 offers...
Read more >Plugins - Cypress Documentation
cypress-vite ... Note - this is 3rd party implementation, different from Cypress Cloud ... Restarts tests when receiving webpack-dev-server HMR updates.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alvarosabu see https://github.com/vitejs/vite/pull/9810, it will be available in Vite 4 (the first alpha is going to be out next week, so you could start using it if you need it before the stable release)
For me would be useful to update styles after update, because my app has multiple iframes and I have to keep styles in sync between them manually.