-
-
Notifications
You must be signed in to change notification settings - Fork 605
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
fix: allow values in selectors to work correctly #894
fix: allow values in selectors to work correctly #894
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. But:
- Need tests.
- Some developers can have same selector and
@value test
, it is potential breaking change.
And it is not bugfix, it is feature, we never support |
yup i'm thinking through the breaking change case, Might make this all opt-in initially... Will definitely add tests |
I would call it a bugfix since the behavior is not supposed to be new, it's specced out by css-modules. That said, it's never worked and it adds new behavior so if you want to call it a feature i understand |
@jquense Let's do this step by step. Please clarify what each PR do:
And how it is related to this PR |
src/plugins/postcss-icss-parser.js
Outdated
|
||
if (typeof importIndex === 'number') { | ||
if (replacement != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not if (replacement) {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be! The old want needed to check for 0
but that's not the case anymore so lets do that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Need fix CI problem with naming commit, please read CONTRIBUTING.md |
Also please accept CLA |
right so there are a few blocks to supporting this: PR: css-modules/postcss-modules-values#2This updates the values plugin so that it also replaces values in selectors. That behavior was always intended but it was using an old version of the icss utils that didn't support it. PR: css-modules/postcss-modules-scope#4Now that selectors are being replaced we run into a problem further down the chain in the scope plugin. With the @value btn-class from './button.module.css'
.toolbar > .btn-class {
margin-left: 10px
} gets turned into: :import('./button.module.css') {
1__const_btn-class-0: btn-class
}
.toolbar > .1__const_btn-class-0 {
margin-left: 10px
} So that's what we want, the value of :local(.toolbar) > :local(.1__const_btn-class-0) {
...
} This leads to the value identifier ( This PRThe reason we need the last step is b/c after that pipeline we need to replace instances of import identifiers with a webpack |
Now that i'm thinking about it, it may be better to change the local by default plugin instead of the scope one...will check that |
Okey, we need major release for this feature, it is normal, but we need more tests here and in plugins |
yes I will add the tests, I wanted to make sure this wasn't going to be rejected out of hand before doing all that :) The lint issue doesn't seem to be because of this. I've got the commit named correctly already i believe |
@jquense just update lock file in other PR: |
/cc @jquense PR looks good, but we have some big problems in some plugins and i think we should solve this problems, need solve #578 as patch release and when merge other PRs as major release. Problem:
Can you help with this? |
sounds good i can work on that yeah 👍 |
@jquense feel free to ping me |
/cc @jquense friendly ping, now we can merge and release new css modules plugins version and release major version |
ok updated the other PR, need that merged and released before I can easily write tests here! |
/cc @jquense need rebase and fix CI, also can you provide link what should be merged first/second/etc, thanks |
/cc @jquense friendly ping |
Sorry, didn't realize I was the bottleneck. Everything is up to date on my end. Waiting on css-modules/postcss-modules-local-by-default#13 to be merged, should have been more clear, realized I just linked the issue |
only css-modules/postcss-modules-local-by-default#13 |
/cc @jquense sorry for very big delay, there are a lot of jobs, can you rebase and we release new version |
@jquense Just clarify, css-modules/postcss-modules-values#2 need merge too? |
03807ba
to
e2ae777
Compare
@evilebottnawi this should be ready now 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, thanks!
/cc @jquense i think we should rewrite https://github.com/css-modules/icss-utils/blob/master/src/replaceValueSymbols.js and use this in our code instead own |
sure I can look into that |
@jquense thanks! |
Let's do release on this week |
/cc @jquense @value v-primary: #BF4040;
@value s-black: 'black-selector'; /* Problem here */
@value m-large: (min-width: 960px);
.primary-selector {
color: v-primary;
}
.s-black {
color: black;
}
@media m-large {
.header {
padding: 0 20px;
}
} I think we should fix it (or maybe better error message) |
what's happening that seems wrong with the example? |
@jquense error when you compile due this line |
I don't think this is a new issue? @value color: 'black';
.s-black {
color: color;
} is possible now and also won't work. Agree that a nicer error would be good but I don't think that's in scope for this PR? |
@jquense I already implement supporting |
Ya you bet 👍 should we close this one then if you've pulled it in otherwise 😁 |
@jquense i keep open issue due we should fix problem what i describe above |
/cc @jquense i can't do release before we can't fix problem with:
|
I'm sorry, i haven't had any time but i still don't understand why this is a blocker. The behavior of it not working is expected and consistent with the current v2 behavior for value interpolation. |
Better, question what do you want it to do? having a selector with quotes is invalid, i don't think we should support that. |
Error like: |
Unfortunately I don't think is no good place to check for and throw this error (unless you have an idea). It would likely involve a big refactor of the css-modules pipeline in order to even notice it since it's related to behavior across multiple postcss plugins. I agree that the behavior isn't great, but it's not new behavior and it's LESS bad than other cases like this which fail silently. I don't think we should make it a release blocker. Overall i'd be happy to work on these things generally but i don't have any access to the key repos or the authority to make larger structural changes necessary to fix these sort of systemic issues with css-modules. Besides yourself no one else is responsive on any repo either |
So we can't fix it in |
I don't think so...you'd only catch the ones for imported values, so your example above would still fail. We could try and put it in the |
Maybe we just throw error on |
Solved in postcss-modules-local-by-default |
I think tomorrow will be release new major version |
awesome! glad you found a solution, I was thinking too hard about it 👍 |
This PR contains a:
Motivation / Use-Case
depends on:
This works to enable behavior that is specced by css-modules, but has been only partially implemented until now; TL; DR; selectors are a valid place for imported values to be interpolated.
Breaking Changes
Maybe! Still thinking through that
Additional Info