vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.77k stars 26.63k forks source link

next/font/local dynamic preload #56710

Open kravchenko2805 opened 11 months ago

kravchenko2805 commented 11 months ago

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/dynamic-preload-value-v5jhv4?file=%2Fpages%2Findex.tsx%3A1%2C1&embed=1

To Reproduce

Documentation says that preload takes boolean:

const isPreload = boolean;

if I'm trying to add ternary to preload:

const fontName = localFont({
  src: '...',
  weight: '...',
  preload: isPreload,
});

IDE is OK with it, but dev server falls on browser: image

Current vs. Expected behavior

Current: preload option of localFont cannot take ternary expression

Expected behavior: preload option of localFont can take ternary expression

Verify canary release

Provide environment information

Relevant Packages:
  next: 13.5.5-canary.5
  eslint-config-next: 13.4.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Font optimization (next/font)

Additional context

No response

Rishab49 commented 11 months ago

hey @kravchenko2805 I think localFont is evaluated at compile time and you are assigning it a boolean which is not known at compile time thats why you are getting that error.