vite-on-swc icon indicating copy to clipboard operation
vite-on-swc copied to clipboard

[t|j]sx files without a component causing infinite browser load.

Open chrismcv opened this issue 2 years ago • 1 comments

Thanks for this library.

I've noticed one strange issue with it, which is whereby the page will continually refresh when importing a tsx file which doesn't contain any react components. (This is in a large codebase, which seems to use the tsx extension for a lot of classes)

e.g. if you call the below store.tsx and import it into the example App.tsx, then the page will hit a refresh loop.

class Store {
  constructor(initial: number) {
    this.value = initial
  }

  value: number = 1

  update(newValue: number) {
    this.value = newValue
  }
}

export default Store

I'm wondering if the call to invalidate should only be called in a hot.on context? https://vitejs.dev/guide/api-hmr.html#hot-on-event-cb

chrismcv avatar Apr 25 '22 10:04 chrismcv

Thanks for using the library. You are right about when to call the invalidate function. I just don't have time to fix it(PR welcome :). The official vite react plugin does an amazing job, you should use it. I feel like transpiling is not the bottleneck of vite, so kind of lose the interest to maintain this plugin.

hyf0 avatar Apr 26 '22 03:04 hyf0