Skip to content

fix(core): inline and preserve sub-composition scripts in preview bundles#1068

Merged
miguel-heygen merged 3 commits into
heygen-com:mainfrom
func25:fix/subcomp-local-script-bundling
May 25, 2026
Merged

fix(core): inline and preserve sub-composition scripts in preview bundles#1068
miguel-heygen merged 3 commits into
heygen-com:mainfrom
func25:fix/subcomp-local-script-bundling

Conversation

@func25
Copy link
Copy Markdown
Contributor

@func25 func25 commented May 25, 2026

What

Fix preview bundling for sub-compositions that reference local scripts.

Makes preview bundles inline local sub-composition scripts and preserve authored script order, so required component/runtime scripts are available before inline scene scripts run.

Why

Preview bundling had two related issues:

  • local scripts referenced by sub-compositions could be left as broken external src URLs in bundled preview HTML
  • authored script order could be lost, so inline scene code could run before required globals were defined

These bugs caused preview-only runtime failures such as HTML being parsed as JS and component globals being undefined.

How

  • inline local scripts referenced by sub-compositions into preview bundles
  • preserve authored sub-composition script order while still deduplicating repeated external script sources

Test plan

How was this tested?

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

Comment thread packages/core/src/compiler/inlineSubCompositions.ts Fixed
}

export function wrapInlineScriptWithErrorBoundary(source: string, errorLabel: string): string {
return `(function(){ try { Function(${JSON.stringify(source)}).call(window); } catch (_err) { console.error(${JSON.stringify(errorLabel)}, _err); } })();`;
}

export function wrapInlineScriptWithErrorBoundary(source: string, errorLabel: string): string {
return `(function(){ try { Function(${JSON.stringify(source)}).call(window); } catch (_err) { console.error(${JSON.stringify(errorLabel)}, _err); } })();`;
@miguel-heygen miguel-heygen merged commit 375e298 into heygen-com:main May 25, 2026
44 checks passed
@func25 func25 deleted the fix/subcomp-local-script-bundling branch May 25, 2026 13:36
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.

3 participants