Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation in HMR event, 'vite:afterUpdate' #6379

Closed
4 tasks done
eddie0329 opened this issue Jan 4, 2022 · 5 comments · Fixed by #9810
Closed
4 tasks done

Implementation in HMR event, 'vite:afterUpdate' #6379

eddie0329 opened this issue Jan 4, 2022 · 5 comments · Fixed by #9810
Labels
enhancement New feature or request feat: hmr p2-to-be-discussed Enhancement under consideration (priority)

Comments

@eddie0329
Copy link

eddie0329 commented Jan 4, 2022

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

@bluwy
Copy link
Member

bluwy commented Jun 26, 2022

I think this make sense, but it would be helpful if you can show a usecase for it too to further justify this feature request.

@eddie0329
Copy link
Author

eddie0329 commented Jun 28, 2022

@bluwy Thanks for reply. Should I refer ordinary usecase, using other bundlers, such as webpack, rollup? (usecase for afterUpdate.
Or Should I get mine using vite?

@potty
Copy link

potty commented 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.

rexxars added a commit to rexxars/vite that referenced this issue Aug 20, 2022
rexxars added a commit to rexxars/vite that referenced this issue Aug 24, 2022
rexxars added a commit to rexxars/vite that referenced this issue Aug 24, 2022
rexxars added a commit to rexxars/vite that referenced this issue Aug 24, 2022
@sapphi-red sapphi-red added enhancement New feature or request and removed enhancement: pending triage labels Aug 24, 2022
@patak-dev patak-dev added the p2-to-be-discussed Enhancement under consideration (priority) label Aug 24, 2022
@alvarosabu
Copy link

I was looking for something like this, this will be specially useful for the work I'm doing with ThreeJS, since is tricky to have a good DX while updating files, with this hooks I could basically dispose renderers and initialize them

@patak-dev
Copy link
Member

@alvarosabu see #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)

@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: hmr p2-to-be-discussed Enhancement under consideration (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants