Skip to content

fix: treat empty custom_fonts array as intent to remove default fonts#2808

Open
Br1an67 wants to merge 1 commit intoChainlit:mainfrom
Br1an67:fix/empty-custom-fonts-array
Open

fix: treat empty custom_fonts array as intent to remove default fonts#2808
Br1an67 wants to merge 1 commit intoChainlit:mainfrom
Br1an67:fix/empty-custom-fonts-array

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Problem

When custom_fonts is set to [] in theme.json, the user intends to manage fonts themselves (e.g., via @font-face in custom_css). However, the default Inter Google Font <link> tags are still injected because [] is falsy in Python, so the condition custom_theme.get("custom_fonts") evaluates to False.

This causes:

  • Unnecessary network requests to fonts.googleapis.com
  • Breakage in air-gapped/government environments where Google domains are blocked
  • Privacy concerns (user IPs sent to Google)

Fix

  • Check for key presence ("custom_fonts" in custom_theme) instead of truthiness
  • Use if font is not None instead of if font so an empty string properly clears the default font tags via replace_between_tags

When custom_fonts is:

  • absent → default Inter preserved (backward-compatible)
  • [] → default Inter removed (user manages fonts)
  • [{...}] → custom fonts replace Inter (existing behavior)

Fixes #2804


Summary by cubic

Stop injecting the default Inter font when theme.json sets custom_fonts to []. An empty array now removes the Inter links, reducing unwanted Google requests and supporting air-gapped environments. Fixes #2804.

  • Bug Fixes
    • Check for key presence ("custom_fonts" in custom_theme) instead of truthiness so: absent → keep Inter, [] → remove Inter, [{...}] → use custom links.
    • Use if font is not None when replacing the FONT block so an empty string clears the tags.

Written for commit 0f69d69. Summary will update on new commits.

When custom_fonts is set to [] in theme.json, the user intends to manage
fonts themselves (e.g., via custom_css). Previously, empty array was falsy
in Python so the default Inter Google Font link was always preserved.

Now check for key presence instead of truthiness, and use 'is not None'
for the replacement check so an empty string properly clears the default
font tags.

Fixes Chainlit#2804
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. backend Pertains to the Python backend. bug Something isn't working labels Mar 1, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

theme.json: custom_fonts: [] should remove default Inter Google Font

1 participant