Skip to content

fix(figma): read the branch key from a Figma branch URL - #6863

Open
kevin9327 wants to merge 1 commit into
heygen-com:mainfrom
kevin9327:fix/figma-branch-url-key
Open

kevin9327 wants to merge 1 commit into
heygen-com:mainfrom
kevin9327:fix/figma-branch-url-key

Conversation

@kevin9327

@kevin9327 kevin9327 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What

parseFigmaRef now returns the branch key for a Figma branch URL.

A branch link has the shape https://www.figma.com/design/<fileKey>/branch/<branchKey>/<Name>. The REST API serves a branch under its own key (GET /v1/files/:key, where the key "can be a file key or branch key", per the file endpoints docs), but FILE_KEY_RE stopped at the first segment, so a branch link resolved to the main file. Every later call (/files/:key/nodes, images, variables) then read the main file, and a frame that only exists on the branch came back as missing, or a frame edited on the branch was imported in its main-file state.

How

FILE_KEY_RE optionally matches a following /branch/<key> segment, and the parser uses that key when it is present. Non-branch URLs, the fileKey:nodeId shorthand and node-id handling are unchanged; a file whose name is literally branch (no key after it) still resolves to the main key.

Test

Two new cases in packages/core/src/figma/parseFigmaRef.test.ts: a /design/.../branch/... URL with a node id and a /file/.../branch/... URL without one both return the branch key, and /design/<key>/branch keeps the file key. The first case fails before the change (it returns MainKey123) and passes after; the whole file passes (8 tests). Formatted with oxfmt 0.41.0.

fails without the fix: packages/core/src/figma/parseFigmaRef.test.ts › "uses the branch key of a branch URL, which is the key the REST API serves the branch under" (returns MainKey123 instead of the branch key)

This PR was prepared with AI assistance; I reviewed the change and ran the tests.

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES · 1 blocker · 0 important · 0 nits · head bd1e27ef

  • blocker (process): the PR body has no fails without the fix: line naming the regression test. Add one, for example fails without the fix: packages/core/src/figma/parseFigmaRef.test.ts › "uses the branch key of a branch URL, …" (it currently returns MainKey123). That line is the only thing blocking this.
Scope

I read the full diff (parseFigmaRef.ts and its test). The regex change is correct: the optional /branch/<key> group wins over the file key, the bare /branch name still resolves to the main key, and node-id handling is unchanged. parseFigmaRef is the only Figma URL parser in the repo (the CLI goes through it), so there are no sibling sites to update. CI was still running at review time. The finished checks (captures, comments, preview-regression, player perf) are green.

@kevin9327

Copy link
Copy Markdown
Contributor Author

Added the fails without the fix: line to the PR body (the branch-URL case in parseFigmaRef.test.ts returns MainKey123 without the change).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant