Repository navigation
fix(settings): restore theme font when selecting System - #1245
Conversation
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge The PR now resolves Overview
Issue Details (click to expand)WARNING
Files Reviewed (5 files)
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 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)
Previous review (commit bee609e)Status: No Issues Found | Recommendation: Merge The fix resolves Files Reviewed (5 files)
Reviewed by claude-sonnet-5.5 · Input: 268 · Output: 5K · Cached: 801.5K Review guidance: REVIEW.md from base branch |
bee609e to
fbbdc8d
Compare
debba
left a comment
There was a problem hiding this comment.
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.tsxconflicts: main replacedinvoke/listenwithuseTabularisClient/client.call. Keep main's client calls and re-apply your three changes: theuseThemeimport andthemeFontFamily, dropping the eager apply inloadSettings, and theuseLayoutEffectwith the resolved font.- The frontend moved to
packages/web-ui/srcand the tests topackages/web-ui/tests, sotests/utils/settingsFont.test.tshas to move too.
A few nits:
- Per
.rules/testing.md, tests mirror the source files, so the settingsFont cases belong intests/utils/settings.test.ts. Please also use the@/alias instead of../../src/...(same for thevi.mockinSettingsProvider.test.tsx). - With an explicit font like Hack, switching theme runs
ThemeProvider's passiveapplyThemeToCSSafter your layout effect, and it overwrites--font-basewith the theme font. The body stays on Hack, butvar(--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-familyeven for System. At startup, if settings load beforeThemeProviderhas 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.
fbbdc8d to
2467091
Compare
| : getFontCSS(settings.fontFamily); | ||
| applyFontToDocument(resolvedFontFamily, settings.fontSize); | ||
| if (usesThemeFont) document.body.style.removeProperty('font-family'); | ||
| }, [isLoading, isThemeLoading, settings.fontFamily, settings.fontSize, themeFontFamily]); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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-baseto the theme font, becauseapplyThemeToCSSruns inThemeProvider's passive effect after your layout effect. The body stays on Hack, but anything usingvar(--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,
applyFontToDocumentwrites 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!
Switching the interface font back to Theme default (
System) could leave the previously selected font active because--font-basewas not restored.This change:
SettingsProvider, using the current theme’s font for System.applyFontToDocumentfocused on applying the resolved font and size.useLayoutEffectbefore paint, removing duplicate startup and font-size updates.