mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
Closes DOCS-1573 ## Problem Recently, @antlio surfaced that our side nav was visually breaking. This is caused by a duplicate-id issue. The docs E2E axe scan reports duplicate `id` attributes as a warning only, so pages with duplicate IDs ship. A full scan of production guides found duplicate IDs on 25 of 586 pages. **Causes:** - **Repeated headings:** a page uses the same heading text twice, for example `#### Example` under two sections. Each heading slugs to the same ID. - **Pricing partials:** three usage pages put `## Pricing` directly above a shared partial that starts with its own Pricing heading. - **Components:** Mermaid diagrams hardcode SVG marker and node IDs. The Apple secret generator renders `id="undefined-optional"` on each field label. Each "Build it" listing on the Supabase way page renders `#build-it`. ## Solution - **Enforce the rules:** add `duplicate-id`, `duplicate-id-active`, and `duplicate-id-aria` to `ENFORCED_RULES`. - **Repeated headings:** give each later duplicate a `[#parent-section-heading]` anchor. The first occurrence keeps its ID. - **Pricing headings:** remove the page heading above the three partials that start with `## Pricing`. The PITR partial starts with `### Pricing`, so it gets `[#pitr-pricing]` and the page keeps its H2. - **Mermaid:** prefix the SVG IDs of each diagram with `useId()`. - **Apple secret generator:** give each field an ID. The label now also points at its input. - **Content listings:** add an optional `headingAnchor` to listing groups, and set it on the repeated "Build it" groups. - **pg_net:** the `http_delete` signature had `[#post-signature]`, copied from `http_post`. It is now `[#delete-signature]`. **Cross-references:** no link in the repo targets a changed ID. Each first occurrence keeps its ID, so existing links resolve to the same heading as before. **Not changed:** the www suite and `packages/ui-patterns`. All fixes stay in `apps/docs`. **Verification:** - Against production, `/docs/guides/platform/manage-your-usage/log-drains` fails the @a11y test with `duplicate-id`. - Against a local docs server, the @a11y test passes on all 28 changed or affected pages. **Unverified:** a full-site run with `A11Y_ENFORCE_ALL=1`. Run it against the preview before merge. ## Review instructions 1. From `e2e/docs`, run the a11y test against production. See it fail with `duplicate-id`: ```bash DOCS_E2E_PAGE_PATHS=/docs/guides/platform/manage-your-usage/log-drains PLAYWRIGHT_BASE_URL=https://supabase.com pnpm exec playwright test --grep @a11y ``` 2. Run the same command with `PLAYWRIGHT_BASE_URL` set to the docs preview URL from the Vercel bot comment. See it pass. 3. On the preview, open `/docs/guides/platform/manage-your-usage/log-drains`. In the table of contents, select **Pricing** under **Log Drain Events**. See the page scroll to the second Pricing section. 4. On the preview, open `/docs/guides/integrations/partner-integration-guide`. See both sequence diagrams render with arrowheads. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
115 lines
2.7 KiB
TypeScript
115 lines
2.7 KiB
TypeScript
import type { Page, TestInfo } from '@playwright/test'
|
|
import type { Result } from 'axe-core'
|
|
|
|
import { scan, scanResults } from '../../shared/axe.ts'
|
|
|
|
export const WCAG_TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']
|
|
|
|
export const ENFORCED_RULES = [
|
|
'heading-order',
|
|
'page-has-heading-one',
|
|
'button-name',
|
|
'duplicate-id',
|
|
'duplicate-id-active',
|
|
'duplicate-id-aria',
|
|
]
|
|
|
|
export const EXCLUDED_RULES = [
|
|
'color-contrast',
|
|
'html-has-lang',
|
|
'html-lang-valid',
|
|
'html-xml-lang-mismatch',
|
|
'document-title',
|
|
'aria-hidden-body',
|
|
'meta-viewport',
|
|
'meta-refresh',
|
|
'css-orientation-lock',
|
|
]
|
|
|
|
export interface A11yScanResult {
|
|
surface: string
|
|
url: string
|
|
include: string
|
|
excludedRules: string[]
|
|
loaded: boolean
|
|
status: number | null
|
|
elementCount: number
|
|
violations: Result[]
|
|
}
|
|
|
|
export function shouldEnforceAll(): boolean {
|
|
return !!process.env.A11Y_ENFORCE_ALL
|
|
}
|
|
|
|
export async function scanArticle(
|
|
page: Page,
|
|
surface: string,
|
|
include: string
|
|
): Promise<A11yScanResult> {
|
|
const reported = await scan(page, { tags: WCAG_TAGS, excludeRules: EXCLUDED_RULES, include })
|
|
const enforcedResults = await scanResults(page, { rules: ENFORCED_RULES })
|
|
const enforced = [
|
|
...enforcedResults.violations,
|
|
...enforcedResults.incomplete.filter((result) => result.id === 'duplicate-id-aria'),
|
|
]
|
|
|
|
const byRule = new Map([...reported, ...enforced].map((violation) => [violation.id, violation]))
|
|
|
|
const elementCount = await page.evaluate(
|
|
(selector) => document.querySelector(selector)?.querySelectorAll('*').length ?? 0,
|
|
include
|
|
)
|
|
|
|
return {
|
|
surface,
|
|
url: page.url(),
|
|
include,
|
|
excludedRules: EXCLUDED_RULES,
|
|
loaded: true,
|
|
status: null,
|
|
elementCount,
|
|
violations: [...byRule.values()],
|
|
}
|
|
}
|
|
|
|
export function unloadedResult(
|
|
surface: string,
|
|
url: string,
|
|
status: number | null,
|
|
include: string
|
|
): A11yScanResult {
|
|
return {
|
|
surface,
|
|
url,
|
|
include,
|
|
excludedRules: EXCLUDED_RULES,
|
|
loaded: false,
|
|
status,
|
|
elementCount: 0,
|
|
violations: [],
|
|
}
|
|
}
|
|
|
|
export const MIN_MEANINGFUL_ELEMENTS = 20
|
|
|
|
export function scanLooksEmpty(
|
|
result: A11yScanResult,
|
|
minElements: number = MIN_MEANINGFUL_ELEMENTS
|
|
): boolean {
|
|
return result.elementCount < minElements
|
|
}
|
|
|
|
export async function attachScanReport(testInfo: TestInfo, result: A11yScanResult): Promise<void> {
|
|
await testInfo.attach('axe-results.json', {
|
|
body: JSON.stringify(result, null, 2),
|
|
contentType: 'application/json',
|
|
})
|
|
}
|
|
|
|
export function blockingViolations(result: A11yScanResult): Result[] {
|
|
if (shouldEnforceAll()) return result.violations
|
|
return result.violations.filter((violation) => ENFORCED_RULES.includes(violation.id))
|
|
}
|
|
|
|
export { formatViolations, settleForAxe, violationIds } from '../../shared/axe.ts'
|