-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
server.handleUpgrade invalid configuration for Storybook with unstable vite plugin #7953
Comments
Thanks for reporting the issue.
I'm not so familiar with recent storybook ecosystem, but from the quick look of their vite/react integration, you might not need "remix" plugin integrated into storybook (though I still don't know what it means by "integrating" exactly). If that's the case, then similar to what I suggested to workaround when using vitest #7918 (comment), one quicker-and-dirtier approach to filter out "remix" plugin when running storybook could be something like: // vite.config.ts
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [
// turn it off based on executed js entry file
!process.argv[1].endsWith("storybook/index.js") && remix(),
tsconfigPaths()
],
}); I made a reproduction here https://github.com/hi-ogawa/test-remix-vite-storybook/blob/165e95f8de119a666f959f26673ce59179938540/vite.config.ts#L7 and this trick seems to work on my PC (linux) at least. I picked up some potentially relevant code if remix team wants to investigate further:
|
Hi @hi-ogawa , by
I mean that as you mention, storybook should just work with their react plugin without any problem even if remix plugin is provided in vite configuration. The trick seems not working with index.js but just checking if the arg include storybook, seems ok on my side // vite.config.ts
import { unstable_vitePlugin as remix } from '@remix-run/dev';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
plugins: [
!process.argv[1]?.includes('storybook') && remix(),
tsconfigPaths(),
],
esbuild: {
jsx: 'automatic',
},
}); |
Thanks for confirming it, also nicer workaround! I was wondering what svelte ecosystem would do and I found that it looks like storybook "supports" svelte/sveltekit by providing dedicated // disable specific plugins that are not compatible with Storybook
plugins = (
await withoutVitePlugins(plugins, [
'vite-plugin-sveltekit-compile',
'vite-plugin-sveltekit-guard',
])
).concat(configOverrides()); So, if remix would follow this "trend", then probably it's unlikely that remix is going to deal with storybook integration by itself, but some sort of workaround might be better fit on storybook side. |
I'm also receiving this error. I'm trying to integrate vite with remix plugin to existing express app where I already have a websocket server: vite.createServer({
appType: 'custom',
server: {
middlewareMode: true,
hmr: {
path: '/hmr',
server: httpServer,
},
},
}) Because remix plugin is creating it's own child vite server: https://github.com/remix-run/remix/blob/main/packages/remix-dev/vite/plugin.ts#L596 http server instance is passed to this child. Then vite registers two 'upgrade' handlers to the same server https://github.com/vitejs/vite/blob/f576d98265f7db6f09218aeab024ccdc1a82d467/packages/vite/src/node/server/ws.ts#L136 Later when the websocket is connected |
@Mordred Thanks, nice find! Currently child compiler is used only for remix/packages/remix-dev/vite/plugin.ts Lines 214 to 225 in fd8d3a2
so I think child compiler doesn't need any of websocket/hmr feature, but it seems In this case, however, I think it would work fine if remix simply pass |
@markdalgleish #8123 is only adding some documentation, but this bug is not fixed. Can you reopen this issue until #8095 is solved? |
Thanks .. you are right. I was testing v2.3.1 .. Good job |
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
Expected Behavior
The storybook dev server should correctly run and integrate with remix vite server and showing onboarding stories stored in stories folder
Actual Behavior
Seems remix plugin is creating an exception causing the following error
Error: server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration at WebSocketServer.completeUpgrade (file:///Users/donato.leone/projects/rox/homelink/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:61573:13) at WebSocketServer.handleUpgrade (file:///Users/donato.leone/projects/rox/homelink/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:61549:10) at Server.hmrServerWsListener (file:///Users/donato.leone/projects/rox/homelink/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:61788:21) at Server.emit (node:events:526:35) at onParserExecuteCommon (node:_http_server:942:14) at onParserExecute (node:_http_server:836:3)
Seems a problem with vite plugin because changing viteFinal in main.ts excluding remix plugins, storybook works as expected
The text was updated successfully, but these errors were encountered: