Skip to content

fix(studio): align preview fonts with render - #797

Closed
func25 wants to merge 1 commit into
heygen-com:mainfrom
func25:preview-render-fonts
Closed

fix(studio): align preview fonts with render#797
func25 wants to merge 1 commit into
heygen-com:mainfrom
func25:preview-render-fonts

Conversation

@func25

@func25 func25 commented May 13, 2026

Copy link
Copy Markdown
Contributor

What

Align Studio preview font handling with final render.

Why

Preview and render use different font handling. I found this when making a video with a quite strict text's size and position. This bug could change text width and make text layout look different between preview and final render.

How

Add a preview HTML transform hook in the Studio API. Use it in preview adapters to inject the same deterministic fonts used by render.

I only fixed the font handling. For other mismatches between preview and render, consider making another PR (or I can make it later if having more time).

Test plan

How was this tested?

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)

@miguel-heygen

Copy link
Copy Markdown
Collaborator

thanks for catching it!

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Superseded by #799, which adds error handling for the transform hook and fills in three missing test cases. Thanks for the fix!

miguel-heygen added a commit that referenced this pull request May 13, 2026
## What

Align Studio preview font handling with final render, and harden the transform hook against failures.

## Why

Preview and render use different font handling. This bug changes text width and makes text layout look different between preview and final render.

## How

- Add a `transformPreviewHtml` hook in `StudioApiAdapter` that adapters can implement to post-process preview HTML before Studio augments it
- Use it in both the Vite adapter and the CLI studio server to inject the same deterministic `@font-face` rules that render uses
- Wrap the hook in a try/catch so a failing transform (e.g. network error during Google Fonts fetch) degrades gracefully — the preview still loads with the original HTML

## Edge cases covered

| Path | Covered |
|------|---------|
| Bundled HTML (adapter returns string) | ✓ |
| Bundle returns null → reads index.html from disk | ✓ |
| Bundle throws → catch-block fallback reads index.html | ✓ |
| Sub-composition preview | ✓ |
| Transform hook throws → graceful fallback to original HTML | ✓ |

## Test plan

- [x] Unit tests added for all five paths above
- [x] Manual testing performed

Closes #797
@func25
func25 deleted the preview-render-fonts branch May 14, 2026 13:42
dahans-msft2 pushed a commit to dahans-msft2/hyperframes that referenced this pull request Aug 6, 2026
## What

Align Studio preview font handling with final render, and harden the transform hook against failures.

## Why

Preview and render use different font handling. This bug changes text width and makes text layout look different between preview and final render.

## How

- Add a `transformPreviewHtml` hook in `StudioApiAdapter` that adapters can implement to post-process preview HTML before Studio augments it
- Use it in both the Vite adapter and the CLI studio server to inject the same deterministic `@font-face` rules that render uses
- Wrap the hook in a try/catch so a failing transform (e.g. network error during Google Fonts fetch) degrades gracefully — the preview still loads with the original HTML

## Edge cases covered

| Path | Covered |
|------|---------|
| Bundled HTML (adapter returns string) | ✓ |
| Bundle returns null → reads index.html from disk | ✓ |
| Bundle throws → catch-block fallback reads index.html | ✓ |
| Sub-composition preview | ✓ |
| Transform hook throws → graceful fallback to original HTML | ✓ |

## Test plan

- [x] Unit tests added for all five paths above
- [x] Manual testing performed

Closes heygen-com#797
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.

2 participants