-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
SSR: generated class names are not consistent for client and server bundles since v5.1.3 #1384
Comments
hm, weird, I will look at this in near future |
Also got that error. Downgrade to Node 14 did not solve the problem |
After upgrading to 6.4.0 which contains the fix from #1385, I'm getting this error in my app:
I suspect this is a regression from the other change in that release: #1382 Update: never mind, fixed by changing |
Yes, try to avoid uses very small value for hashes, we have ideas how to improve this for webpack v6, but now we have some limitations with very small value of |
@alexander-akait After updating to 6.4.0, I'm getting classname collisions. I'm trying to figure out how the two change in the release would do that, but reverting to 6.3.0 fixes them. |
And can you provide example of collusion, i.e. |
I'll test that. Here is an example of collision: import { styled } from 'astroturf/react';
import { User } from '../commons';
export const Container = styled.div`
cursor: pointer;
width: 70px;
height: 70px;
display: flex;
align-items: center;
justify-content: center;
img,
svg {
width: 100%;
}
&:global(.flyout-open) {
background-color: white;
box-shadow: -1px 0 0 0 #dcdcdc;
transition: background-color 0.3s, box-shadow 0.3s;
}
`;
export const Box = styled.div`
position: relative;
width: 42px;
height: 42px;
`;
export const Dot = styled(User.Presence)`
position: absolute;
right: 2px;
bottom: 2px;
`; on 6.4.0, each of these has the same class generated. Astrotruf extracts each template string into a virtual
|
@jsg2021 Because we can't rely on As you can see the original post in this issue about this. |
i'm up to do whatever but what is the suggestion here? How would astroturf provide css-loader a hash? I'd love to not use matchResource at all, but that was the path we were led down for doing virtual modules. |
@jquense We need pass to |
ah maybe, that should be fine to provide a hash in the request query...will style and extract loader pass that through when they rewrite the request? That seems a lot better actually. css-loader would use the hash for calculating the class name hashes? |
Should use, if we have
Yes, we need small changes here, but it is not hard to implement |
adding the query to the css-loader itself is a bit harder, we'd have to rewrite the current loader chain with the new option...i think i've done that in the past tho, just a bit messy |
@jquense Does |
The main problem what
|
you'd have the best idea what works. It's a bit frustrating we couldn't have a resourcePath supported out of the box but webpack for these, but i'm sure there is a good reason |
Let's keep open until we solve it |
@alexander-akait who needs to move first? |
ok i'll hang and wait for that then 👍 should i tell users to not upgrade to the latest css-loader until then? |
Yes, better ask to keep old version |
ok let me know if there is anything i can do to help. it is a bit tough to have people pin a minor version of css-loader, esp in frameworks. |
Wondering if any progress is in sight here? We're currently stuck pinning css-loader 6.3.0 within another dependency due to ^6.4.0 incompatibility with astroturf (which is very annoying with our current version of npm – need to upgrade). |
I would also love to not pin css-loader anymore, is there anything i can do here to move this along? I don't think this is just an astroturf issue, anything that uses matchResources (which is now documented on the doc site even) will have a problem here |
@jquense Sorry for delay, I lose context, pinned issue to return to this in near future, sorry again |
For quick refresh: when css-loader hashes classnames, it only looks are resourcePath. which is "wrong" for resources imported with
|
@jquense Will |
@alexander-akait that PR seems to work! do you think that's sufficient? something like |
I think yes, it was my fault, we should not concat such things, I will do release, because no problems with SSR and allow to solve your problem |
Bug report
We are using
css-loader
with server-side rendering (SSR), so we run webpack twice: once for the client and once for the server.For the client, we need to generate CSS files, so we use
mini-css-extract-plugin
in combination withcss-loader
.For the server, we don't need to generate CSS files, so we use
exportOnlyLocals: true
. We just need the CSS modules to export the same class names as the ones used in the CSS files we generated for the client (above).Actual Behavior
Generated class names are not consistent for client and server bundles.
Expected Behavior
Generated class names are consistent for client and server bundles.
How Do We Reproduce?
Full reduced test case: https://github.com/OliverJAsh/webpack-css-loader-ident-hash-bug
package.json
:webpack.config.js
:src/main.js
:src/main.css
:Since this change which first appeared in v5.1.3,
css-loader
generates different class names for the client/server:It seems this is because
css-loader
now usesrelativeMatchResource
as part of the hash, and in this case,relativeMatchResource
will be different depending on whether or not we're usingmini-css-extract-plugin
:MODE=server
(mini-css-extract-plugin
is used):relativeMatchResource
is''
MODE=client
(mini-css-extract-plugin
is not used):relativeMatchResource
is'src/main.css\x00'
We are able to workaround the issue by downgrading to v5.1.2 which does not include this change.
Please paste the results of
npx webpack-cli info
here, and mention other relevant informationThe text was updated successfully, but these errors were encountered: