Closed axelra82 closed 2 months ago
It worked if I change useDefineForClassFields
to false
to align the tsconfig with rollup's one.
https://github.com/axelra82/vite-pnext-web-worker-issue/blob/0fa3cb4a7285ccf41a6d1b5e1ff84a407e9ac9ab/apps/vite-app/tsconfig.json#L32
(The default value is false
for some options.)
Closing as this is not a bug in Vite.
For posterity sake.
I was somewhat confused about the useDefineForClassFields
key in TS config (since I didn't recognize it. @fredrik-hjelmaeus was the one who added it for testing).
The example Vite app is only a small reproduction setup. Our production repo has a TSConfig monorepo package with multiple TS-config files depending on app.
We were able to identify that this useDefineForClassFields
is default true
when TS-config compilerOptions.target
is >= es2022
(reference).
Since we had the following in our base.json TS-config:
{
...
compilerOptions: {
...
target: "esnext",
},
}
Changing target
to "es2020"
appears to solve the issue. Again, our use case is a bit more nested than the reproduction repo and we are currently evaluating if this completely solves it for us, but as far as we can tell this is NOT a Vite issue but solely a TS-config issue.
A big thanks to @sapphi-red for finding this somewhat obscure solve and @fredrik-hjelmaeus for adding useDefineForClassFields
in the first place (otherwise we would still be scratching our heads as to why it worked in the reproduction app but not our production repo).
Describe the bug
When running PNext three loader in a Vite bundled app (see
Vite app
example in reproduction repo) there are issues with the web worker. Specifically theadaptive
point type is not updated in the render loop, thus creating afixed
point type since the shader is not getting proper data.As far as we (me and @fredrik-hjelmaeus) can tell, the issue stems from how Vite deals with web workers when doing its "Vite magic".
Possible Culprit
Looking closer at the final builds (i.e. this issue extends from
dev
toprod
as well) we have come to the conclusion that their must be something with how Vite is handling the import of the web worker found inapps/vite-app/src/pnext-loader/loading2/worker-pool.ts
.In
createWorker
we've tried 2 ways of importing the web worker (both involve changing therequire
reference for proper Vite import handling):import DecoderWorker from './decoder.worker.js?worker&inline';
(NOTE Removinginline
does not solve the issue. Using it helps us identify the difference in results between the Vite and Rollup bundlers)return new Worker(new URL('./decoder.worker.js', import.meta.url),{ type: 'module' });
We've tried to identify when/where Vite deals with the imported worker. Currently we've been looking at
webWorkerPlugin
in the build source code of Vite. Our working theory is that there has to be something in the "wrapping abstractions" inwebWorkerPlugin
that is causing the "final state" to differ in the Vite app from the Rollup/Webpack apps.Reproduction
https://github.com/axelra82/vite-pnext-web-worker-issue/tree/master
Steps to reproduce
Steps
pnpm i
(install)npm run dev
(start dev servers)Incorrect
Working
To see issue, click
Load
on each page. What you will see is the pointcloud loading withfixed
point type, when it should beadaptive
. The way you can distinguish the two is:fixed
the points will start small and growadaptive
the points will start big and shrinkThis is simplified but should provide an adequate explanation of what to look for. By running the provided apps and comparing them, side-by-side, the difference will become clear (if their are any doubts).
System Info
Used Package Manager
pnpm
Logs
No response
Validations