[Docs] Add Figma images support - #1418
Conversation
Copilot-Session: 7f4f3eb4-ed1c-4ba0-8f13-8517b3fec854
|
🟢 No design token changes found |
🟢 Bundle size report
|
🟢 No visual differences foundOur visual comparison tests did not find any differences in the UI. |
Copilot-Session: ac87ac9e-711e-4766-8585-6c2e0b2c324b
Copilot-Session: 048a0f3a-d8e7-43c2-8cd8-d5745e10c7f4
There was a problem hiding this comment.
Pull request overview
Adds first-class support for embedding and validating Figma frame previews in the Primer Brand docs app (apps/next-docs), including a generator/validator workflow and updated docs pages that adopt the new FigmaImage component.
Changes:
- Introduces a
FigmaImageMDX component (with light/dark sources, captions, and “Edit in Figma” links) plus server-side resolution of committed preview assets. - Adds AST-based MDX/YAML discovery + URL validation + asset verification scripts, with a local generate command and token-free CI validation.
- Adds GitHub Actions workflows to generate/update committed Figma previews (manual and “update figma images” label driven), and documents the workflow in contributor docs.
Show a summary per file
| File | Description |
|---|---|
| package-lock.json | Updates workspace versions and adds dependencies required for MDX parsing/validation and @primer/figma-images. |
| CONTRIBUTING.md | Documents how to reference Figma frames and update/validate generated assets. |
| apps/next-docs/src/components/FigmaImage/FigmaImagePreview.tsx | Client-side preview rendering with missing-preview fallback UI and dimension handling. |
| apps/next-docs/src/components/FigmaImage/FigmaImageEditLink.tsx | Client-side “Edit in Figma” link tied to the active (light/dark) source. |
| apps/next-docs/src/components/FigmaImage/FigmaImage.utils.ts | Shared utilities for choosing active sources/edit URLs and preserving aspect ratios. |
| apps/next-docs/src/components/FigmaImage/FigmaImage.types.ts | Defines the resolved source shape passed between server/client components. |
| apps/next-docs/src/components/FigmaImage/FigmaImage.tsx | Main MDX component composing preview + edit link + caption, with alt/presentation rules. |
| apps/next-docs/src/components/FigmaImage/FigmaImage.server.mjs | Resolves Figma URLs to committed local assets and maps pageMap thumbnails accordingly. |
| apps/next-docs/src/components/FigmaImage/FigmaImage.module.css | Styling for previews, captions, missing states, and the hover/focus edit link affordance. |
| apps/next-docs/scripts/figma-images.test.mjs | Node-test coverage for discovery, validation, generation/asset verification, and key utilities. |
| apps/next-docs/scripts/figma-images.mjs | Implements MDX/YAML AST discovery, URL validation rules, and asset verification + generate/validate CLI. |
| apps/next-docs/public/images/figma/images.json | Adds the generated manifest mapping node basenames to filenames/dimensions. |
| apps/next-docs/package.json | Wires up generate/validate scripts, runs validation in check, and adds a workspace test script. |
| apps/next-docs/mdx-components.js | Registers FigmaImage for MDX pages. |
| apps/next-docs/content/components/CTABanner/index.mdx | Switches an anatomy image to use <FigmaImage> with light/dark sources and caption. |
| apps/next-docs/content/components/Card/index.mdx | Switches thumbnails to Figma-backed URLs (light/dark) for generation/validation. |
| apps/next-docs/app/layout.tsx | Maps Figma-backed thumbnails in the doctocat page map to committed asset URLs. |
| .github/workflows/update_figma_images.yml | Adds a manual workflow to regenerate previews on main and open a draft PR if assets change. |
| .github/workflows/update_figma_images_on_label.yml | Adds a pull_request_target workflow to regenerate previews and commit them back to the PR branch when labeled. |
| .github/copilot-instructions.md | Adds repo guidance that Figma images are generated artifacts and must be regenerated, not edited manually. |
Review details
- Files reviewed: 19/24 changed files
- Comments generated: 3
- Review effort level: Low
Copilot-Session: d539b22f-f2d0-4139-8c9d-cf79dea8ec42
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (2)
apps/next-docs/src/components/FigmaImage/FigmaImage.server.mjs:49
- In both the “missing generated preview” and “success” branches,
editUrlis set to the rawurlinput. If an author passes a relative or protocol-relative URL, the rendered “Edit in Figma” link can point to the docs site (or an unexpected host) instead of Figma. Using the normalized URL here keeps the link consistent with the URL parsing logic used to resolve the asset.
return {
editUrl: url,
width: manifestEntry?.width,
height: manifestEntry?.height,
missingReason: 'The generated preview image is missing for this Figma frame.',
apps/next-docs/src/components/FigmaImage/FigmaImage.server.mjs:63
- In the
catchfallback,editUrlis returned as the originalurlinput. Since this value is used as an anchorhref, a malformed/non-Figma URL can become a clickable link. Use a safe default (or omit the edit link) when URL normalization/parsing throws.
return {
editUrl: url,
missingReason: 'The selected Figma frame URL could not be parsed.',
}
- Files reviewed: 19/24 changed files
- Comments generated: 2
- Review effort level: Low
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3652e08c-de25-4309-9cbd-bdb5295b0106
Summary
Resolves https://github.com/github/brand-experience/issues/428
Adds support for embedding Figma frames in Primer Brand docs pages and thumbnails, with generated images committed to the repository.
This ports the existing Primer Docs workflow and adapts it with stricter discovery and validation for Brand content.
Authors reference a Figma frame through
<FigmaImage>or page frontmatter. The generation script discovers and downloads those frames, while CI verifies that the URLs and committed assets remain in sync without requiring Figma access during a docs build.List of notable changes:
update figma imageslabel workflow that regenerates previews and commits them to the current PR branchremark-frontmatter,unist-util-visit, andyamlthroughnextra; andunified,remark-parse,remark-mdx, andunist-util-visitthrough@mdx-js/mdx.What should reviewers focus on?
Steps to test:
npm run figma-images:validate --workspace=apps/next-docs.