crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.98k stars 192 forks source link

ES6 Modules singleton is break for DevServer HMR #662

Closed KspTooi closed 1 year ago

KspTooi commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

i am using the @crxjs/vite-plugin to build my project with vite4.1.4 however i noticed that when running the devServer all ES6 modules imported into the project are not singleton preventing me from maintaining state within the module.

i have tested building the project with npm run build, and this issue does not occur in the production build tried using different vite config and plugin options but issue persists

this problem prevents me from using this plugin in my projects, and i would appreciate any help in fix it.

Reproduction

https://github.com/KspTooi/my-chrome-ext

Logs

No response

System Info

System:
    OS: Windows 10 10.0.17763
    CPU: (8) x64 Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
    Memory: 17.92 GB / 49.95 GB
  Binaries:
    Node: 18.14.1 - C:\Apps\nodejs\node.EXE
    npm: 9.5.0 - C:\Apps\nodejs\npm.CMD
  Browsers:
    Internet Explorer: 11.0.17763.2989
  npmPackages:
    @crxjs/vite-plugin: ^2.0.0-beta.13 => 2.0.0-beta.13
    vite: ^4.1.0 => 4.1.4

Severity

blocking all usage of RPCE

jacksteamdev commented 1 year ago

@KspTooi Thanks for bringing this up. I've confirmed it and am working on a fix.

jacksteamdev commented 1 year ago

I've added tests to ensure that modules are singleton, and fixed the bug.