-
Notifications
You must be signed in to change notification settings - Fork 14
opt-out mechanism for unavoidable global CSS scenarios #78
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
Comments
I see your problem, using /* @cssmodules-pure: false */
::view-transition-group(modal) {
animation-timing-function: ease-in-out;
}
/* Re-enable pure mode */
/* @cssmodules-pure: true */
.component {
color: blue;
} potentially has performance issues when searching for comments (binary search using ranges for start and end, not all module implementations use AST), that's why ts doesn't have them and have only complete disable for file or disable by lines, since this is quite a rare case and tracking the start and end can take quite a bit of time I would suggest going the other way and using only inline comments: /* @cssmodules-pure-ignore */
#stripe-modal-backdrop {
background: rgba(0, 0, 0, 0.5);
}
.test,
.foo,
.bar,
/* @cssmodules-pure-ignore */
#stripe-modal-backdrop {
background: rgba(0, 0, 0, 0.5);
} |
thanks @alexander-akait for the feedback! Good point with the parsing - haven't thought about that. I see two ways /* @cssmodules-pure-ignore */
#stripe-modal-backdrop {
background: rgba(0, 0, 0, 0.5);
/* @cssmodules-pure-ignore */
animation-name: foo;
}
/* or */
/* @cssmodules-pure-ignore-next-line */
#stripe-modal-backdrop {
background: rgba(0, 0, 0, 0.5);
/* @cssmodules-pure-ignore-next-line */
animation-name: foo;
} I'll start working on a PR and will try to implement the basic ignore logic Please let me know once you chose the best fitting comment |
@jantimon Looks good for me |
Following some popular libraries among styling and linting, I suggest to skip the
|
I am fine without |
postcss-modules-local-by-default
enforces pure CSS Modules by requiring all styles to be locally scoped, with:global
only being allowed within:local
wrappers. Generally this is exactly the desired behavior, but there are several cases where it is hardly possible to use pure CSS Modules:1. third-party integration scenarios
when integrating third-party services that inject their own DOM nodes with React Portals there are sometimes cases where we need to style elements outside of our component tree:
2. new platform apis
The View Transitions API is a good example of where pure CSS Modules are very hard to use:
3. global animations
Right now it is not possible to target global animations e.g.:
Solution in similar tools
One tool which limits the usage of javascript is typescript - but it allows disabling this for edge cases e.g.:
Proposal:
We could add something similar to css modules to allow explicitly opting-out
Alternative syntax options could include:
I believe this would keep the current behaviour of postcss-modules-local-by-default as it is today and also offer an escape hatch in very special edge case scenarios. The advantages might be obvious (because of the learnings from typescript or one of these other tools):
How would you design such an opt-out?
I can help test different approaches and create a PR once we figure out how to move on
The text was updated successfully, but these errors were encountered: