Skip to content

fix(studio): preserve authored caption groups on import - #3900

Open
AksharP5 wants to merge 5 commits into
heygen-com:mainfrom
AksharP5:fix/caption-group-import
Open

AksharP5 wants to merge 5 commits into
heygen-com:mainfrom
AksharP5:fix/caption-group-import

Conversation

@AksharP5

@AksharP5 AksharP5 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Opening existing captions in Studio silently moved words between groups. Seven words authored as 5 + 2 became 4 + 3, so editing and regenerating captions used the wrong boundaries.

Fixes #3899.

Caption group Before import Current main This fix
1 We asked what you needed. We asked what you We asked what you needed.
2 Forty-seven percent needed. Forty-seven percent Forty-seven percent

How

Read each outer caption group's word count instead of averaging all words and groups. Nested layout lines do not count twice. Incomplete DOM falls back to the existing five-word grouping without dropping transcript words.

Both import paths share the existing model construction, preserving segment IDs, word IDs, timing, and defaults. No UI changes or dependencies.

Verification

  • Regression suite reproduced seven failures before the fix; all nine new cases now pass. Covers 5 + 2, 2 + 4 + 1, alternate class names, nested lines, incomplete DOM, and generated-HTML re-import.
  • All 73 caption tests pass.
  • Chromium check using generated caption HTML, real iframe DOM, and GSAP preserves both groups and word metadata through import, regeneration, and re-import.
  • Workspace build, final Studio build and typecheck, lint, formatting, and fallow audit pass. Pre-commit checks pass.

Before

Main imports the authored 5 + 2 caption groups as 4 + 3. Browser regression harness using the actual Studio parser from main (a4a7cbeac) and synthetic fixture data in a live iframe DOM.

Before caption import

After

The same input retains 5 + 2, keeping “needed.” in the first group. The harness uses this PR’s parser with the same source and DOM.

After caption import

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. This fixes #3899: import now reads each outer group's word count instead of averaging.

  • packages/studio/src/captions/parser.ts:112 (readTranscriptGroups) skips groups nested inside another group selector, so the .caption-block > .caption-line layout (e.g. registry/components/caption-editorial-emphasis) counts once. It also returns null unless the DOM covers exactly every transcript word.
  • Groups and words go through the same model builder as before, so the ID scheme (group-N, segment-N, wN) is unchanged for uniform grouping.
  • One behavior change to be aware of: when the DOM doesn't account for every word (parser.ts:192), the fallback is now a fixed 5 words per group instead of the old words/groups average. The PR describes this, and a partial DOM average was not reliable anyway, so I'm fine with it.
  • I checked the fixture compositions under packages/producer/tests/*/captions.html. Groups with no .word spans (e.g. style-8) still fall back to 5, which is the same result as main.

What I ran:

  • vitest run src/captions: 71/71 pass.
  • Mutation check: with main's parser.ts restored, 7 of the new cases fail ([5,2], [2,4,1], caption-line, caption-block, nested lines, incomplete DOM, regenerate + re-import). That matches the PR's claim.
  • git merge-tree against #3896's head: no conflicts, so the two caption PRs can land in either order.

— Rames

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.

Studio changes authored caption group boundaries on import

2 participants