feat: pass the source file name to the preload filter for fonts - #16443
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/1a83c001ff3fd063174e3b2b298eea993286989bOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 1a83c00 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
274fa31 to
be0eacd
Compare
extracts the drive-by improvements in #16443 to reduce the size of that diff (am weighing a slightly different approach, but this change unambiguously makes sense) --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
|
Merged #16445 back in, the diff is feature-only now. |
name to the preload filter for fonts and assetsname to the preload filter for fonts
|
Reworked, |
Assets are emitted as `[name].[hash][extname]`, so the source file name can be recovered from the output path without a manifest lookup. The font and modulepreload paths each branched on `link_header_preload` themselves; a Link header value is the `<link>` attribute list joined with `; ` plus `nopush`, so one helper now covers both.
0f6fcc8 to
f21575c
Compare
Rich-Harris
left a comment
There was a problem hiding this comment.
tweaked it so that it's the project relative filename rather than just the base name — allows for things like filename.includes('@fontsource') and so on
The docs say to opt fonts into preloading with a `preload` filter but not what to match against, so what everyone writes is a substring check against the hashed output path, which silently stops matching when the font is renamed. #16443 added `filename` for this; this shows it. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] This message body should clearly illustrate what problems it solves. - [ ] Ideally, include a test that fails without this PR but passes with it. ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [ ] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed. --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
Implements the
nameproperty from #16424 (comment).nameis looked up from the Vite client manifest where the fonts arrays are built, so the filter receives the exact source file name. Deriving it from the emitted path was wrong two ways, the bundler sanitizes characters (inter+bold.woff2is emitted asinter_bold.<hash>.woff2) and content-identical assets are emitted once under a single name. The union includesnameforfontonly, kit never callspreloadwith typeasset.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits