Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: preload: false does not work for custom font #70

Open
ChristopherJohnson25 opened this issue Jul 11, 2024 · 1 comment
Open

[Bug]: preload: false does not work for custom font #70

ChristopherJohnson25 opened this issue Jul 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ChristopherJohnson25
Copy link

Demo URL

No response

What happened?

setting preload: false does not work for custom font

Reproduction steps

1. add preload: false to options
2. observe that fonts are still preloaded

Relevant log output

No response

What browsers are you seeing the problem on?

Chrome

What is your operating system?

MacOS

@ChristopherJohnson25 ChristopherJohnson25 added the bug Something isn't working label Jul 11, 2024
@BenBE
Copy link

BenBE commented Sep 5, 2024

While reading through the source code, I noticed, that generating tags is unconditional for all generated link tags. Thus whenever a bundled asset matches the filename pattern for a font file, there will be a tag for it. Kinda unintuitively the settings under options.custom.prefetch and options.custom.preload are applied for all fonts, including Google Fonts, Font Source, etc.

Unfortunately, there's a bit of code duplication for the actual link tag generation, which makes the fix for this a bit spread all around the code base.

The outline for this is basically:

  • Find all places where getHeadLinkTags is called.
  • Look at the for (const file of files) loop directly below
  • The tags.push() there needs to be conditional on options.custom.prefetch || options.custom.preload

While at it and looking in the context of #10, after that for loop is also the ideal place to introduce a new callback options.custom.linkFilter hook, that in the simplest case just receives the tags array and could then do:

  • return true -> return tags unaltered
  • return false -> return no tags
  • return a modified tag array -> forward the modified choice of headers to generate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants