Skip to content

Commit 82c3013

Browse files
authored
refactor: remove css variables feature flag (#4337)
Css variables are landed. No need for conditional rendering.
1 parent 0c25e50 commit 82c3013

File tree

8 files changed

+12
-51
lines changed

8 files changed

+12
-51
lines changed

apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator-tree.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { nanoid } from "nanoid";
33
import { atom, computed } from "nanostores";
44
import { mergeRefs } from "@react-aria/utils";
55
import { useStore } from "@nanostores/react";
6-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
76
import {
87
Box,
98
rawTheme,
@@ -481,7 +480,7 @@ export const NavigatorTree = () => {
481480
}}
482481
>
483482
<TreeRoot>
484-
{isFeatureEnabled("cssVars") && rootMeta && (
483+
{rootMeta && (
485484
<TreeNode
486485
level={0}
487486
isSelected={selectedKey === ROOT_INSTANCE_ID}

apps/builder/app/builder/features/style-panel/property-label.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { atom } from "nanostores";
22
import { useStore } from "@nanostores/react";
33
import { useState, type ReactNode } from "react";
44
import { AlertIcon, ResetIcon } from "@webstudio-is/icons";
5-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
65
import {
76
hyphenateProperty,
87
toValue,
@@ -55,7 +54,7 @@ const renderCss = (styles: ComputedStyleDecl[], isComputed: boolean) => {
5554
for (const styleDecl of styles) {
5655
const property = hyphenateProperty(styleDecl.property);
5756
let value;
58-
if (isComputed && isFeatureEnabled("cssVars")) {
57+
if (isComputed) {
5958
value = toValue(styleDecl.usedValue);
6059
} else {
6160
value = toValue(styleDecl.cascadedValue);

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { useStore } from "@nanostores/react";
1212
import { computed } from "nanostores";
1313
import { matchSorter } from "match-sorter";
14-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
1514
import { PlusIcon } from "@webstudio-is/icons";
1615
import {
1716
Box,
@@ -123,9 +122,6 @@ const matchOrSuggestToCreate = (
123122
const matched = matchSorter(items, search, {
124123
keys: [itemToString],
125124
});
126-
if (isFeatureEnabled("cssVars") === false) {
127-
return matched;
128-
}
129125
const propertyName = search.trim();
130126
if (
131127
propertyName.startsWith("--") &&
@@ -149,9 +145,7 @@ const getNewPropertyDescription = (item: null | SearchItem) => {
149145
};
150146

151147
const insertStyles = (text: string) => {
152-
const parsedStyles = parseCss(`selector{${text}}`, {
153-
customProperties: true,
154-
});
148+
const parsedStyles = parseCss(`selector{${text}}`);
155149
if (parsedStyles.length === 0) {
156150
return false;
157151
}

apps/builder/app/builder/features/style-panel/shared/css-fragment.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ import {
99
} from "@codemirror/autocomplete";
1010
import { parseCss } from "@webstudio-is/css-data";
1111
import { css as style } from "@webstudio-is/design-system";
12-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
1312
import {
1413
CodeEditorBase,
1514
getMinMaxHeightVars,
1615
} from "~/builder/shared/code-editor-base";
1716
import { $availableVariables } from "./model";
1817

1918
export const parseCssFragment = (css: string, fallbacks: string[]) => {
20-
let parsed = parseCss(`.styles{${css}}`, {
21-
customProperties: isFeatureEnabled("cssVars"),
22-
});
19+
let parsed = parseCss(`.styles{${css}}`);
2320
if (parsed.length === 0) {
2421
for (const fallbackProperty of fallbacks) {
25-
parsed = parseCss(`.styles{${fallbackProperty}: ${css}}`, {
26-
customProperties: isFeatureEnabled("cssVars"),
27-
});
22+
parsed = parseCss(`.styles{${fallbackProperty}: ${css}}`);
2823
parsed = parsed.filter((styleDecl) => styleDecl.value.type !== "invalid");
2924
if (parsed.length > 0) {
3025
break;

apps/builder/app/shared/style-object-model.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const createModel = ({
4646
matchingStates?: Set<string>;
4747
}): StyleObjectModel => {
4848
const instanceTags = new Map<Instance["id"], HtmlTags>();
49-
const parsedStyles = parseCss(css, { customProperties: true });
49+
const parsedStyles = parseCss(css);
5050
const styles: Styles = new Map();
5151
for (const { breakpoint, selector, state, property, value } of parsedStyles) {
5252
const styleDecl: StyleDecl = {
@@ -77,7 +77,7 @@ const createModel = ({
7777
}
7878
const presetStyles = new Map<string, StyleValue>();
7979
for (const [componentName, css] of Object.entries(presets ?? {})) {
80-
const parsedStyles = parseCss(css, { customProperties: true });
80+
const parsedStyles = parseCss(css);
8181
for (const styleDecl of parsedStyles) {
8282
const key = getPresetStyleDeclKey({
8383
component: componentName,

packages/css-data/src/parse-css.test.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -406,27 +406,15 @@ describe("Parse CSS", () => {
406406
]);
407407
});
408408

409-
// @todo https://github.com/webstudio-is/webstudio/issues/3399
410-
test("parse variable as unset default", () => {
411-
expect(parseCss(`a { color: var(--color) }`)).toEqual([
412-
{
413-
selector: "a",
414-
property: "color",
415-
value: { type: "keyword", value: "unset" },
416-
},
417-
]);
418-
});
419-
420-
test("optionally parse variable as var value", () => {
409+
test("parse variable as var value", () => {
421410
expect(
422411
parseCss(
423412
`
424413
a {
425414
color: var(--color);
426415
background-color: var(--color, red);
427416
}
428-
`,
429-
{ customProperties: true }
417+
`
430418
)
431419
).toEqual([
432420
{

packages/css-data/src/parse-css.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ const unprefixProperty = (property: string) => {
5757

5858
const parseCssValue = (
5959
property: string,
60-
value: string,
61-
{ customProperties }: { customProperties: boolean }
60+
value: string
6261
): Map<StyleProperty, StyleValue> => {
6362
const expanded = new Map(expandShorthands([[property, value]]));
6463
const final = new Map();
@@ -70,12 +69,6 @@ const parseCssValue = (
7069
continue;
7170
}
7271

73-
// @todo https://github.com/webstudio-is/webstudio/issues/3399
74-
if (customProperties === false && value.includes("var(")) {
75-
final.set(property, { type: "keyword", value: "unset" });
76-
continue;
77-
}
78-
7972
final.set(
8073
property,
8174
parseCssValueLonghand(
@@ -101,12 +94,7 @@ type Selector = {
10194
state?: string;
10295
};
10396

104-
type ParserOptions = {
105-
customProperties?: boolean;
106-
};
107-
108-
export const parseCss = (css: string, options: ParserOptions = {}) => {
109-
const customProperties = options.customProperties ?? false;
97+
export const parseCss = (css: string) => {
11098
const ast = cssTreeTryParse(css);
11199
const styles = new Map<string, ParsedStyleDecl>();
112100

@@ -231,8 +219,7 @@ export const parseCss = (css: string, options: ParserOptions = {}) => {
231219

232220
const parsedCss = parseCssValue(
233221
unprefixProperty(node.property),
234-
stringValue,
235-
{ customProperties }
222+
stringValue
236223
);
237224

238225
for (const { name: selector, state } of selectors) {

packages/feature-flags/src/flags.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export const internalComponents = false;
44
export const unsupportedBrowsers = false;
55
export const aiRadixComponents = false;
66
export const cms = false;
7-
export const cssVars = false;
87
export const filters = false;
98
export const xmlElement = false;
109
export const staticExport = false;

0 commit comments

Comments
 (0)