Fix leaking CSS variables
See original GitHub issueDescribe the bug Non-inherited CSS properties are being inherited thanks to the shared CSS variable declaration (they have the same name).
This is OK behaviour for properties that inherit - not ok for ones that shouldn’t.
To Reproduce Steps to reproduce the behavior:
import React from 'react';
import { styled } from '@compiled/core';
const Box = styled.div<{ border?: string }>`
border: ${(props) => props.border || ''};
`;
export const NestedWithDynamicValues = () => (
<Box border="2px solid red">
Should have border
<Box>Should not have border</Box>
</Box>
);
Expected behavior
Nested Box should not have a border.
Additional context
We can fix this by unsetting the CSS variable when it resolves to undefined.
--value: ;
Currently we resolve to an empty string if it has a prefix/suffix - to fix this we will probably have to always do it for everything.
Testing notes
- Css prop interpolations
- Styled component interpolations
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
150728 – leaks seen in fast/css/variables tests - WebKit Bugzilla
SUMMARY CSSParserValueList leaks seen in fast/css/variables tests. * STEPS TO REPRODUCE shell> run-webkit-tests --leaks -1 ...
Read more >Utilizing CSS variables caused a browser behavior that leaks ...
Using the CSS variables will cause the browser to request the background image twice. If there are multiple links like this, each one...
Read more >[css-variables] Custom properties are slow when setting them ...
[css-variables] Clone style when there are no variable references. When resolving the CSS Custom Properties inheritance, we recalculate all
Read more >postcss-css-variables | Yarn - Package Manager
PostCSS plugin to transform CSS Custom Properties (CSS variables) syntax into a static representation. This plugin provides a future-proof way of using most ......
Read more >4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
In the context of JavaScript, unwanted references are variables kept ... However, leaks that are periodic are bugs and must be fixed.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Actually I thought you will do on Monday and I should not do it 😛. But then we discussed and did today hehehehe.
No worries mate ❤️