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

Avoiding relying on "this" in functions attached to "import.meta.hot" #15667

Closed
7 tasks done
fabiospampinato opened this issue Jan 20, 2024 · 3 comments
Closed
7 tasks done

Comments

@fabiospampinato
Copy link

fabiospampinato commented Jan 20, 2024

Describe the bug

Basically I've been doing HMR for a component like this:

export default hmr ( import.meta.hot?.accept, Component );

But since v5 the "accept" function relies on "this", which is not preserved the way I was using it, so it breaks.

Reproduction

https://github.com/utrolig/voby-vite-error

Steps to reproduce

npm i && npm run dev

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 105.52 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
    bun: 1.0.15 - ~/.bun/bin/bun
  npmPackages:
    vite: ^5.0.12 => 5.0.12

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Jan 22, 2024

cc @sheremet-va. I'm not sure if this is something we had always guaranteed. You can also manually do import.meta.hot?.accept.bind(import.meta.hot) to make it work for Vite 5. If we want to support it, we'd also do the bind manually internally. And as shown in #15610, binding is expensive especially that it'll apply to all files that uses the HMR API.

@sheremet-va
Copy link
Member

Hmm, I did not expect this usage. I am fine with changing the context implementation back to the object instead of a class.

@bluwy
Copy link
Member

bluwy commented Feb 6, 2024

Closing according to #15679 (comment)

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants