Skip to content

Commit

Permalink
Turbopack next/font/google: don't insert css rules for multiple weigh…
Browse files Browse the repository at this point in the history
…ts or styles (#55852)

If multiple weights or styles are requested, e.g. `Open_Sans({ weight: ['300', '400']})` or `Open_Sans({ style: ['normal', 'italic']})`, don't insert css rules for those properties.

Prior behavior was to insert the first ('300' or 'normal' in the above cases), which did not match webpack's behavior.


Closes WEB-1645
  • Loading branch information
wbinnssmith committed Sep 25, 2023
1 parent 1d86a09 commit df3c1b8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/next-swc/crates/next-core/src/next_font/google/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,21 @@ async fn get_font_css_properties(
font_family: Vc::cell(font_families.join(", ")),
weight: Vc::cell(match &options.weights {
FontWeights::Variable => None,
FontWeights::Fixed(weights) => weights.first().map(|w| w.to_string()),
FontWeights::Fixed(weights) => {
if weights.len() > 1 {
// Don't set a rule for weight if multiple are requested
None
} else {
weights.first().map(|w| w.to_string())
}
}
}),
style: Vc::cell(if options.styles.len() > 1 {
// Don't set a rule for style if multiple are requested
None
} else {
options.styles.first().cloned()
}),
style: Vc::cell(options.styles.first().cloned()),
variable: Vc::cell(options.variable.clone()),
}))
}
Expand Down

0 comments on commit df3c1b8

Please sign in to comment.