Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): EPUB previews load styles imported without a space after @import #48126

ClosedStiensWout(GitHub profile, opens in a new tab)wants to merge 7 commits intomain fromrefs/pull/48126/headopened View on GitHub

EPUB chapters whose stylesheet import has no whitespace after the keyword showed default formatting. This covers a quoted URL right after @import (@import"chapter.css";) and a comment used as the separator (@import/**/url(chapter.css);). Both are valid CSS, but the preview's import parser required whitespace after @import. The parser now also accepts a quoted URL directly after the keyword and CSS comments as the separator, while keeping the at-keyword boundary, so the imported stylesheet's formatting appears.

Reproduction on main

Commit 71217d7188 (main). The chapter text appears with default formatting. Expected: The chapter shows the formatting from the bundled stylesheet.

  1. Add an EPUB whose chapter uses @import"chapter.css"; to load a stylesheet bundled in the book.
  2. Open the EPUB from the workspace file picker.
  3. Read the chapter that uses the imported stylesheet.

The cause is at apps/web/src/components/files/epubPreview.ts:706. Ran pnpm scenarios:prove scripts/scenarios/epub-preview-loads-compact-import.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean boat.dev VM, with expected "rgb(0, 0, 0)" to be "rgb(0, 90, 190)" in the output.

Evidence

Environment: The web app in Chromium on Linux x64, a fresh checkout on a boat.dev VM reset before each run.

Proven: the repro fails at the test commit 5121406272 and passes on the head 752ff85933, both on main 3eb5894919.

BeforeAfter
Commit5121406272752ff85933
ResultASSERTION_FAILED: expected "rgb(0, 0, 0)" to be "rgb(0, 90, 190)"passed
epub chapter formattingBefore: epub chapter formatting Before: epub chapter formatting (changed region)
The chapter text appears with default formatting.
After: epub chapter formatting After: epub chapter formatting (changed region)
The chapter shows the formatting from the bundled stylesheet.
failureBefore: failure
RecordingBefore: recordingAfter: recording

Tests

  • 5121406272 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed 3eb58949194ce010be0af51d861d3292127e8a37 passed on head.

Not in this change

  • SVG chapter styles share the same parser and are fixed too, but no separate test covers them.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by GPT 6.2 Sol and Claude Opus 5.5

    1. tanstack-source added labelsbug

    2. @@ -703,4 +703,4 @@
      703703 css = css.replace(/^\uFEFF/, "").replace(/^\s*@charset\s+["'][^"']+["']\s*;/i, "");
      704704 // `(?=(x))\1` makes the target and the tail atomic; backtracking into them is quadratic.
      705705 const prelude =
      706- /^\s*(?:\/\*[\s\S]*?\*\/\s*)*@import\s+(?:url\(\s*)?(?:"(?=((?:\\[\s\S]|[^"\\])+))\1"|'(?=((?:\\[\s\S]|[^'\\])+))\2'|(?=((?:\\(?:[\da-f]{6}|[\da-f]{1,5}(?![\da-f]))(?:\r\n|[ \t\r\n\f])?|\\[^\da-f]|[^\s;)\\])+))\3)(?=(\s*\)?\s*([^;]*)))\4;/i;
      706+ /^\s*(?:\/\*[\s\S]*?\*\/\s*)*@import(?:(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?=["'])|(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)+(?:url\(\s*)?)(?:"(?=((?:\\[\s\S]|[^"\\])+))\1"|'(?=((?:\\[\s\S]|[^'\\])+))\2'|(?=((?:\\(?:[\da-f]{6}|[\da-f]{1,5}(?![\da-f]))(?:\r\n|[ \t\r\n\f])?|\\[^\da-f]|[^\s;)\\])+))\3)(?=(\s*\)?\s*([^;]*)))\4;/i;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High files/epubPreview.ts:706

      A malformed @import followed by many comments and no terminating ; makes this regex backtrack quadratically, blocking the JavaScript thread while addStyle processes the stylesheet. The + separator backtracks across comments while the unquoted-URL branch rescans the remaining input; make the separator atomic with a lookahead/backreference, as is already done for the target and tail.

      ✅ Resolved in 3f40bc1c5f37ea58f1015542f85ed0cdfdec79b0

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 3f40bc1

      Macroscope's review found this PR approvable — EPUB previews now recognize additional valid CSS import syntax. The change retains archive-local resolution and existing import limits, keeping its impact confined to preview styling.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The EPUB preview import matcher now handles compact and comment-separated CSS imports. Unit tests cover additional import forms and stylesheets with many comments. An end-to-end test checks the computed chapter text color after previewing an EPUB with a compact import.

      Changes: EPUB CSS imports

      Layer / File(s)Summary
      Import matching and unit coverage
      apps/web/src/components/files/epubPreview.ts, apps/web/src/components/files/FilePreviewPanel.test.ts
      The addStyle matcher uses an anchored pattern to capture import targets and conditions. Unit tests cover escaped URLs, compact imports, comment-separated tokens, and preservation of stylesheets with many comments.
      EPUB preview end-to-end validation
      scripts/scenarios/epub-preview-loads-compact-import.e2e.ts
      The scenario previews an EPUB with a compact @import and checks the chapter text's computed color.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: iamshadmantaqi, only21mil

      Merge Risk: Minimal · up to 3f40b

      EPUB chapter stylesheets imported without a space after @import should now load in the preview. No merge-blocking risk was found.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the actual change: EPUB previews now load stylesheets imported without a space after @import. The changeset matches this, with the epubPreview.ts import-parser change, new tests, and a…
      Description checkPassedThe description follows the repository template. It has a clear Problem section with reproduction steps and expected behavior, a Change section explaining the parser update, a Scope section that descr…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the actual change: EPUB previews now load stylesheets imported without a space after @import. The changeset matches this, with the epubPreview.ts import-parser change, new tests, and an e2e scenario for the compact import form. The title is specific and follows the conventional commit style.

      Full details: Description check

      Explanation

      The description follows the repository template. It has a clear Problem section with reproduction steps and expected behavior, a Change section explaining the parser update, a Scope section that describes a bug fix and cites the reproduction commit, and a detailed Verification section with a before/after table, test results, and screenshots or recordings. It also includes the model and harness attribution the template asks for. The Scope section does not link a GitHub issue. It gives no reason for skipping one, and it does not mention a maintainer request, so that part is incomplete. This is a minor gap and does not affect the overall assessment.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 752ff85933fec449c2d683a915a5f7d1e5cdc559 and 3f40bc1c5f37ea58f1015542f85ed0cdfdec79b0.

      Files selected for processing: 2

      • apps/web/src/components/files/FilePreviewPanel.test.ts
      • apps/web/src/components/files/epubPreview.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

    5. juliusmarminge added labelstakeover:in-progress

    1. Pushed3f40bc1

    2. The automated pipeline stopped on this pull request and will not merge it:

      the proof could not be captured: the agent's turn was cut short: failed

      It stays open for a person to finish or close.

    3. juliusmarminge added labelstakeover:blocked

    4. juliusmarminge removed labelstakeover:in-progress

Sign in to join this conversation.