solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.47k stars 927 forks source link

Vitest, pnpm and "You appear to have multiple instances of Solid" #2205

Closed jtmueller closed 4 months ago

jtmueller commented 4 months ago

Describe the bug

Using Vitest to test a SolidJS project results in one instance of the following error for each test suite: "You appear to have multiple instances of Solid. This can lead to unexpected behavior."

And one instance of this error per test: "computations created outside a createRoot or render will never be disposed"

But this only happens when pnpm is used as the package manager. I recognize that you'll probably tell me this isn't a SolidJS bug, and I can't blame you for that. However, I have never come across any suggestions that the package manager might be at fault in all of the time I've spent searching for solutions to this issue. I have tried so many different vite.config settings and none of them have done any good, so I'm hoping that someone else in this situation might come across this issue even if it's closed.

Also, I'm not sure what's actually going on here, and I would welcome any suggestions as to whether this is a Vitest issue or a Pnpm issue, and how to report it in a way that won't be immediately bounced back as not their problem.

Or maybe there's a workaround in the vitest config?

Your Example Website or App

https://github.com/solidjs/templates/tree/main/ts-vitest

Steps to Reproduce the Bug or Issue

1.npx degit solidjs/templates/ts-vitest solid-vitest

  1. cd solid-vitest
  2. pnpm i
  3. pnpm run test

You will see messages like:

stderr | file:/Users/user/dev/solid-vitest/node_modules/.pnpm/solid-js@1.8.11/node_modules/solid-js/dist/dev.js:1747:67
You appear to have multiple instances of Solid. This can lead to unexpected behavior.

stderr | src/todo-list.test.tsx > <TodoList /> > it will render an text input and a button
computations created outside a `createRoot` or `render` will never be disposed

stderr | src/todo-list.test.tsx > <TodoList /> > it will add a new todo
computations created outside a `createRoot` or `render` will never be disposed

stderr | src/todo-list.test.tsx > <TodoList /> > it will mark a todo as completed
computations created outside a `createRoot` or `render` will never be disposed

Now you can run rm -rf node_modules and try installing and running the tests with either npm or bun and the errors will not occur.

Expected behavior

As a user, I expected vitest and solidjs to work regardless of which package manager I use.

Screenshots or Videos

No response

Platform

Additional context

No response

atk commented 4 months ago

The issue is in https://github.com/solidjs/templates, which currently seems unmaintained. My last PRs to fix this were ignored, so I closed them.

As a workaround, you can run pnpm update, especially for vitest and vite-plugin-solid, which fixes the issue.

jtmueller commented 4 months ago

@atk Thanks for that. I thought I had found an isolated repro case for my actual problem, where my project gets these errors even with the latest libraries installed. Turns out it also gets these errors when npm or bun is used, and whatever was causing them in the templates must be unrelated to what was causing them in my project.

Maybe I'll try adding other solid-related dependencies that my real project has, to the template project, see if I can find a cause.