Repository navigation
Vite Websocket Connection Failed #31225
SummaryI have a Rails project using Vite, with hot-module reloading working just fine inside Rails... but Storybook fails completely. Storybook continually retries, and fails, to open the websocket connection to the vite host. The actual error is this (from the browser console log): The network request is showing as I'm super down to keep digging, but I'm kind of at a loss as to where to go from here. I'll see if I can reproduce the issues with the Additional information
/** @type { import('@storybook/react-vite').StorybookConfig } */
const config = {
"stories": [
"../spec/stories/**/*.mdx",
"../spec/stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
"addons": [
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@chromatic-com/storybook",
"@storybook/experimental-addon-test"
],
"framework": {
"name": "@storybook/react-vite",
"options": {}
}
};
export default config;
import { defineConfig } from 'vite'
import ViteRails from 'vite-plugin-rails'
import ViteReactSWC from '@vitejs/plugin-react-swc'
import dynamicImport from 'vite-plugin-dynamic-import'
import ignore from "rollup-plugin-ignore"
export default defineConfig({
base: '/',
plugins: [
ViteRails({
envVars: { RAILS_ENV: 'development' },
fullReload: { additionalPaths: ['config/routes.rb', 'app/views/**/*'] }
}),
ViteReactSWC(),
dynamicImport(),
],
build: {
minify: false,
terserOptions: {
compress: false,
mangle: false,
},
rollupOptions: {
output: {
entryFileNames: `assets/[name]`,
chunkFileNames: `assets/[name]`,
assetFileNames: `assets/[name].[ext]`
},
plugins: [
ignore(["app/javascript/entrypoints/inject_refresh_preamble.js", "/@react-refresh"])
],
}
},
server: {
cors: { origin: '*' },
watch: { usePolling: true },
hmr: { protocol: 'ws' },
}
})Create a reproductionNo response |
Replies: 3 comments 1 reply
|
Dug around a bit - The websocket's |
|
Update; If I'm not running the other Which is in the same execution path as the original error - just further down. Rather than continually retrying the WS connection, it's waiting until the server pings back. So, I think that means: Is Storybook supposed to launch it's own vite-dev server, or...? |
|
Alright - This was kind of silly, and definitely an artefact of the shenanigans I'm trying to pull. This was the file:
{
"all": {
"sourceCodeDir": "app/javascript",
"watchAdditionalPaths": []
},
"development": {
"host": "0.0.0.0",
"autoBuild": true,
"publicOutputDir": "vite-dev",
"port": 6006 // <------------- HERE
},
"test": {
"autoBuild": true,
"publicOutputDir": "vite-test",
"port": 3037
}
}By changing the Rails/Vite default there of 3036 to the Storybook 6006, Storybook can also function as the Rails vite dev server. Neat! (And, when running |
Alright - This was kind of silly, and definitely an artefact of the shenanigans I'm trying to pull.
This was the file:
config/vite.json{ "all": { "sourceCodeDir": "app/javascript", "watchAdditionalPaths": [] }, "development": { "host": "0.0.0.0", "autoBuild": true, "publicOutputDir": "vite-dev", "port": 6006 // <------------- HERE }, "test": { "autoBuild": true, "publicOutputDir": "vite-test", "port": 3037 } }By changing the Rails/Vite default there of 3036 to the Storybook 6006, Storybook can also function as the Rails vite dev server. Neat!
(And, when running
vite devon its own, everything works as expected)