Skip to content

fix(css): inject inlined CSS after the shebang line#22717

Open
shulaoda wants to merge 1 commit into
mainfrom
shulaoda/06-19-fix_css_inject_inlined_css_after_the_shebang_line
Open

fix(css): inject inlined CSS after the shebang line#22717
shulaoda wants to merge 1 commit into
mainfrom
shulaoda/06-19-fix_css_inject_inlined_css_after_the_shebang_line

Conversation

@shulaoda

Copy link
Copy Markdown
Member

For es-format chunks that start with a shebang, injectInlinedCSS inserted the CSS-injection code into the shebang line instead of after it.

Problem

  • The injection point was set to the index of the first \n, and s.appendRight(index, ...) inserts before that character — i.e. at the end of the shebang line.
  • Result for #!/usr/bin/env node\n<body>: #!/usr/bin/env nodeinjectCSS();\n<body>.
  • This breaks two things at once:
    • The shebang line no longer points at a valid interpreter, so the file is no longer executable.
    • JS treats the leading #!... line as a hashbang comment, so the appended injection code is dropped — the inlined CSS is never injected.
  • The no-newline fallback (= 0) was also wrong: it prepended the code before the shebang.

Fix

  • Inject after the shebang's newline (newlinePos + 1), matching how importAnalysisBuild.ts handles the same case (indexOf('\n') + 1).
  • When the shebang has no trailing newline, append \n + the injection so the shebang stays on its own line.

Tests

  • Added es-format cases for: shebang, no shebang (regression guard), and shebang without a trailing newline. The shebang cases fail without this change and pass with it.

@shulaoda shulaoda requested review from sapphi-red and removed request for sapphi-red June 19, 2026 11:40
@shulaoda shulaoda marked this pull request as draft June 19, 2026 12:28
@shulaoda shulaoda marked this pull request as ready for review June 19, 2026 13:00
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.

1 participant