question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementation in HMR event, 'vite:afterUpdate'

See original GitHub issue

Clear 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
patak-devcommented, Nov 3, 2022

@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)

1reaction
pottycommented, Jun 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found