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

feat: disable font preloading option in qwikVite #7297

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
const fileFilter: QwikVitePluginOptions['fileFilter'] = qwikViteOpts.fileFilter
? (id, type) => TRANSFORM_REGEX.test(id) || qwikViteOpts.fileFilter!(id, type)
: () => true;
const disableFontPreload = qwikViteOpts.disableFontPreload ?? false;
const injections: GlobalInjections[] = [];
const qwikPlugin = createPlugin(qwikViteOpts.optimizerOptions);

Expand Down Expand Up @@ -549,7 +550,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
}
} else {
const selectedFont = FONTS.find((ext) => fileName.endsWith(ext));
if (selectedFont) {
if (selectedFont && !disableFontPreload) {
injections.unshift({
tag: 'link',
location: 'head',
Expand Down Expand Up @@ -1000,6 +1001,15 @@ interface QwikVitePluginCommonOptions {
* to be stable between releases
*/
experimental?: (keyof typeof ExperimentalFeatures)[];

/**
* Disables automatic preloading of font assets (WOFF/WOFF2/TTF) found in the build output. When
* enabled, the plugin will not add `<link rel="preload">` tags for font files in the document
* head.
*
* Disabling may impact Cumulative Layout Shift (CLS) metrics.
*/
disableFontPreload?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CI passes and there's no API changes, I think you need to put this jsdoc elsewhere

}

interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {
Expand Down