Skip to content

Commit 5ce7dc1

Browse files
cursoragentskovhus
andcommitted
Remove 'Dynamic styles inside pseudo elements' warning
StyleX now supports dynamic styles inside ::before/::after pseudo elements (facebook/stylex#1396 is closed). Remove the bail/error warning that fired when tryHandleDynamicPseudoElementViaCustomProperty could not handle a case — instead, fall through to the remaining interpolation handlers. The custom property workaround itself is preserved as one valid strategy; cases it cannot handle now proceed to other handlers instead of bailing the entire declaration. Co-authored-by: Kenneth Skovhus <skovhus@users.noreply.github.com>
1 parent 84c0da8 commit 5ce7dc1

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

src/internal/logger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export type WarningType =
4747
| "Resolved border helper value could not be expanded to longhand properties"
4848
| "Resolved conditional border variant could not be expanded to longhand properties"
4949
| "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)"
50-
| "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396"
5150
| "Failed to parse theme expressions"
5251
| "Heterogeneous background values (mix of gradients and colors) not currently supported"
5352
| "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported"

src/internal/lower-rules/rule-interpolated-declaration.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,10 @@ export function handleInterpolatedDeclaration(args: InterpolatedDeclarationConte
319319
) {
320320
continue;
321321
}
322-
// Dynamic styles inside ::before/::after pseudo-elements are not natively supported
323-
// by StyleX (see https://github.com/facebook/stylex/issues/1396).
324-
// Workaround: use CSS custom properties set as inline styles on the parent element,
325-
// referenced via var() in the pseudo-element's static StyleX styles.
326322
if (isPseudoElementSelector(pseudoElement)) {
327323
if (tryHandleDynamicPseudoElementViaCustomProperty(args)) {
328324
continue;
329325
}
330-
warnings.push({
331-
severity: "error",
332-
type: "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396",
333-
loc: decl.loc,
334-
context: { pseudoElement },
335-
});
336-
bail = true;
337-
break;
338326
}
339327
if (
340328
tryHandleInterpolatedBorder(
@@ -2326,7 +2314,8 @@ function isPseudoElementSelector(pseudoElement: string | null): boolean {
23262314
* Output: StyleX → `"::after": { backgroundColor: "var(--Badge-after-backgroundColor)" }`
23272315
* Inline → `style={{ "--Badge-after-backgroundColor": $badgeColor }}`
23282316
*
2329-
* Bails (returns false) for unsupported shapes: multi-slot interpolations or CSS shorthands.
2317+
* Returns false for shapes it cannot handle (multi-slot interpolations, CSS shorthands,
2318+
* theme access); callers fall through to other handlers.
23302319
*/
23312320
function tryHandleDynamicPseudoElementViaCustomProperty(
23322321
args: InterpolatedDeclarationContext,

test-cases/selector-dynamicPseudoElement.input.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import styled from "styled-components";
22

33
/**
44
* Test case for dynamic styles in pseudo elements (::before / ::after).
5-
* Uses CSS custom properties as a workaround for StyleX's limitation
6-
* with dynamic values inside pseudo elements.
7-
* See: https://github.com/facebook/stylex/issues/1396
5+
* Uses CSS custom properties on the parent element, referenced via var()
6+
* in the pseudo-element's static StyleX styles.
87
*/
98
const Badge = styled.span<{ $badgeColor: string }>`
109
position: relative;

test-cases/selector-dynamicPseudoElement.output.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ type BadgeProps = React.PropsWithChildren<{
77

88
/**
99
* Test case for dynamic styles in pseudo elements (::before / ::after).
10-
* Uses CSS custom properties as a workaround for StyleX's limitation
11-
* with dynamic values inside pseudo elements.
12-
* See: https://github.com/facebook/stylex/issues/1396
10+
* Uses CSS custom properties on the parent element, referenced via var()
11+
* in the pseudo-element's static StyleX styles.
1312
*/
1413
function Badge(props: BadgeProps) {
1514
const { children, badgeColor } = props;

0 commit comments

Comments
 (0)