Skip to content

fix(compiler): rebase composition asset paths from the file read and charge what they add - #8166

Merged
miguel-heygen merged 3 commits into
mainfrom
secbounds/asset-path-prefix
Nov 18, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
secbounds/asset-path-prefix

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

When a render inlines a mounted composition, the relative paths inside it are rebased from the folder of the file the render actually read, and every byte that rebasing adds counts toward the render's size limit, including the rebase of an entry file that sits in a subfolder.

Why

The rebase prefix came from the raw data-composition-src attribute. A query or fragment in it (scene.html?<long text with slashes>) still names the same small file, because the file lookup drops it, but the text up to its last / became part of every rebased path. Even without that, a composition in a deep real folder multiplies every short ../x reference (a srcset candidate can be 6 bytes) by the folder's length. Nothing counted those bytes, so a small project could make the compile build gigabytes of strings.

Related work

Builds on #8147 and #8144: uses the same CompositionExpansionBudget and the inliner's existing chargeEmitted callback. No second budget.

How

  • rewriteAssetPath (parsers) takes an optional charge callback and reports what each rebased reference adds over the authored one. Every rebase goes through it: attributes, srcset candidates, inline styles and CSS url() (via rewriteAssetPaths, rewriteInlineStyleAssetUrls and rewriteCssAssetUrls, which pass it on), plus hoisted link and script URLs and import-map addresses in the inliner. A charge that throws stops the rewrite at that reference, before more strings are built.
  • The core inliner takes an optional resolveFilePath(src): the project-relative file resolveHtml read. It rebases from that path instead of the attribute. The producer fills it from resolveCompositionFile, the same function that reads the mount, so the two cannot disagree. The preview bundler reads the attribute as a literal path already, so it passes nothing and keeps today's behaviour (a folder really named scenes%20# still works; htmlBundler.test.ts covers it).
  • The inliner charges rebased bytes to the mount's src through chargeEmitted; the producer's entry-file rebase now runs after the render's budget is created and charges it too.
  • The generic size error now says "Scripts, styles and rebased asset paths generated for compositions ...".
  • A sub-composition sheet without a scope id is charged once more after its rewrite (as before), so its rebased growth counts twice there. That errs toward refusing early, and only for the added bytes.

Test plan

fails without the fix: htmlCompiler.sizeLimit.test.ts "rebases from the mounted file, not a query in its src" (the query text lands in every rebased path), "refuses a mount in a deep folder whose rebased references add up past the limit" and "refuses an entry file in a deep folder ..." (both compile with no refusal on main); rewriteSubCompPaths.test.ts "reports what each rebased reference adds, for every rewrite path" (no charge on main).

  • One mutation per behaviour, each turning its test red and restored (with parsers and core rebuilt, since producer loads their built output): the inliner rebasing from the raw attribute, no charge in rewriteAssetPath, and an entry-file charge that does nothing.

  • New size-limit tests passed 3 runs in a row (about 0.55 s each for the deep-folder cases).

  • parsers src 1583 passed, core src/compiler 702 passed, producer htmlCompiler.sizeLimit.test.ts 23 and htmlCompiler.test.ts 196 passed. tsc --noEmit clean for parsers, core and producer; oxfmt, oxlint and fallow audit clean.

  • Unit tests added/updated

  • Manual testing performed (no end-to-end render)

  • Documentation updated (if applicable): no docs change

  • Comments follow CONTRIBUTING.md "Comments"

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 63 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (2)

  • seqplainkeys-none-px-r0-root-z100: error / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@terencecho terencecho 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.

Reviewed pinned head 429a981. No blocker found.

The producer supplies the project-relative file resolved by the same resolver used to read the mount, so query/fragment text no longer becomes a rebase prefix. Rebased growth flows through the shared parser callback for attributes/srcset, styles/CSS, and hoisted script/link/import-map references. Mounted and direct-entry rewrites use the render's existing budget; a refusal propagates before subsequent references are assembled. The preview bundler keeps its existing literal-path behavior. The documented conservative extra stylesheet charge is unchanged in direction.

Validation: full workspace build passed after retrying one SIGTERM. 16 parser tests, 270 core inliner/bundler tests, 23 producer size-limit tests and 196 compiler tests passed (505 total). Removing the parser charge breaks the new per-reference accounting test; restoring the raw source prefix breaks the query-path regression; disabling entry charging breaks the entry limit case; disabling mounted-path charging breaks the mount limit case. Restoring all source/build artifacts makes the parser and all three new integration cases pass again. No temporary changes remain.

The required fails-without-the-fix line is present. CI has 79 successes, 11 skipped and three still running, with no failed checks when reviewed. No end-to-end render was performed.

— tai (automated review)

…charge what they add

A mount's references now rebase from the project file the render read for
it, so a query or fragment in data-composition-src no longer lengthens every
rebased path. Every byte a rebased reference adds, including the entry file's
own rebase, is charged to the render's expansion budget as it is produced.
@miguel-heygen
miguel-heygen force-pushed the secbounds/asset-path-prefix branch from 429a981 to 38cf4d9 Compare November 18, 2026 09:28

@terencecho terencecho 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.

Re-pinned at 38cf4d9 after rebasing onto main 3b79b18, the merged #8152 commit. No blocker found in the rebase.

Range-diff shows the compiler-fix commit unchanged. Core inliner and parser implementation/test files have identical final contents to approved 429a981. I checked the resolved test-file conflict rather than relying only on the commit summary: the entire asset-path describe block is byte-identical to the approved block, and the remainder equals the merged font-test base plus the existing mkdirSync/dirname import additions. Both describe blocks, including their closing braces, are preserved independently.

The previous full build, 505 focused tests and four failing-without-the-fix checks carry forward; no tests or build were rerun for this content-verified rebase. The required fails-without-the-fix line remains. CI is running with 52 successes, eight skipped and 26 in progress, with no failed checks when reviewed.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit bb55c1e Nov 18, 2026
94 checks passed
@miguel-heygen
miguel-heygen deleted the secbounds/asset-path-prefix branch November 18, 2026 10:10
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