Skip to content

Commit 2aa23a8

Browse files
authored
fix(core): reset.css leaves hidden="until-found" content findable (#7520)
The reset's `:where([hidden]) { display: none }` also matched `hidden="until-found"`. The browser renders that state with `content-visibility: hidden`, which find in page and text fragment links can search and reveal; `display: none` took the content out of both, so a link to text inside a collapsed section scrolled nowhere and fired no `beforematch`. The rule now skips the until-found state (`:where([hidden]:not([hidden='until-found' i]))`), which is how the HTML Standard's own rendering rules split the two. Plain `hidden` elements keep `display: none`, still in `@layer reset`. A browser without until-found support treats the value as plain `hidden`, and its own `[hidden]` rule still hides it. The GitHub Pages landing serves a byte-identical copy of the file, which its test requires to match, so the copy and its manifest hash move with it.
1 parent 17306ce commit 2aa23a8

6 files changed

Lines changed: 123 additions & 5 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] `reset.css` no longer hides `hidden="until-found"` content with `display: none`. The browser's own rendering, `content-visibility: hidden`, now applies, so find in page and text fragment links can find the content and reveal it, as the HTML Standard specifies. Plain `hidden` elements are still `display: none`, and a browser without until-found support still hides the content with its own `[hidden]` rule.
6+
7+
@vjeux

‎.github/pages/assets/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"files": {
88
"reset.css": {
9-
"sha256": "b4d429b96882389b18b8df23086a686eda7c8427c66d5089c86969b2fc754323"
9+
"sha256": "8423107ecd6d1ea308d277ebc83fb5d6115ccddece700ce0f489ba44d42d8461"
1010
},
1111
"astryx.css": {
1212
"sha256": "bc66e60ffeb0eb3b2f2b303d89ba6bae1e7e922b10bb380f7b25624d73c765ba"

‎.github/pages/assets/reset.css‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@
354354
}
355355

356356
/*
357-
* Ensure hidden elements are actually hidden.
357+
* Ensure hidden elements are actually hidden. `hidden="until-found"` keeps
358+
* the browser's own rendering, `content-visibility: hidden`, so find in page
359+
* and text fragment links can still find its content and reveal it.
358360
*/
359-
:where([hidden]) {
361+
:where([hidden]:not([hidden='until-found' i])) {
360362
display: none;
361363
}
362364

‎packages/core/src/reset.css‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@
354354
}
355355

356356
/*
357-
* Ensure hidden elements are actually hidden.
357+
* Ensure hidden elements are actually hidden. `hidden="until-found"` keeps
358+
* the browser's own rendering, `content-visibility: hidden`, so find in page
359+
* and text fragment links can still find its content and reveal it.
358360
*/
359-
:where([hidden]) {
361+
:where([hidden]:not([hidden='until-found' i])) {
360362
display: none;
361363
}
362364

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file reset.until-found.a11y.browser.spec.ts
5+
* @input packages/core/src/reset.css, alone on a blank page
6+
* @output Browser evidence that `hidden="until-found"` content stays findable
7+
* @position reset.css integration proof. The browser hides until-found content
8+
* with `content-visibility: hidden`, which find in page and text fragments
9+
* can search and reveal; `display: none` takes the content out of both, and
10+
* only a shipping engine shows which one applies.
11+
*/
12+
13+
import * as fs from 'node:fs';
14+
import {fileURLToPath} from 'node:url';
15+
import {expect, test} from '@playwright/test';
16+
17+
const RESET_CSS = fs.readFileSync(
18+
fileURLToPath(new URL('./reset.css', import.meta.url)),
19+
'utf8',
20+
);
21+
22+
// Served at a real URL so a text fragment navigation can run against it.
23+
const ORIGIN = 'http://reset.test';
24+
const PAGE = `<!doctype html>
25+
<style>${RESET_CSS}</style>
26+
<div style="height: 3000px">Above the fold</div>
27+
<div id="answer" hidden="until-found">The hidden answer</div>
28+
<div id="closed" hidden>Plain hidden text</div>
29+
<script>
30+
document.getElementById('answer').addEventListener('beforematch', () => {
31+
document.body.dataset.beforematch = 'fired';
32+
});
33+
</script>`;
34+
35+
test.beforeEach(async ({page}) => {
36+
await page.route(`${ORIGIN}/**`, async route =>
37+
route.fulfill({contentType: 'text/html', body: PAGE}),
38+
);
39+
});
40+
41+
test('until-found content keeps the browser rendering', async ({page}) => {
42+
await page.goto(`${ORIGIN}/`);
43+
const styles = await page.evaluate(() =>
44+
['answer', 'closed'].map(id => {
45+
const element = document.getElementById(id);
46+
if (!element) {
47+
throw new Error(`missing #${id}`);
48+
}
49+
const style = getComputedStyle(element);
50+
return {
51+
display: style.display,
52+
contentVisibility: style.contentVisibility,
53+
};
54+
}),
55+
);
56+
expect(styles).toEqual([
57+
{display: 'block', contentVisibility: 'hidden'},
58+
{display: 'none', contentVisibility: 'visible'},
59+
]);
60+
});
61+
62+
test('a text fragment finds until-found content and reveals it', async ({
63+
page,
64+
}) => {
65+
await page.goto(`${ORIGIN}/#:~:text=hidden%20answer`);
66+
// The browser removes the attribute and fires beforematch when it reveals.
67+
await expect(page.locator('#answer')).not.toHaveAttribute('hidden');
68+
await expect(page.locator('#answer')).toBeInViewport();
69+
await expect(page.locator('body')).toHaveAttribute(
70+
'data-beforematch',
71+
'fired',
72+
);
73+
// Plain hidden content stays out of reach.
74+
await expect(page.locator('#closed')).toBeHidden();
75+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* Static guard for the reset's `[hidden]` rule and `hidden="until-found"`.
5+
*
6+
* The browser hides until-found content with `content-visibility: hidden`,
7+
* which find in page and text fragments can search and reveal. A
8+
* `display: none` that also matches it takes the content out of both.
9+
* reset.until-found.a11y.browser.spec.ts measures the result in a browser.
10+
*/
11+
12+
import fs from 'fs';
13+
import path from 'path';
14+
15+
import {describe, expect, it} from 'vitest';
16+
17+
describe('reset.css and hidden="until-found"', () => {
18+
it('sets display: none only on hidden elements that are not until-found', () => {
19+
const stripped = fs
20+
.readFileSync(path.resolve(__dirname, './reset.css'), 'utf-8')
21+
.replace(/\/\*[\s\S]*?\*\//g, '');
22+
const hiddenRules = [...stripped.matchAll(/([^{}]+)\{([^{}]*)\}/g)]
23+
.map(([, selector, body]) => ({selector: selector.trim(), body}))
24+
.filter(({selector}) => selector.includes('[hidden'));
25+
expect(hiddenRules.length).toBeGreaterThan(0);
26+
for (const {selector, body} of hiddenRules) {
27+
if (/display:\s*none/.test(body)) {
28+
expect(selector).toContain(":not([hidden='until-found' i])");
29+
}
30+
}
31+
});
32+
});

0 commit comments

Comments
 (0)