-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preload fonts using ReactDOM.preload (#48931)
This PR updates the way we preload fonts. Previously we tracked which fonts we needed to preload for each layer and rendered a `<link rel="preload" href="..." as="font" />` tag for each preloadable font. This unfortunately gets blocked by data fetching and we want to be able to hint these preloads as soon as possible. Now that React support Float methods in RSC we can use `ReactDOM.preload(..., { as: "font" })` to implement this functionality This PR makes the following changes 1. expose a `preloadFont` method through the RSC graph 2. expose a `preconnect` metho through the RSC graph 3. refactor the preloads generation to use `preloadFont` instead of rendering a preload link 4. If there are no fonts to preload but fonts are being used in CSS then a `preconnect` asset origin is called instead of rendering a preconnect link 5. instead of emitting a data attribute per font preload indicating whether the project is using size-adjust we now emit a single global meta tag. In the future we may get more granular about which fonts are being size adjusted. In the meantime the current hueristic is to add `-s` to the filename so it can still be inferred. In the process of completing this work I discovered there were some bugs in how the preconnect logic was originally implemented. Previously it was possible to get multiple preconnects per render. Additionally the preconnect href was always `"/"` which is not correct if you are hosting your fonts at a CDN. The refactor fixed both of these issues I want to do a larger refactor of the asset loading logic in App-Render but I'll save that for a couple weeks from now Additionally, the serialized output of preloads now omits the word anonymous when using crossorigin so tests were updated to reflect `crossorigin=""` Additionally, tests were updated to no longer look for the size-adjust data attribute on preloads Additionally, There is a note about leaving a `{null}` render in place to avoid a conflict with how the router models lazy trees. I'll follow up with a PR addressing this Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
799a05c
commit 4f5f476
Showing
7 changed files
with
84 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters