-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Missing styles in production (CRA + Emotion 11) #2209
Comments
To give an example, this image shows elements with generated CSS class names, but nothing showing up in the debugger and the style tags for emotion in the I sincerely appreciate any assistance :) |
Are you using |
@tyom - no, I’m not currently using |
It looks like if you would load more than one instance of Emotion - the other one touching style elements if the first ine and thjs them losing injected styles. From what I remember those elements dont lose styles in FireFox - if this works for u in FF it would validate my diagnosis. Could u check this? |
@Andarist - unfortunately I get the same issue in firefox. Something I noticed though is that the styles for our header seem to be applied initially for about a second, and then everything goes missing. We do use code-splitting, and this could be correlated but not the cause, but it seems like when bundle for the first page loads in (after the shell loads in), that's when the styles seem to break / get removed. Not sure if it would be possible for the "multiple instances of emotion" to get loaded in that way. |
@Andarist - it looks like you are right with the multiple versions. I can't believe I didn't try this before, but I removed the one use of I guess my question now becomes, is there any easy way to safely use |
Yes. The exact thing I was suspecting is multiple instances of the |
Checking out my |
It kinda depends on your node_modules layout but I would expect issues to arise when using Storybook and not in your production code. Either way - can't pinpoint it to the very exact problem if I can't investigate the repro case |
Seeing this when upgrading from 10.x.x to 11 as well in my production code, but we're using preact and the standalone(?) version of emotion (emotion -> @emotion/core when we upgraded to 11). I'm working to get together an example of this currently but my scenario is that my company provides a javascript bundle that behaves as a widget. If our javascript file is loaded twice sometimes some of the css classes do not get added to the DOM as a style element. It only appears to be one class for me and my emotion style looks like the following:
We're currently using emotion 10.0.27 and attempted to move to @emotion/core version 11.1.3 |
I believe that you have meant |
I ran into same issue. I am able to resolve with custom code, but compiler of storybook instance is not parsing certain import statement correctly so it throws errors for some stories. What I did? $ cd .storybook
$ touch babel.config.js
module.exports = {
extends: '../../../babel.config.js',
presets: [
'@babel/preset-typescript',
[
'@babel/preset-react',
{
runtime: 'automatic',
importSource: '@emotion/react',
},
],
],
plugins: [
[
'@emotion',
{
sourceMap: true,
autoLabel: 'always',
labelFormat: '[local]',
cssPropOptimization: true,
},
],
],
}; Then, in import { resolve } from 'path';
import webpack from 'webpack';
/**
* Map Emotion 10 libraries to Emotion 11 libraries.
* This function makes a shallow copy of an object, rejecting keys that match /emotion/
*
* Otherwise Storybook fails to compile with "Module not found: Error: Can't resolve '@emotion/styled/base'", etc.
* It wasn't necessary to do this until we imported React component using "@emotion/styled".
* This issue is probably caused because Storybook uses Emotion 10 while we have Emotion 11 used by the Next.js app.
*
* @see https://github.com/storybookjs/storybook/issues/13277#issuecomment-751747964
* @see https://github.com/storybookjs/storybook/issues/12262#issuecomment-681953346
* @see https://emotion.sh/docs/emotion-11#package-renaming
*/
function emotionless<T extends Record<string, unknown>>(object: T) {
let result = {} as T;
for (let key in object) {
if (!/emotion/.test(key)) {
result[key] = object[key];
}
}
return result;
}
export default {
stories: ['../src/**/*.story.@(tsx|mdx)'],
addons: ['@storybook/addon-docs', '@storybook/addon-actions', '@storybook/addon-a11y'],
babel: (config: any) => {
config.plugins = config.plugins.map((plugin: any) => {
if (/emotion/.test(plugin[0])) {
return [
require('@emotion/babel-plugin'),
{
sourceMap: true,
autoLabel: 'always',
labelFormat: '[local]',
cssPropOptimization: true,
},
];
}
return plugin;
});
return config;
},
webpackFinal: async (config: { [key: string]: any }) => {
if (config.resolve.plugins) {
config.resolve.plugins.push(...alias.plugins);
} else {
config.resolve.plugins = alias.plugins;
}
config.devtool = isProductionEnv ? false : 'cheap-module-source-map';
return {
...config,
resolve: {
...config.resolve,
alias: {
...emotionless(config.resolve.alias),
},
},
};
},
}; This https://emotion.sh/docs/@emotion/babel-preset-css-prop plugin loads everything without error but some styles are missing. Storybook is mess right now, had also issues with webpack v4-v5 and still not resolve. If anyone get around with it, let me know. Otherwise just have to wait til storybook bump emotion to v11. |
Does #2361 fix this issue? |
And if so, has it been released yet? |
Hopefully - yes. The repro case for this problem has not been given so I can't say for sure. I have to assume that this has been fixed - if not, please open a new issue with the repro case.
Yes, this has been released in the last 24h. |
Current behavior:
Successfully updated codebase to emotion 11 (from 9) and using the
css
prop in conjunction with craco to override the webpack config and use the@emotion/babel-preset-css-prop
preset. When running locally in development, all styles are applied properly and everything looks good. When building for production however, it seems like there are styles missing throughout the app.To reproduce:
I don't have a repro case as this is in app, I'm hoping I've just missed a step or something else obvious.
Environment information:
react
version: 17.0.1@emotion/react
version: 11.1.4The text was updated successfully, but these errors were encountered: