mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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)
262 lines
9.2 KiB
TypeScript
262 lines
9.2 KiB
TypeScript
'use client'
|
|
|
|
import type { ContentListingGroup, ContentListingItem } from '~/lib/content-listings.schema'
|
|
import {
|
|
filterContentListingItems,
|
|
getContentListingById,
|
|
getContentListingGroupLabel,
|
|
isExternalContentListingHref,
|
|
} from '~/lib/content-listings.utils'
|
|
import { useSendTelemetryEvent } from '~/lib/telemetry'
|
|
import { ChevronDown, ChevronRight } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useCallback, useMemo } from 'react'
|
|
import ReactMarkdown from 'react-markdown'
|
|
import { Badge, cn, Heading } from 'ui'
|
|
import { GlassPanel } from 'ui-patterns/GlassPanel'
|
|
|
|
import { resolveContentListingIcon } from './iconChip'
|
|
|
|
const GRID_ITEM_CLASS = {
|
|
// Stay 2-up until xl (~1280px) so cards aren't cramped beside the docs sidebar.
|
|
2: 'col-span-12 md:col-span-6',
|
|
3: 'col-span-12 md:col-span-6 xl:col-span-4',
|
|
4: 'col-span-12 md:col-span-6 xl:col-span-3',
|
|
} as const
|
|
|
|
function useContentListingClickHandler(group: ContentListingGroup) {
|
|
const sendTelemetryEvent = useSendTelemetryEvent()
|
|
const groupLabel = getContentListingGroupLabel(group)
|
|
|
|
const trackClick = useCallback(
|
|
(item: ContentListingItem) => {
|
|
if (!item.href) return
|
|
|
|
sendTelemetryEvent({
|
|
action: 'docs_content_listing_clicked',
|
|
properties: {
|
|
targetPath: item.href,
|
|
linkTitle: item.title,
|
|
...(groupLabel ? { groupTitle: groupLabel } : {}),
|
|
listingId: group.id,
|
|
},
|
|
})
|
|
},
|
|
[sendTelemetryEvent, group.id, groupLabel]
|
|
)
|
|
|
|
return { trackClick }
|
|
}
|
|
|
|
const PROGRESSION_COLUMNS = 2
|
|
|
|
type FlowDirection = 'right' | 'wrap' | 'none'
|
|
|
|
function progressionDirection(index: number, count: number): FlowDirection {
|
|
if (index >= count - 1) return 'none'
|
|
if (index % PROGRESSION_COLUMNS === PROGRESSION_COLUMNS - 1) return 'wrap'
|
|
return 'right'
|
|
}
|
|
|
|
function FlowArrow({ icon: Icon }: { icon: typeof ChevronDown }) {
|
|
return (
|
|
<span className="relative flex size-4 items-center justify-center rounded-full bg-background text-brand-600">
|
|
<Icon size={14} strokeWidth={2.5} />
|
|
</span>
|
|
)
|
|
}
|
|
|
|
function ProgressionConnector({ direction }: { direction: Exclude<FlowDirection, 'none'> }) {
|
|
return (
|
|
<span aria-hidden className="pointer-events-none absolute inset-0 z-10">
|
|
<span className="absolute top-full left-1/2 flex h-(--flow-gap) -translate-x-1/2 items-center justify-center @md:hidden">
|
|
<span className="absolute inset-y-0 w-px bg-brand-500/15 dark:bg-brand-500/40" />
|
|
<FlowArrow icon={ChevronDown} />
|
|
</span>
|
|
{direction === 'right' && (
|
|
<span className="absolute top-1/2 left-full hidden h-px w-(--flow-gap) -translate-y-1/2 items-center justify-center @md:flex">
|
|
<span className="absolute inset-x-0 h-px bg-brand-500/15 dark:bg-brand-500/40" />
|
|
<FlowArrow icon={ChevronRight} />
|
|
</span>
|
|
)}
|
|
{direction === 'wrap' && (
|
|
<span className="absolute top-full right-0 hidden h-(--flow-gap) w-[calc(200%+var(--flow-gap))] [--elbow:50%] @md:block">
|
|
<span className="absolute top-0 right-[calc(25%-var(--flow-gap)/4)] h-(--elbow) w-px bg-brand-500/15 dark:bg-brand-500/40" />
|
|
<span className="absolute top-(--elbow) right-[calc(25%-var(--flow-gap)/4)] left-[calc(25%-var(--flow-gap)/4)] h-px bg-brand-500/15 dark:bg-brand-500/40" />
|
|
<span className="absolute top-(--elbow) bottom-0 left-[calc(25%-var(--flow-gap)/4)] w-px bg-brand-500/15 dark:bg-brand-500/40" />
|
|
<span className="absolute bottom-0 left-[calc(25%-var(--flow-gap)/4)] -translate-x-1/2">
|
|
<FlowArrow icon={ChevronDown} />
|
|
</span>
|
|
</span>
|
|
)}
|
|
</span>
|
|
)
|
|
}
|
|
|
|
function ContentListingProgression({ group }: { group: ContentListingGroup }) {
|
|
const { trackClick } = useContentListingClickHandler(group)
|
|
const items = filterContentListingItems(group.items).filter(
|
|
(item): item is ContentListingItem & { href: string } => Boolean(item.href)
|
|
)
|
|
|
|
return (
|
|
<div className="@container [--flow-gap:calc(2rem*4/3)]">
|
|
<ol
|
|
aria-labelledby={group.labelledBy}
|
|
aria-label={group.labelledBy ? undefined : (group.heading ?? 'Progression')}
|
|
className="m-0 grid list-none grid-cols-1 gap-(--flow-gap) p-0 @md:grid-cols-2"
|
|
>
|
|
{items.map((item, index) => {
|
|
const direction = progressionDirection(index, items.length)
|
|
const panel = (
|
|
<GlassPanel title={item.title} icon={resolveContentListingIcon(item.icon)} showIconBg>
|
|
{item.subtitle && (
|
|
<span className="-mt-1 ml-11 block text-xs text-foreground">{item.subtitle}</span>
|
|
)}
|
|
</GlassPanel>
|
|
)
|
|
|
|
return (
|
|
<li key={`${group.id}-${item.href}`} className="relative">
|
|
<a
|
|
href={item.href}
|
|
className="focus-ring block h-full rounded-lg no-underline"
|
|
onClick={() => trackClick(item)}
|
|
>
|
|
{panel}
|
|
</a>
|
|
{direction !== 'none' && <ProgressionConnector direction={direction} />}
|
|
</li>
|
|
)
|
|
})}
|
|
</ol>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function ContentListingGroupHeading({ group }: { group: ContentListingGroup }) {
|
|
if (!group.heading) return null
|
|
|
|
return (
|
|
<Heading tag={group.headingLevel ?? 'h2'} customAnchor={group.headingAnchor}>
|
|
{group.heading}
|
|
</Heading>
|
|
)
|
|
}
|
|
|
|
function ContentListingsGroup({ group }: { group: ContentListingGroup }) {
|
|
const { trackClick } = useContentListingClickHandler(group)
|
|
const items = useMemo(() => filterContentListingItems(group.items), [group.items])
|
|
const isGrid = group.type === 'grid'
|
|
const listClassName = isGrid ? 'grid md:grid-cols-12 gap-4' : 'list-disc pl-6 space-y-2'
|
|
const gridItemClassName = isGrid ? GRID_ITEM_CLASS[group.columns ?? 3] : undefined
|
|
|
|
if (!items.length) return null
|
|
|
|
// Heading stays outside `not-prose` so it inherits the surrounding MDX prose
|
|
// typography. The list itself opts out so its explicit Tailwind layout wins.
|
|
return (
|
|
<section className="space-y-4">
|
|
<ContentListingGroupHeading group={group} />
|
|
<div className="not-prose space-y-4">
|
|
{group.description && (
|
|
<div className="text-foreground-light [&_a]:text-foreground [&_a]:underline [&_p]:m-0">
|
|
<ReactMarkdown>{group.description}</ReactMarkdown>
|
|
</div>
|
|
)}
|
|
<ul className={listClassName}>
|
|
{items.map((item) => {
|
|
const key = `${group.id}-${item.href ?? item.title}`
|
|
const panel = (
|
|
<GlassPanel
|
|
title={item.title}
|
|
icon={resolveContentListingIcon(item.icon)}
|
|
hasLightIcon={item.hasLightIcon ?? typeof item.icon === 'string'}
|
|
className={item.href ? undefined : 'cursor-default'}
|
|
badge={
|
|
item.badge && item.badgePosition !== 'below' ? (
|
|
<Badge variant="success">{item.badge}</Badge>
|
|
) : undefined
|
|
}
|
|
>
|
|
{item.badge && item.badgePosition === 'below' && (
|
|
<Badge variant="success" className="mb-3 block w-fit">
|
|
{item.badge}
|
|
</Badge>
|
|
)}
|
|
{item.subtitle && (
|
|
<span className="mb-2 block text-tertiary-foreground">{item.subtitle}</span>
|
|
)}
|
|
{item.description}
|
|
</GlassPanel>
|
|
)
|
|
const listContent = (
|
|
<>
|
|
<strong>{item.title}</strong>: {item.description}
|
|
</>
|
|
)
|
|
|
|
if (!item.href) {
|
|
return (
|
|
<li key={key} className={gridItemClassName}>
|
|
{isGrid ? panel : listContent}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
const external = isExternalContentListingHref(item.href)
|
|
|
|
if (isGrid) {
|
|
return (
|
|
<li key={key} className={gridItemClassName}>
|
|
<Link
|
|
href={item.href}
|
|
passHref
|
|
className="block h-full"
|
|
onClick={() => trackClick(item)}
|
|
target={external ? '_blank' : undefined}
|
|
rel={external ? 'noopener noreferrer' : undefined}
|
|
>
|
|
{panel}
|
|
</Link>
|
|
</li>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<li key={key}>
|
|
<Link
|
|
href={item.href}
|
|
onClick={() => trackClick(item)}
|
|
target={external ? '_blank' : undefined}
|
|
rel={external ? 'noopener noreferrer' : undefined}
|
|
>
|
|
{listContent}
|
|
</Link>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
</div>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
export function ContentListings({ id }: { id: string }) {
|
|
const group = getContentListingById(id)
|
|
if (!group || !filterContentListingItems(group.items).length) return null
|
|
if (group.type === 'progression') {
|
|
return (
|
|
<div className="not-prose my-10">
|
|
<ContentListingProgression group={group} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="my-10 space-y-10">
|
|
<ContentListingsGroup group={group} />
|
|
</div>
|
|
)
|
|
}
|