Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core)!: reset.css reaches ::before, ::after, ::placeholder and search fields (#7355)

Christopher Chedeau7ec7d16d380e
diff --git a/.changeset/reset-css-now-reaches-before-after-placeholder-a-kgb9.md b/.changeset/reset-css-now-reaches-before-after-placeholder-a-kgb9.md
new file mode 100644
index 0000000000..171277d7b1
--- /dev/null
+++ b/.changeset/reset-css-now-reaches-before-after-placeholder-a-kgb9.md
@@ -0,0 +1,11 @@
+---
+'@astryxdesign/core': minor
+---
+
+[breaking] `reset.css` now reaches `::before`, `::after`, `::placeholder` and the search field's cancel button, as its comments document. Three of its rules wrote the pseudo-element inside `:where()`, where pseudo-elements are invalid, so browsers dropped those parts of the selector and the rules never applied to them. Each pseudo-element now follows the `:where()`, as in `:where(*)::before`, and the rules stay in `@layer reset`, so any later layer or unlayered style still overrides them.
+
+What changes on a page that loads the reset: a `::before` or `::after` with padding or a border used to size as `content-box` and now sizes as `border-box`; setting only `border-width` on one used to draw nothing and now draws a solid `currentColor` border; a placeholder with no color of its own used to show the browser's grey and now shows `--color-text-secondary` (or that token's own default, `light-dark(#4E606F, #AAAFB5)`, when no Astryx CSS defines it); and a `type="search"` field no longer shows the browser's cancel button.
+
+To keep the old result for one of your own elements, set it in your own CSS: `box-sizing: content-box` or `border-style: none` on the pseudo-element, a `color` on the `::placeholder`, or `appearance: auto` on the field's `::-webkit-search-cancel-button`. There is no codemod: whether a stylesheet relied on the old result cannot be read from its source.
+
+@vjeux
diff --git a/.github/pages/assets/manifest.json b/.github/pages/assets/manifest.json
index d671650932..4b259a3e24 100644
--- a/.github/pages/assets/manifest.json
+++ b/.github/pages/assets/manifest.json
@@ -6,7 +6,7 @@
},
"files": {
"reset.css": {
- "sha256": "b949d5c8442bb43cce0bfd11fcea19614eba43557ade5f4fb05a1686335726f9"
+ "sha256": "b4d429b96882389b18b8df23086a686eda7c8427c66d5089c86969b2fc754323"
},
"astryx.css": {
"sha256": "bc66e60ffeb0eb3b2f2b303d89ba6bae1e7e922b10bb380f7b25624d73c765ba"
diff --git a/.github/pages/assets/reset.css b/.github/pages/assets/reset.css
index d4677d7711..19246aad50 100644
--- a/.github/pages/assets/reset.css
+++ b/.github/pages/assets/reset.css
@@ -13,7 +13,7 @@
* - Removes default margins, padding, and list styles
* - Makes images block-level and responsive
* - Resets form elements to inherit font styles
- * - Uses :where() for zero specificity (easy to override)
+ * - Uses :where() for zero specificity (pseudo-elements go outside it)
*
* Usage:
*
@@ -46,7 +46,7 @@
* Use border-box globally. Prevents padding/border from affecting
* element dimensions — the single most impactful reset.
*/
- :where(*, *::before, *::after) {
+ :where(*), :where(*)::before, :where(*)::after {
box-sizing: border-box;
}
@@ -54,7 +54,7 @@
* Reset borders to 0-width solid. This lets you add a border by just
* setting border-width — no need to also specify border-style.
*/
- :where(*, *::before, *::after) {
+ :where(*), :where(*)::before, :where(*)::after {
border-width: 0;
border-style: solid;
border-color: currentColor;
@@ -284,19 +284,19 @@
/*
* Normalize placeholder opacity (Firefox renders at reduced opacity)
- * and set a sensible default color using the Astryx text-placeholder token.
+ * and color it with the --color-text-secondary token, or its default.
*/
- :where(input::placeholder, textarea::placeholder) {
+ :where(input, textarea)::placeholder {
opacity: 1;
- color: var(--color-text-secondary, #9ca3af);
+ color: var(--color-text-secondary, light-dark(#4E606F, #AAAFB5));
}
/*
* Remove the inner padding and cancel buttons in search inputs
* for Chrome and Safari.
*/
- :where([type='search']::-webkit-search-decoration,
- [type='search']::-webkit-search-cancel-button) {
+ :where([type='search'])::-webkit-search-decoration,
+ :where([type='search'])::-webkit-search-cancel-button {
-webkit-appearance: none;
}
diff --git a/internal/eslint-plugin-astryx/README.md b/internal/eslint-plugin-astryx/README.md
index 04c7f3dc1d..33d563ad24 100644
--- a/internal/eslint-plugin-astryx/README.md
+++ b/internal/eslint-plugin-astryx/README.md
@@ -1010,8 +1010,8 @@ assumed, and none has an instance in the repo except the last:
look for colours is a different rule.
- **A `.css` file**, which ESLint never parses. There is one live instance:
`packages/core/src/reset.css:291` reads
- `var(--color-text-secondary, #9ca3af)` — the same defensive-fallback shape as
- the `Sankey` hits, and it rides with them.
+ `var(--color-text-secondary, light-dark(#4E606F, #AAAFB5))` — the same
+ defensive-fallback shape as the `Sankey` hits, and it rides with them.
Everything else the rule reaches, and a probe confirms it: a `const`, an object
property, an array element, an enum member, a computed key, a template
diff --git a/packages/core/src/reset.a11y.chromium.spec.ts b/packages/core/src/reset.a11y.chromium.spec.ts
new file mode 100644
index 0000000000..0f6bd01fc8
--- /dev/null
+++ b/packages/core/src/reset.a11y.chromium.spec.ts
@@ -0,0 +1,178 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file reset.a11y.chromium.spec.ts
+ * @input packages/core/src/reset.css, alone on a blank Chromium page
+ * @output Browser evidence that the reset reaches ::before, ::after,
+ * ::placeholder and the search field's cancel button
+ * @position reset.css integration proof. A pseudo-element inside :where() is
+ * invalid, and the forgiving list drops it without an error, so only a
+ * shipping engine shows which of the reset's rules still match.
+ */
+
+import * as fs from 'node:fs';
+import {fileURLToPath} from 'node:url';
+import {expect, test, type Page} from '@playwright/test';
+
+const RESET_CSS = fs.readFileSync(
+ fileURLToPath(new URL('./reset.css', import.meta.url)),
+ 'utf8',
+);
+
+// No Astryx CSS is loaded, so --color-text-secondary is undefined and a
+// placeholder takes the reset's fallback: the token's own light-dark() default.
+const PLACEHOLDER_FALLBACK = {
+ light: 'rgb(78, 96, 111)',
+ dark: 'rgb(170, 175, 181)',
+};
+
+/** Every style rule's selector, in source order, comments stripped. */
+function sourceSelectors(css: string): string[] {
+ const stripped = css.replace(/\/\*[\s\S]*?\*\//g, '');
+ return [...stripped.matchAll(/([^{}]+)\{[^{}]*\}/g)].map(([, selector]) =>
+ selector.trim(),
+ );
+}
+
+/** Whitespace and quote style are the only differences serialization adds. */
+function normalize(selector: string): string {
+ return selector.replace(/\s+/g, '').replace(/'/g, '"');
+}
+
+async function loadReset(page: Page) {
+ await page.setContent(`
+ <div id="probe"></div>
+ <input id="name" placeholder="Name">
+ <textarea id="notes" placeholder="Notes"></textarea>
+ <input id="query" type="search" value="query" style="width: 200px">
+ `);
+ await page.addStyleTag({content: RESET_CSS});
+ // Width 100 plus 10px padding a side: 100 wide under border-box, 120
+ // under content-box. The ::before border sets only its width.
+ await page.addStyleTag({
+ content: `
+ #probe { display: inline-block; }
+ #probe::before, #probe::after {
+ content: '';
+ display: block;
+ width: 100px;
+ height: 20px;
+ padding: 10px;
+ }
+ #probe::before { border-width: 5px; }
+ `,
+ });
+}
+
+test.beforeEach(async ({page}) => {
+ await loadReset(page);
+});
+
+test('Chromium keeps every selector the reset writes', async ({page}) => {
+ // A forgiving list drops an invalid entry instead of the whole rule, so a
+ // dropped pseudo-element shows up as a shorter serialized selector.
+ const parsed = await page.evaluate(() => {
+ const layer = document.styleSheets[0].cssRules[0] as CSSLayerBlockRule;
+ return [...layer.cssRules].map(rule => (rule as CSSStyleRule).selectorText);
+ });
+ expect(parsed.map(normalize)).toEqual(
+ sourceSelectors(RESET_CSS).map(normalize),
+ );
+});
+
+test('::before and ::after are border-box and take the border reset', async ({
+ page,
+}) => {
+ const measured = await page.evaluate(() => {
+ const probe = document.getElementById('probe');
+ if (!probe) {
+ throw new Error('missing probe');
+ }
+ const before = getComputedStyle(probe, '::before');
+ const after = getComputedStyle(probe, '::after');
+ return {
+ beforeBoxSizing: before.boxSizing,
+ afterBoxSizing: after.boxSizing,
+ beforeBorderStyle: before.borderTopStyle,
+ beforeBorderWidth: before.borderTopWidth,
+ afterBorderWidth: after.borderTopWidth,
+ width: probe.getBoundingClientRect().width,
+ };
+ });
+ expect(measured).toEqual({
+ beforeBoxSizing: 'border-box',
+ afterBoxSizing: 'border-box',
+ beforeBorderStyle: 'solid',
+ beforeBorderWidth: '5px',
+ afterBorderWidth: '0px',
+ width: 100,
+ });
+});
+
+test('input and textarea placeholders take the reset color in both schemes', async ({
+ page,
+}) => {
+ const readPlaceholders = async () =>
+ page.evaluate(() =>
+ ['name', 'notes'].map(id => {
+ const field = document.getElementById(id);
+ if (!field) {
+ throw new Error(`missing #${id}`);
+ }
+ const placeholder = getComputedStyle(field, '::placeholder');
+ return {color: placeholder.color, opacity: placeholder.opacity};
+ }),
+ );
+ for (const scheme of ['light', 'dark'] as const) {
+ await page.emulateMedia({colorScheme: scheme});
+ const color = PLACEHOLDER_FALLBACK[scheme];
+ expect(await readPlaceholders(), scheme).toEqual([
+ {color, opacity: '1'},
+ {color, opacity: '1'},
+ ]);
+ }
+});
+
+test('a search field has no cancel button to clear it', async ({page}) => {
+ // Chromium draws the cancel button at the inline end of a focused search
+ // field that has a value, and a click on it empties the field.
+ const query = page.locator('#query');
+ await query.focus();
+ const box = await query.boundingBox();
+ if (!box) {
+ throw new Error('missing search field box');
+ }
+ await page.mouse.click(box.x + box.width - 8, box.y + box.height / 2);
+ await expect(query).toHaveValue('query');
+});
+
+test('a later layer and an unlayered rule still override the reset', async ({
+ page,
+}) => {
+ // Same 0,0,1 specificity as the reset's own selectors, so only the cascade
+ // layer decides.
+ await page.addStyleTag({
+ content: `
+ @layer reset, astryx-base;
+ @layer astryx-base {
+ :where(textarea)::placeholder { color: rgb(0, 128, 0); }
+ }
+ :where(#probe)::after { box-sizing: content-box; }
+ `,
+ });
+ const overridden = await page.evaluate(() => {
+ const probe = document.getElementById('probe');
+ const notes = document.getElementById('notes');
+ if (!probe || !notes) {
+ throw new Error('missing probe or textarea');
+ }
+ return {
+ placeholderColor: getComputedStyle(notes, '::placeholder').color,
+ afterBoxSizing: getComputedStyle(probe, '::after').boxSizing,
+ };
+ });
+ expect(overridden).toEqual({
+ placeholderColor: 'rgb(0, 128, 0)',
+ afterBoxSizing: 'content-box',
+ });
+});
diff --git a/packages/core/src/reset.css b/packages/core/src/reset.css
index d4677d7711..19246aad50 100644
--- a/packages/core/src/reset.css
+++ b/packages/core/src/reset.css
@@ -13,7 +13,7 @@
* - Removes default margins, padding, and list styles
* - Makes images block-level and responsive
* - Resets form elements to inherit font styles
- * - Uses :where() for zero specificity (easy to override)
+ * - Uses :where() for zero specificity (pseudo-elements go outside it)
*
* Usage:
*
@@ -46,7 +46,7 @@
* Use border-box globally. Prevents padding/border from affecting
* element dimensions — the single most impactful reset.
*/
- :where(*, *::before, *::after) {
+ :where(*), :where(*)::before, :where(*)::after {
box-sizing: border-box;
}
@@ -54,7 +54,7 @@
* Reset borders to 0-width solid. This lets you add a border by just
* setting border-width — no need to also specify border-style.
*/
- :where(*, *::before, *::after) {
+ :where(*), :where(*)::before, :where(*)::after {
border-width: 0;
border-style: solid;
border-color: currentColor;
@@ -284,19 +284,19 @@
/*
* Normalize placeholder opacity (Firefox renders at reduced opacity)
- * and set a sensible default color using the Astryx text-placeholder token.
+ * and color it with the --color-text-secondary token, or its default.
*/
- :where(input::placeholder, textarea::placeholder) {
+ :where(input, textarea)::placeholder {
opacity: 1;
- color: var(--color-text-secondary, #9ca3af);
+ color: var(--color-text-secondary, light-dark(#4E606F, #AAAFB5));
}
/*
* Remove the inner padding and cancel buttons in search inputs
* for Chrome and Safari.
*/
- :where([type='search']::-webkit-search-decoration,
- [type='search']::-webkit-search-cancel-button) {
+ :where([type='search'])::-webkit-search-decoration,
+ :where([type='search'])::-webkit-search-cancel-button {
-webkit-appearance: none;
}
diff --git a/packages/core/src/reset.test.ts b/packages/core/src/reset.test.ts
index 2a4292ca06..3aaf57a832 100644
--- a/packages/core/src/reset.test.ts
+++ b/packages/core/src/reset.test.ts
@@ -80,3 +80,115 @@ describe('reset.css accessibility invariants', () => {
).toBe(true);
});
});
+
+/** The argument of every `:where()` and `:is()`, nested ones included. */
+function forgivingListArguments(selector: string): string[] {
+ return [...selector.matchAll(/:(?:where|is)\(/g)].map(match => {
+ const start = match.index + match[0].length;
+ let depth = 1;
+ let end = start;
+ for (; end < selector.length && depth > 0; end++) {
+ if (selector[end] === '(') {
+ depth++;
+ } else if (selector[end] === ')') {
+ depth--;
+ }
+ }
+ return selector.slice(start, end - 1);
+ });
+}
+
+/** A selector list split on its top-level commas. */
+function topLevelSelectors(list: string): string[] {
+ const selectors: string[] = [];
+ let depth = 0;
+ let start = 0;
+ for (let index = 0; index < list.length; index++) {
+ if (list[index] === '(') {
+ depth++;
+ } else if (list[index] === ')') {
+ depth--;
+ } else if (list[index] === ',' && depth === 0) {
+ selectors.push(list.slice(start, index).trim());
+ start = index + 1;
+ }
+ }
+ selectors.push(list.slice(start).trim());
+ return selectors;
+}
+
+/**
+ * A pseudo-element is not valid inside :where() or :is() (Selectors Level 4).
+ * Both take a forgiving selector list, so the browser drops that entry rather
+ * than the rule, and the declarations silently stop reaching the
+ * pseudo-element. It goes after the :where(), as in `:where(*)::before`.
+ * reset.a11y.chromium.spec.ts measures the result in Chromium.
+ */
+describe('reset.css pseudo-element rules', () => {
+ let ruleBlocks: {selector: string; body: string}[];
+
+ beforeAll(() => {
+ const stripped = fs
+ .readFileSync(path.resolve(__dirname, './reset.css'), 'utf-8')
+ .replace(/\/\*[\s\S]*?\*\//g, '');
+ ruleBlocks = [...stripped.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map(
+ ([, selector, body]) => ({selector: selector.trim(), body}),
+ );
+ });
+
+ it('keeps every pseudo-element outside :where() and :is()', () => {
+ for (const {selector} of ruleBlocks) {
+ for (const argument of forgivingListArguments(selector)) {
+ expect
+ .soft(argument, `"${selector}" puts a pseudo-element in a list`)
+ .not.toMatch(/::|:(?:before|after|first-line|first-letter)\b/);
+ }
+ }
+ });
+
+ it('targets ::before, ::after, ::placeholder and the search field parts', () => {
+ const selectorsFor = (declaration: string) =>
+ ruleBlocks
+ .filter(({body}) => body.includes(declaration))
+ .flatMap(({selector}) => topLevelSelectors(selector));
+ const endsWith = (declaration: string, pseudoElement: string) =>
+ selectorsFor(declaration).some(selector =>
+ selector.endsWith(pseudoElement),
+ );
+
+ for (const declaration of [
+ 'box-sizing: border-box',
+ 'border-style: solid',
+ ]) {
+ expect(endsWith(declaration, '::before'), declaration).toBe(true);
+ expect(endsWith(declaration, '::after'), declaration).toBe(true);
+ }
+ expect(endsWith('opacity: 1', '::placeholder')).toBe(true);
+ expect(
+ endsWith('-webkit-appearance: none', '::-webkit-search-decoration'),
+ ).toBe(true);
+ expect(
+ endsWith('-webkit-appearance: none', '::-webkit-search-cancel-button'),
+ ).toBe(true);
+ });
+
+ it('falls back to the --color-text-secondary default for placeholders', () => {
+ // A page that loads only the reset never defines the token. The fallback
+ // repeats the token's own default, so that page shows the placeholder an
+ // Astryx page does, at the contrast the token was chosen for.
+ const tokens = fs.readFileSync(
+ path.resolve(__dirname, './theme/tokens.stylex.ts'),
+ 'utf-8',
+ );
+ const tokenDefault = tokens.match(
+ /'--color-text-secondary':\s*'([^']+)'/,
+ )?.[1];
+ expect(tokenDefault).toMatch(/^light-dark\(/);
+ const placeholder = ruleBlocks.find(({selector}) =>
+ selector.endsWith('::placeholder'),
+ );
+ expect(placeholder?.body).toContain(
+ `color: var(--color-text-secondary, ${tokenDefault});`,
+ );
+ });
+});