Skip to content

Bun.serve dev bundler corrupts unicode-range values in CSS @font-face rules #27598

@cursor

Description

@cursor

What version of Bun is running?

1.3.10

What platform is your computer?

Linux 6.12.58+ x86_64

What steps can reproduce the bug?

  1. Create a project using Bun.serve() with an HTML import:
// server.ts
import index from "./index.html";
Bun.serve({
  development: true,
  routes: { "/": index },
  fetch(req) { /* ... */ },
});
  1. In index.html, reference a script that imports @fontsource-variable/roboto:
<script type="module" src="./app.tsx"></script>
  1. In app.tsx:
import "@fontsource-variable/roboto";
  1. The fontsource package's index.css contains @font-face rules with unicode-range values like:
@font-face {
  font-family: "Roboto Variable";
  src: url(./files/roboto-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153;
}
  1. Load the page and inspect the CSS output served by Bun.

What is the expected behavior?

The unicode-range values should be preserved as-is:

unicode-range: U+0000-00FF,U+0131,U+0152-0153;

What do you see instead?

Bun's CSS processor strips the + from U+ prefixes and sometimes inserts spaces, producing invalid unicode-range values:

unicode-range: U0000-00FF, U0131, U0152-0153;

Some ranges also get mangled with spaces: U + A640-A69F instead of U+A640-A69F.

Because U0000-00FF is not valid CSS (the spec requires U+), browsers silently ignore the entire @font-face rule, causing fonts to not load at all.

Additional information

This affects any CSS with unicode-range processed by Bun's dev bundler (not just fontsource). The corruption occurs in Bun's built-in CSS minification/processing pipeline.

Workaround: Process font CSS via a custom [serve.static].plugins loader that reads the raw CSS and injects it via a <style> tag, bypassing Bun's CSS processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions