Skip to content

Wrong behavior of local font's font-family handling in Turbopack #85912

@shuding

Description

@shuding

The logic to allow specifying custom font-family of a local font implemented in #76274 is for Webpack only, and not ported to Turbopack.

Webpack

font-family: variableName is only inserted when there's no custom font family set:

...(hasCustomFontFamily ? [] : [['font-family', variableName]]),

Turbopack

scoped_font_family is always inserted:

@font-face {{
{}
font-family: '{}';
src: url('@vercel/turbopack-next/internal/font/local/font?{}') format('{}');
font-display: {};
{}{}
}}
"#,
options.declarations.as_ref().map_or_else(
|| "".to_owned(),
|declarations| declarations
.iter()
.map(|declaration| format!("{}: {};", declaration.prop, declaration.value))
.join("\n")
),
scoped_font_family,

Reproduction

import localFont from 'next/font/local'

const geist = localFont({
  src: './geist.woff2',
  declarations: [
    {
      prop: 'font-family',
      value: "Geist",
    },
  ],
})

With Turbopack, the above code results in a @font-face with two font-family properties:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalid linkThe issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions