Skip to content

fix(snap): isolate fontconfig cache to prevent square font rendering - #3103

Merged
IsmaelMartinez merged 3 commits into
IsmaelMartinez:mainfrom
HamzaHassanM:fix/snap-fontconfig-cache-isolation
Oct 15, 2026
Merged

IsmaelMartinez merged 3 commits into
IsmaelMartinez:mainfrom
HamzaHassanM:fix/snap-fontconfig-cache-isolation

Conversation

@HamzaHassanM

@HamzaHassanM HamzaHassanM commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On modern Linux distributions such as Ubuntu 24.04 LTS, Electron Snap applications experience broken font rendering where UI text (such as system tray context menus and dialogs) renders as square boxes (tofu □□□□).

Root Cause

  1. electron-builder's core22 snap launcher runs desktop-common.sh, which defines make_user_fontconfig and unconditionally emits <cachedir>$REALHOME/.cache/fontconfig</cachedir>.
  2. The bundled snap runtime uses gnome-3-28-1804 (fontconfig 2.12.6, cache format 7), whereas modern host systems run fontconfig 2.15.0+ (cache format 11/12).
  3. The Snap's fontconfig attempts to parse host cache files with incompatible binary formats, failing glyph resolution and falling back to tofu boxes.
  4. Clearing host/snap caches manually is only a temporary workaround because the host system regenerates modern cache files as soon as fonts or packages update on the host.

Fix

  • In scripts/patchSnapDesktopLauncher.js, patch desktop-common.sh at build time to remove the $REALHOME/.cache/fontconfig reference from make_user_fontconfig. The snap now strictly uses its own isolated cache path (<cachedir prefix="xdg">fontconfig</cachedir>), mapped to $SNAP_USER_COMMON/.cache/fontconfig.
  • Clear stale snap font caches ($XDG_CACHE_HOME/fontconfig) when SNAP_DESKTOP_COMPONENTS_NEED_UPDATE="true" so existing installations upgrading to this revision automatically purge corrupt/incompatible cache.

closes #3092
refs #1105, #357

Testing

  • npm run lint (required)
  • npm run test:unit
  • Ran the app manually and exercised the affected path
  • Tested directly on Ubuntu 24.04 LTS: verified font cache isolation in snap and confirmed tray context menu renders correctly instead of tofu boxes.

Documentation

  • Updated docs-site/docs/troubleshooting.md
  • No new PII added to logs (see CLAUDE.md "Logging Guidelines")

Notes for reviewers

Unit tests were added in tests/unit/snapDesktopLauncherPatch.test.js to ensure the patch removes the host cache directory, adds the cache purge on update, and remains strictly idempotent.

RetriggerConfidence Score: 5/5

The PR appears safe to merge.

Summary

The PR isolates the Snap font cache from the host cache and clears stale Snap caches on revision updates.

  • Snap launches now keep font lookups inside the Snap’s own cache.

Reviews (3) · Last reviewed commit: "test(snap): clean up redundant inline co..." · Reviewed by Greptile

electron-builder's core22 snap launcher template injects the host's
$REALHOME/.cache/fontconfig into fonts.conf. On modern distributions
like Ubuntu 24.04 LTS, the host's fontconfig format (cache-11/12)
conflicts with the runtime's fontconfig 2.12.6 (cache-7), causing UI
text and tray context menus to render as square boxes (tofu).

Patch desktop-common.sh at build time to isolate the font cache to
$SNAP_USER_COMMON/.cache/fontconfig and avoid reading host cache files.
Also ensure stale snap font caches are cleared on revision update.

closes IsmaelMartinez#3092
refs IsmaelMartinez#1105, IsmaelMartinez#357
Comment thread docs-site/docs/troubleshooting.md Outdated
Comment thread tests/unit/snapDesktopLauncherPatch.test.js
â€Ķn format

- Address review comments by testing font cache cleanup execution under
  SNAP_DESKTOP_COMPONENTS_NEED_UPDATE=true and false.
- Ensure host font cache remains untouched during snap cache purges.
- Update troubleshooting callout syntax from GitHub alert to Docusaurus :::note.

refs IsmaelMartinez#3092
@sonarqubecloud

Copy link
Copy Markdown

@IsmaelMartinez
IsmaelMartinez requested a balanced review from Copilot October 15, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ðŸ”ĩ Needs a closer look

Compatibility with downloaded architecture-specific launcher templates remains unverified.

0 open findings

What changed in this PR

Addresses square-box text in Snap menus and dialogs by isolating fontconfig caches from the host.

Changes:

  • Removes host cache references and clears stale Snap caches on updates.
  • Adds regression coverage for isolation, cleanup, and idempotency.
  • Documents automatic isolation and older-version workarounds.
File Description
tests/​unit/​snapDesktopLauncherPatch.test.js Tests cache isolation, cleanup, and repeat patching.
scripts/​patchSnapDesktopLauncher.js Patches the launcher to isolate and refresh font caches.
docs-site/​docs/​troubleshooting.md Clarifies when manual workarounds remain necessary.

🧠 Review effort: Balanced


ðŸ’Ą Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

ðŸ“Ķ PR Snap Build Artifacts

✅ Snap builds successful! Download artifacts:

🐧 Linux Snap Packages

x86_64 (108.20 MB)

arm64 (105.53 MB)

armv7l (105.27 MB)


📝 Note: Other package formats (.deb, .rpm, .AppImage, .dmg, .exe) are built in the main workflow

View workflow run

@github-actions

Copy link
Copy Markdown
Contributor

ðŸ“Ķ PR Build Artifacts

✅ Build successful! Download artifacts:

🐧 Linux

x86_64 (436.54 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

arm64 (428.80 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

armv7l (430.56 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

🍎 macOS

x86_64 (Intel) (126.01 MB) - Contains: .dmg

arm64 (Apple Silicon) (119.11 MB) - Contains: .dmg

🊟 Windows

x86_64 (111.42 MB) - Contains: .exe installer


📝 Note: Snap packages (.snap) are built in a separate workflow

View workflow run

🕐 Last updated: 2026-10-15 06:42 UTC

Copy link
Copy Markdown
Owner

Thanks a lot @HamzaHassanM. The squares-instead-of-text bug in the snap has come back on and off for years (#357, #865, #1105, #1328, #1336, #3092), and this is the first fix that addresses the cause rather than asking people to clear caches by hand. Running the actual launcher code under bash in the test is a nice touch. We also checked the patch against the downloaded x64 and armhf launcher templates and the bundled arm64 one, and it applies cleanly to all three. Merging.


Generated by Claude Code

@IsmaelMartinez
IsmaelMartinez merged commit 383766c into IsmaelMartinez:main Oct 15, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Context menu shows only rectangles

3 participants