-
Notifications
You must be signed in to change notification settings - Fork 12k
css warning "variable '--some-var' is undefined" #8289
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
Thanks for reporting this issue. However, this issue is a duplicate of an existing issue #1253. Please subscribe to that issue for future updates. |
@filipesilva this issue is about native css variables. Including a variables file make sense for #1253 and scss, but not in this case. Here, the global css code will be added to the bundle for each include. (#1253 is more about the need to specify a relative path, scss variable declaration is removed in compilation) Can you please take a second look, Thank you! |
Thank you for making that clear, I saw the I don't have an answer for it right now though... |
Currently The most appropriate solution would be to only enable the plugin when the app needs to support browsers that do not have native css variable support. |
@clydin I ran into the same issue, and your explanation makes sense. My project only uses default CSS, and is targeting supported browsers only, so your solution would be ideal in my situation too. Although I only get the issue in cli 1.5 as I compile without AOT. If AOT is enabled, the warning is gone. Not sure why that happens. |
Also, using native css only (no scss) and got the same problem. Eagerly awaiting a fix for this. |
@clydin This feature is really a nice to have (I was the one who requested it) but it should be only enabled in production as not to have warnings everywhere - at least if there is no fix in the horizon-. It seems like a PR has been submitted to silence the warning. Even freaking @LeaVerrou chimed in on this.. So yeah, I'm not sure if hiding all warnings is a solution but I guess it could be one for the time being at least.. |
I don't think we should just suppress the warning. Having |
The problem is more serious than the issue title. Here are details on what @varoot explained : If you serve your app in AOT with Given this code in :root {
--my-color: red;
} And this code in a component : p {
color: var(--my-color);
} the final CSS produced will be : p {
color: var(--my-color);
color: var(--my-color);
} But if I use the CSS var in p {
color: red;
color: var(--my-color);
} So it's like the CSS variables declared in The issue should be renamed and silencing the warnings won't solve the problem. I also don't understand @clydin proposition :
The problem is here in all cases. So currently this feature doesn't have a lot of sense, as being limited to use CSS variables just inside |
@cyrilletuzi Maybe it would be solves by just making sure global styles are included before the component styles in the webpack config webpack-configs/styles.ts? |
It will work for browsers supporting CSS variables, but not for old browsers. Then what's the point of the |
See this comment in the initial PR
|
I agree with @cyrilletuzi , it really should be done right or we need to roll it back out. I didn't understand enough about how the CSS build chain worked and I presumed my PR would work since it covered all my use cases. The warning will show up since the variable was not defined. Also, it would be good to make it an optional step instead to enable support for IE11. Otherwise there's no reason to have this feature. Since the other Polyfills are brought in optionally, this, too, should be. |
As I mentioned in my previous comment, the plugin can only work if it has full knowledge of the CSS variables at build time. The plugin is a build time processing step that alters the stylesheet to mimic the behavior of CSS variables (in certain situations). The plugin, therefore, cannot work if the variables are split between global and component styles as they exist in different contexts at build time. The plugin should also not be used if only browsers with native support are used since the browser can support the full spectrum of css variable usage. This is actually how cssnext uses the plugin (via a browsers list check). |
My first shot at the PR was to use cssnext instead, but it pulled a LOT of dependencies, some of which were licensed in ways that precluded us from using them in Angular CLI (e.g. public domain). |
I agree in its current state the plugin doesn't make much sense for Angular CLI projects. Component styles would be able to transform CSS props only if they themselves included definitions of the variables on Therefore, in projects following best practices the only thing the plugin does in component styles is produce lots of warnings during the build and duplicate CSS rules during development (which clutters the view in DevTools). |
Let me see if I understand this accurately
So basically this plugin is only useful for people who wants to support legacy browser and only have one big global stylesheet (or define variables in each of the global stylesheets where it's use) That really doesn't seem very useful and it might be better to just remove it.
|
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix angular#8289
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix angular#8289
Has this already been fixed in a release? We still get lots of these warnings in v1.6.1. |
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix angular#8289
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix #8289
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix #8289
Just for reference. Bulma maintaner have added a variable that can remove those wornings, |
We currently use a fallback for CSS custom properties on older browsers. This approach has a few problems: - does not work if the custom property declaration is not part of the same of the same file that uses it (multiple global stylesheets, component css). - does not work at all for component CSS in AOT. @clydin suggested a browserlist based approach for enabling this functionality, but that requires a new feature that we don't have. Since currently taking advantage of the custom property fallback is flaky even in the best case scenario, and potentially broken in prod (AOT), I think it's better to remove it altogether until we can actually do it right. Fix angular#8289
We depend on |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
Angular CLI: 1.5.0
Node: 8.9.0
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.0
@angular/flex-layout: 2.0.0-beta.10
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack: 3.8.1
Repro steps.
add to global
styles.scss
:add to some component
scss
:ng serve
The log given by the failure.
Desired functionality.
no warning needed, the component is defined in the global
styles.scss
and everything worksMention any other details that might be useful.
one workaround is the create a
_variables.scss
with all the global:root { --my-var ... }
and include this files in components. This will make to warning go away but the declarations in_variables.scss
will be included few timesThe text was updated successfully, but these errors were encountered: