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

Performance: use inter static fonts #12501

Merged
merged 5 commits into from
Mar 22, 2024
Merged

Performance: use inter static fonts #12501

merged 5 commits into from
Mar 22, 2024

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Mar 19, 2024

Description

Replaces the current variable inter font with static ones to improve loading times.

The variable font we are using is too heavy ~800kb. Loading the necessary static subset will improve the overall loading times.

Since next/local doesn't support unicode-range atm, we are loading and preloading the fonts manually.

Summary by CodeRabbit

  • Refactor
    • Updated the font system across the app for improved readability and performance.
  • New Features
    • Added support for preloading the Inter font for faster text rendering.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2024

Walkthrough

The changes involve updating the font handling in a web application. The inter font declaration was removed, and settings were adjusted to preload the mono font with a new property. The project transitioned to using the Inter, sans-serif font, including adding a preload link for it and importing it from Google Fonts. Adjustments were made in global CSS to incorporate these changes, ensuring the application uses the updated font settings efficiently.

Changes

File(s) Change Summary
src/lib/fonts.ts Removed inter font declaration; added preload: false to mono font.
src/pages/_app.tsx Switched font usage from inter to Inter, sans-serif; updated global CSS variables.
src/pages/_document.tsx Added preload link for inter static web font in the head section.
src/styles/global.css Imported the Inter font from Google Fonts; defined font-face rules for various sets and weights.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added content 🖋️ This involves copy additions or edits review needed 👀 tooling 🔧 Changes related to tooling of the project labels Mar 19, 2024
Copy link

netlify bot commented Mar 19, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 2076622
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65fbfdfb85298b00083fe8ed
😎 Deploy Preview https://deploy-preview-12501--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pettinarip pettinarip changed the title Use inter static font Use inter static fonts Mar 19, 2024
@pettinarip pettinarip changed the title Use inter static fonts Performance: use inter static fonts Mar 19, 2024
@pettinarip pettinarip marked this pull request as ready for review March 20, 2024 10:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f920ff1 and fe009f0.
Files ignored due to path filters (8)
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa0ZL7SUc.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1pL7SUc.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa25L7SUc.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2JL7SUc.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2ZL7SUc.woff2 is excluded by: !**/*.woff2
  • public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2pL7SUc.woff2 is excluded by: !**/*.woff2
  • src/fonts/Inter-VariableFont_slnt,wght.ttf is excluded by: !**/*.ttf
Files selected for processing (4)
  • src/lib/fonts.ts (1 hunks)
  • src/pages/_app.tsx (2 hunks)
  • src/pages/_document.tsx (1 hunks)
  • src/styles/global.css (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/styles/global.css
Additional comments: 3
src/lib/fonts.ts (1)
  • 9-9: The addition of preload: false to the mono font declaration aligns with the PR's objectives to optimize font loading. However, it's important to verify that this change does not adversely affect the loading times or performance of the mono font itself.
src/pages/_document.tsx (1)
  • 32-39: The preload link for the inter static web font is correctly implemented and should contribute to improved font loading times. Ensure that the specified font file path (/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2) is correct and the font file is accessible.
src/pages/_app.tsx (1)
  • 42-42: The changes to the global CSS variables for fonts (--font-inter and --font-mono) are correctly implemented and align with the PR's objectives. Ensure that these changes are consistently applied across the application to maintain uniform font rendering.
Verification successful


The changes to the global CSS variables for fonts (--font-inter and --font-mono) are correctly implemented in src/pages/_app.tsx and are also referenced in src/@chakra-ui/foundations/typography.ts. This confirms the consistent application of these font changes across the application, aligning with the PR's objectives. Ensure that these changes are consistently applied and tested across all relevant parts of the application to maintain uniform font rendering.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the consistent application of font changes across the application
rg --type css --type html --type js --type tsx '--font-inter' --files-with-matches
rg --type css --type html --type js --type tsx '--font-mono' --files-with-matches

Length of output: 993



Script:

#!/bin/bash
# Correctly search for occurrences of '--font-inter' and '--font-mono' across the application
rg --type css --type html --type js --type tsx '--font-inter' --files-with-matches
rg --type css --type html --type js --type tsx '--font-mono' --files-with-matches

Length of output: 993



Script:

#!/bin/bash
# Correctly search for occurrences of '--font-inter' and '--font-mono' across the application using the correct syntax
rg --type css --type html --type js --type tsx -e '--font-inter' --files-with-matches
rg --type css --type html --type js --type tsx -e '--font-mono' --files-with-matches

Length of output: 226



Script:

#!/bin/bash
# Correctly search for occurrences of '--font-inter' and '--font-mono' across the application, excluding the unsupported 'tsx' file type
rg --type css --type html --type js --type ts -e '--font-inter' --files-with-matches
rg --type css --type html --type js --type ts -e '--font-mono' --files-with-matches

Length of output: 288

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

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

Bummer that the variable font is so bulky, but agree that performance takes precedent here. My only request would be to use descriptive filenames instead of hashes so they're easier to reference/trace/understand. Otherwise looks good!

Copy link
Member

Choose a reason for hiding this comment

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

Hm... is there any way we could clean up the typeface file names here so they're descriptive?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good call. Yeah, I can definitely do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2JL7SUc.woff2 -> public/fonts/inter/cyrillic-ext.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa0ZL7SUc.woff2 -> public/fonts/inter/cyrillic.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2ZL7SUc.woff2 -> public/fonts/inter/greek-ext.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1pL7SUc.woff2 -> public/fonts/inter/greek.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa25L7SUc.woff2 -> public/fonts/inter/latin-ext.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2 -> public/fonts/inter/latin.woff2
renamed:    public/fonts/inter/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa2pL7SUc.woff2 -> public/fonts/inter/vietnamese.woff2

@nhsz
Copy link
Member

nhsz commented Mar 20, 2024

@pettinarip This change causes to execute more requests (and some fonts are failing), we would need to measure it to be sure its improving the performance, example of fonts loading on the homepage below

Screen Shot 2024-03-20 at 18 23 37

@pettinarip
Copy link
Member Author

@pettinarip This change causes to execute more requests (and some fonts are failing), we would need to measure it to be sure its improving the performance, example of fonts loading on the homepage below

Screen Shot 2024-03-20 at 18 23 37

You might have some of them cached or coming from a different source (extenstions perhaps?) because the ones that are failing are not being declared in this PR. There are others there in the screenshot that are also not part of this PR, they are probably coming from Netlify, for the Netlify UI elements of the preview deploy. Try to test this in incognito mode and lmk the results you get 🙏🏼

The other fonts, are ok, expected. The first 2 fonts are the most relevant fonts loaded here. The latin one is preloaded, the rest are loaded after the website is fully loaded and ready, so that is not going to affect the overall performance of the site.

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

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

image

This is working great for me locally with fresh cache, and no Netlify additions.

Copy link
Member

@nhsz nhsz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@nhsz nhsz merged commit 351a874 into dev Mar 22, 2024
10 checks passed
@nhsz nhsz deleted the static-inter-font branch March 22, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content 🖋️ This involves copy additions or edits tooling 🔧 Changes related to tooling of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants