Skip to content
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

Built SB has odd selectors that is being applied #59

Closed
tounsoo opened this issue Aug 6, 2024 · 4 comments · Fixed by #63
Closed

Built SB has odd selectors that is being applied #59

tounsoo opened this issue Aug 6, 2024 · 4 comments · Fixed by #63
Labels
bug Something isn't working

Comments

@tounsoo
Copy link

tounsoo commented Aug 6, 2024

Hey team, I noticed some discrepancies between the dev mode vs built files.

For example, & li+li appears on a built files which has higher priorities than the css I have for my components. (I am using CSS at-layers rule for my components)

Screenshot of built

image
image

Build

https://tounsoo.github.io/margin-ds/?path=/story/component-listbox--default

SB team response

On further inspection it looks like it might be an issue with storybook-rsbuild. At least if you check out the build output from React+Vite and React+Webpack examples, you'll see the <style> tag will contain this:
image
but in your example it's minified+compiled, which produces the wrong selector.
It could also be a webpack-plugin in your setup that compiles the styles wrong, not supporting the CSS nesting syntax with &.
If you could create a minimal reproduction and open a bug report that would be great 👍

@fi3ework
Copy link
Member

fi3ework commented Aug 7, 2024

Could you provide a minimal reproduction. I tried to visit https://github.com/tounsoo/margin-ds, but it seems to be a private repository at the moment.

@fi3ework fi3ework added need reproduction A minimal reproduction is needed to troubleshoot the issue. bug Something isn't working labels Aug 7, 2024
@fi3ework
Copy link
Member

fi3ework commented Aug 7, 2024

Confirmed. The code on the left side is the source code, the selector is nested in sb-errordisplay, whereas in the right output, no parent selector anymore.

image

@fi3ework
Copy link
Member

fi3ework commented Aug 7, 2024

The root cause is terser/html-minifier-terser#177.

As for this won't happen in Vite or webpack5 builder, is because html-minify options here will be merged with Rsbuild's default options(https://github.com/rspack-contrib/rsbuild-plugin-html-minifier-terser/blob/38897bccc4330f9191e5d7c9ea54f8e7f5f76015/src/index.ts#L56-L68), which enabled minifyCSS and triggered the issue above.

To resolve the problem, we should simply align with webpack builder's config (https://github.com/storybookjs/storybook/blob/bbfdf5897e399f65368ca2ed14930b912e466a25/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts#L184-L189) strictly, stop from merging with the default options in rsbuild-plugin-html-minifier-terser.

@fi3ework fi3ework removed the need reproduction A minimal reproduction is needed to troubleshoot the issue. label Aug 8, 2024
@tounsoo
Copy link
Author

tounsoo commented Aug 8, 2024

Just updated to the 0.0.11 and confirmed it fixed this issue! Thank you so much for quick response and release 🙏

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants