Skip to content

fix(settings): restore theme font when selecting System - #1245

Merged
debba merged 1 commit into
TabularisDB:mainfrom
zeevenn:fix/system-font
Oct 23, 2026
Merged

debba merged 1 commit into
TabularisDB:mainfrom
zeevenn:fix/system-font

Conversation

@zeevenn

@zeevenn zeevenn commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Switching the interface font back to Theme default (System) could leave the previously selected font active because --font-base was not restored.

This change:

  • Resolves the selected font in SettingsProvider, using the current theme’s font for System.
  • Keeps applyFontToDocument focused on applying the resolved font and size.
  • Applies interface typography in a single useLayoutEffect before paint, removing duplicate startup and font-size updates.
  • Adds regression coverage for restoring the default font, including after a theme change.
Step Before After
1. Select another font Before: select another font After: select another font
2. Switch back to System Before: previous font remains active After: theme default font is restored

@kilo-code-bot

kilo-code-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

The PR now resolves System to the active theme's font in SettingsProvider and applies it from a layout effect. ThemeProvider wraps SettingsProvider in main.tsx, so the new useTheme() call is safe. The effect waits while the theme is loading, so the fallback font is not applied early, and the new tests cover the System, preview and cancel paths. One gap remains for users who pick an explicit font.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/web-ui/src/contexts/SettingsProvider.tsx 343 applyThemeToCSS always writes --font-base and runs after this layout effect. With an explicit font, a theme change or preview overwrites --font-base while body.style.fontFamily keeps the explicit font. The effect only re-runs when the theme's font string changes, so the two can diverge. The new tests cover only the System path across theme changes.
Files Reviewed (5 files)
  • packages/web-ui/src/contexts/SettingsProvider.tsx - 1 issue
  • packages/web-ui/src/utils/settings.ts
  • packages/web-ui/tests/contexts/SettingsProvider.test.tsx
  • packages/web-ui/tests/contexts/ThemeProvider.test.tsx
  • packages/web-ui/tests/utils/settings.test.ts

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit fbbdc8d)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit fbbdc8d)

Status: No Issues Found | Recommendation: Merge

The fix resolves System to the active theme's font in SettingsProvider and passes the resolved value to applyFontToDocument. This restores --font-base and the body font, including after a theme change, because themeFontFamily is a dependency of the layout effect. ThemeProvider wraps SettingsProvider in src/main.tsx, so the new useTheme() call is safe. applyFontToDocument has a single caller in src, and that caller passes an already-resolved font. The result-font effect still covers the removed eager startup call. Regression tests were added for both the provider and the util.

This incremental pass found no changes to the reviewed patch (same 5 files), and no existing inline comments or reviews to reconcile.

Files Reviewed (5 files)
  • src/contexts/SettingsProvider.tsx
  • src/utils/settings.ts
  • tests/contexts/SettingsProvider.test.tsx
  • tests/utils/settings.test.ts
  • tests/utils/settingsFont.test.ts

Previous review (commit bee609e)

Status: No Issues Found | Recommendation: Merge

The fix resolves System to the active theme's font in SettingsProvider and passes the resolved value to applyFontToDocument. This correctly restores --font-base and the body font, including after a theme change, because themeFontFamily is a dependency of the layout effect. ThemeProvider wraps SettingsProvider in src/main.tsx, so the new useTheme() call is safe. The result-font effect still covers the removed eager startup call. Regression tests were added for both the provider and the util.

Files Reviewed (5 files)
  • src/contexts/SettingsProvider.tsx
  • src/utils/settings.ts
  • tests/contexts/SettingsProvider.test.tsx
  • tests/utils/settings.test.ts
  • tests/utils/settingsFont.test.ts

Reviewed by claude-sonnet-5.5 · Input: 268 · Output: 5K · Cached: 801.5K

Review guidance: REVIEW.md from base branch main

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this fix! You found the actual root cause: with System selected, the body font was cleared, but --font-base on :root kept the previous font, so everything using var(--font-base) stayed on the old one. Resolving System to the theme's typography.fontFamily.base in SettingsProvider, with themeFontFamily as a dependency, also means the UI font now follows theme switches and theme previews. Nice. The new provider test fails on main, which is exactly what we want.

It needs a rebase, though, because main changed under you with #676:

  • SettingsProvider.tsx conflicts: main replaced invoke/listen with useTabularisClient/client.call. Keep main's client calls and re-apply your three changes: the useTheme import and themeFontFamily, dropping the eager apply in loadSettings, and the useLayoutEffect with the resolved font.
  • The frontend moved to packages/web-ui/src and the tests to packages/web-ui/tests, so tests/utils/settingsFont.test.ts has to move too.

A few nits:

  • Per .rules/testing.md, tests mirror the source files, so the settingsFont cases belong in tests/utils/settings.test.ts. Please also use the @/ alias instead of ../../src/... (same for the vi.mock in SettingsProvider.test.tsx).
  • With an explicit font like Hack, switching theme runs ThemeProvider's passive applyThemeToCSS after your layout effect, and it overwrites --font-base with the theme font. The body stays on Hack, but var(--font-base) users drift. That already happens on main, so it's not on you, but the "restores the latest theme font after a theme change" test calls the functions in an order React doesn't follow, so it can't catch this.
  • The body now gets an inline literal font-family even for System. At startup, if settings load before ThemeProvider has applied the saved theme, themes with a custom base font can briefly flash the default theme's font.

Since this is your first PR here, welcome! If you'd like to hang out with us, we'd be happy to see you on Discord: https://discord.com/invite/K2hmhfHRSt

Resolve System to the active theme before applying the UI font. Consolidate font and size updates in a layout effect and keep cache writes passive.
: getFontCSS(settings.fontFamily);
applyFontToDocument(resolvedFontFamily, settings.fontSize);
if (usesThemeFont) document.body.style.removeProperty('font-family');
}, [isLoading, isThemeLoading, settings.fontFamily, settings.fontSize, themeFontFamily]);

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.

WARNING: Explicit font can be lost from --font-base after a theme change or preview

applyThemeToCSS unconditionally writes --font-base (themeUtils.ts:131). It runs from ThemeProvider's passive useEffect, which fires after this layout effect. With an explicit font such as Hack, selecting or previewing a theme overwrites --font-base with the theme font while body.style.fontFamily keeps the explicit one. This effect then does not re-run, because themeFontFamily is the only theme-derived dependency and it is not guaranteed to change between two themes that share a font. --font-base consumers (for example result cells using inherit) can silently diverge from the chosen font.

The PR's test only covers the System path across theme changes, not an explicit font across theme changes. Consider also depending on the current theme identity (not just its font string), or re-applying the explicit font after theme application, and add a test for that case.

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for coming back to this so quickly, and for doing the rebase properly. You kept main's client calls in SettingsProvider.tsx, re-applied the fix on top, and folded the font tests into tests/utils/settings.test.ts with the @/ alias as I asked. I also like the new integration tests in ThemeProvider.test.tsx: they mount the real ThemeProvider and SettingsProvider together, so the effects now run in the order React actually uses. The one that holds the font back while the saved theme is still loading takes care of the startup flash I mentioned, and System no longer leaves an inline font on the body.

I ran the three changed test files locally (130 passing), and both regression tests fail if I put back the old SettingsProvider.tsx and settings.ts, which is what we want. pnpm build and eslint are clean too, so I'm approving.

Two small things you could look at in a follow-up if you feel like it. Neither blocks this PR:

  • With an explicit font like Hack, switching or previewing a theme still resets --font-base to the theme font, because applyThemeToCSS runs in ThemeProvider's passive effect after your layout effect. The body stays on Hack, but anything using var(--font-base) drifts. I checked and main does exactly the same, so it's not something you introduced. It would need either a theme dependency in the effect or a reapply after the theme is applied, plus a test for the explicit font case.
  • For System, applyFontToDocument writes the body font and then the provider removes it on the next line (SettingsProvider.tsx:341-342). It works, but the "body inherits from :root" rule now only lives in the provider. Moving it back into the helper (or passing a flag) would keep it in one place and let the unit test cover it.

I'll run a few manual checks in the app before merging. Thanks again!

@debba
debba merged commit 39dab01 into TabularisDB:main Oct 23, 2026
11 checks passed
@zeevenn
zeevenn deleted the fix/system-font branch October 25, 2026 03:32
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.

2 participants