You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm unable to run Preact components using SWR, in test environnement (Vitest).
In dev/prod environnement Vite + Preact handles perfectly SWR, but not Vitest.
When I launch the test, it returns the error : TypeError: Cannot read properties of undefined (reading '__H')
Expected behavior
Vitest + Preact handles SWR in a test environnement, as it is running in dev/prod environnement.
This dual package issue is still partly due to preact's cjs/esm packaging and it cannot be fixed by alias.
Vite bundles it properly, but for example, node cannot handle it either. Here is a simpler reproduction with only use-sync-external-store:
Describe the bug
Hello,
I'm unable to run Preact components using SWR, in test environnement (Vitest).
In dev/prod environnement Vite + Preact handles perfectly SWR, but not Vitest.
When I launch the test, it returns the error :
TypeError: Cannot read properties of undefined (reading '__H')
Expected behavior
Vitest + Preact handles SWR in a test environnement, as it is running in dev/prod environnement.
I opened an issue on PreactJS repo, it seems that vitest loads multiple copies of Preact, so it breaks because it needs to be a singleton.
Reproduction
Barebone example : https://github.com/dolie/preact-swr-vitest-bug
git clone git@github.com:dolie/preact-swr-vitest-bug.git
pnpm i
pnpm vitest
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: