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

Doesn't re-render on HMR #4

Open
zephraph opened this issue Mar 17, 2022 · 3 comments
Open

Doesn't re-render on HMR #4

zephraph opened this issue Mar 17, 2022 · 3 comments

Comments

@zephraph
Copy link
Contributor

zephraph commented Mar 17, 2022

I'm using vite and in dev mode when HMR happens on a module that calls a tunnel, the tunnel itself isn't re-rendered.

I've written a helper as a work-around:

import t from 'tunnel-rat'

export const tunnel = (key: string) => {
  if (import.meta.hot) {
    const fullKey = `tunnel-${key}`
    if (import.meta.hot.data[fullKey]) {
      return import.meta.hot.data[fullKey]
    }
    import.meta.hot.data[fullKey] = t()
    return import.meta.hot.data[fullKey]
  }
  return t()
}

The helper requires a key so that it can persist the tunnel instance in import.meta.hot.data. I'm not incredibly experienced in HMR, so I'm not sure if there's a better solution here.

I believe the issue may have been masked before because we were never clearing the tunnel contents.

@drcmda
Copy link
Member

drcmda commented Jun 30, 2022

is this something that can safely be published that way? or will it inhibit some bundlers or environments?

@zephraph
Copy link
Contributor Author

I've got a safer solution. It's a minor breaking change, but worth it I think. I'll PR it.

@lunacrafts
Copy link

lunacrafts commented Jul 12, 2022

I've got a safer solution. It's a minor breaking change, but worth it I think. I'll PR it.

@zephraph Could you say more about this change? I'm going to re-implement the same pattern very soon and I'd love to have HMR

HMR api has been improved in vite3
https://vitejs.dev/blog/announcing-vite3.html#dev-improvements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants