Open nandhiniG opened 4 days ago
To resolve the issue with show code
not displaying component names correctly in the production build, follow these steps:
main.ts
includes proper handling for component names in production.import { type StorybookConfig } from '@storybook/react-vite';
import { mergeConfig } from 'vite';
const config = {
// ... other configurations
async viteFinal(config) {
return mergeConfig(config, {
optimizeDeps: {
include: ['storybook-dark-mode', '@adaptavant/*'],
},
resolve: {
alias: {
'next/router': 'next-router-mock',
},
},
build: {
rollupOptions: {
output: {
manualChunks: {
react: ['react'],
},
},
},
sourcemap: true, // Ensure sourcemaps are enabled
},
});
},
} satisfies StorybookConfig;
export default config;
Check Storysource Addon: Verify that the @storybook/addon-storysource
is correctly configured to handle component names.
Component Display Names: Ensure that all components have display names set explicitly, especially for forwarded ref components.
const MyComponent = React.forwardRef((props, ref) => {
// component implementation
});
MyComponent.displayName = 'MyComponent';
These steps should help in resolving the issue with component names in the production build.
/code/.storybook/main.ts /code/addons/storysource /code/lib/codemod/src/transforms/testfixtures/storiesof-to-csf /code/lib/codemod/src/transforms/testfixtures/update-organisation-name /code/lib/codemod/src/transforms/testfixtures/add-component-parameters
Component Display Names actually works ! the vite config didnt help ... but is there any other way we can address this ? because this includes adding displayName for all components
Describe the bug
Show code
displays transformed component names and[object Object]
for forwarded ref components in prod build.In Dev Mode :
![AnySnap 03 Jul 2024 at 10_23_00 AM](https://github.com/storybookjs/storybook/assets/18346603/9b630358-df15-4378-992a-79b6c4b44f51)
In prod build:
![AnySnap 03 Jul 2024 at 10_23_20 AM](https://github.com/storybookjs/storybook/assets/18346603/b40d73e4-ab64-4b7b-b33d-771a7b1d8cce)
main.ts
Reproduction link
https://earth.anywhere.co/storybook/index.html?path=/docs/components-button--docs
Reproduction steps
1)Use storybook react + vite project 2) Add component examples 3) Run in dev mode we can see the component code is as expected in the show code. 4)Run in prod mode, using a HTTP server the component names are messed up
System
Additional context
We identified partial issue is reported and see a fix released in 8.0.2 , we tried the same but the issue still persists https://github.com/storybookjs/storybook/pull/26566