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

Versionhash causes duplicate module resolution breaking global object references #10142

Closed
7 tasks done
martinpengellyphillips opened this issue Sep 16, 2022 · 4 comments
Closed
7 tasks done

Comments

@martinpengellyphillips
Copy link

Describe the bug

Following on from #10087;

I implemented the suggested fix in vite-plugin-solid. It fixed the jsx analysis error, but uncovered another issue in how the modules are being resolved. It seems we end up with duplicate versions of the same module (and thus invalid global object references across them which breaks things like Context lookup in Solid JS).

For example; in the repo https://github.com/thisbeyond/solid-dnd-site we end up with both of the following being resolved as separate versions of the same module:

/node_modules/@thisbeyond/solid-dnd/dist/source/drag-drop-context.jsx
/node_modules/@thisbeyond/solid-dnd/dist/source/drag-drop-context.jsx?v=bce1c9bf

And this causes different global instances of a Context lookup object (note the different ids) which breaks the code:

Context id:0.8927619414327423 [drag-drop-context.jsx:7:8](c:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/@thisbeyond/solid-dnd/dist/source/drag-drop-context.jsx)
Context id:0.7896487530041784 [drag-drop-context.jsx:7:8](c:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/@thisbeyond/solid-dnd/dist/source/drag-drop-context.jsx?v=29aaa58c)

I think this might be similar to the issue #9828 but the issue is still present for us in Vite 3.1.1. Note that Vite 3.0.9 did not exhibit this bug.

Reproduction

https://github.com/thisbeyond/solid-dnd-site

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
    Memory: 4.50 GB / 15.91 GB
  Binaries:
    Node: 17.7.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.2.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 105.0.5195.102
    Edge: Spartan (44.19041.1266.0), Chromium (105.0.1343.42)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Logs

No response

Validations

@nksaraf
Copy link

nksaraf commented Sep 16, 2022

I investigated this more and it could be with how vite was deciding whether to add version query hash or not. The correct thing is to add it for everything. So @patak-dev made a fix for this:
#10141. Could we verify if this solves the problem?

@martinpengellyphillips
Copy link
Author

We worked this through and it did address the issue (so long as we also added "jsx" to optimizeDeps.extensions and relevant libraries to optimizeDeps.exclude).

@nksaraf
Copy link

nksaraf commented Sep 17, 2022

Yeah excluding from optimizeDeps is needed right now because we dont add an esbuild loader for jsx files in vite-plugin-solid, so esbuild actually compiles to React code.

@sapphi-red
Copy link
Member

Closing as this seems to be fixed by #10141.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants