Skip to content

Doesn't re-render on HMR #4

@zephraph

Description

@zephraph

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions