Skip to content

feat(preferences): add UI + code font selection via Google Fonts#5951

Open
yazilimalanlari wants to merge 2 commits into
usememos:mainfrom
yazilimalanlari:feat/preferences-font-selection
Open

feat(preferences): add UI + code font selection via Google Fonts#5951
yazilimalanlari wants to merge 2 commits into
usememos:mainfrom
yazilimalanlari:feat/preferences-font-selection

Conversation

@yazilimalanlari
Copy link
Copy Markdown

Add ui_font and code_font fields to user general settings so each user can pick a UI sans-serif and a monospaced code font independently. Fonts are loaded directly from Google Fonts' public CSS endpoint — no API key required.

The Preferences > Appearance section gets two new rows: each offers a curated list of popular families (Inter, Bricolage Grotesque, JetBrains Mono, Cascadia Code, Recursive, …) plus a "Custom…" option that accepts any Google Fonts family name. Selections are applied immediately, persisted via UpdateUserSetting, and re-applied early on page load (localStorage cache) to avoid a flash of the wrong typeface.

Custom family inputs are validated against an ASCII allowlist so they can't inject CSS or URL syntax into the generated /<style> tags.


Screenshot 2026-05-13 at 23 26 09
Screen.Recording.2026-05-13.at.23.28.11.mov

Add `ui_font` and `code_font` fields to user general settings so each user
can pick a UI sans-serif and a monospaced code font independently. Fonts are
loaded directly from Google Fonts' public CSS endpoint — no API key required.

The Preferences > Appearance section gets two new rows: each offers a curated
list of popular families (Inter, Bricolage Grotesque, JetBrains Mono,
Cascadia Code, Recursive, …) plus a "Custom…" option that accepts any Google
Fonts family name. Selections are applied immediately, persisted via
`UpdateUserSetting`, and re-applied early on page load (localStorage cache)
to avoid a flash of the wrong typeface.

Custom family inputs are validated against an ASCII allowlist so they can't
inject CSS or URL syntax into the generated <link>/<style> tags.
@yazilimalanlari yazilimalanlari requested a review from a team as a code owner May 13, 2026 20:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f711d6d-3a55-4ec5-8d2d-e13bd620e867

📥 Commits

Reviewing files that changed from the base of the PR and between ede6390 and d0a6207.

📒 Files selected for processing (2)
  • web/src/components/Settings/PreferencesSection.tsx
  • web/src/utils/font.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/components/Settings/PreferencesSection.tsx
  • web/src/utils/font.ts

📝 Walkthrough

Walkthrough

This PR adds user-configurable font selection across the memos application. Proto schemas define ui_font and code_font fields; the server handles persistence and API conversion. A comprehensive font utility library manages Google Fonts loading, CSS variable injection, localStorage persistence, and early bootstrap to prevent typeface flash. A FontSelect component enables selection from presets or custom families. The preferences settings UI integrates font pickers, and app initialization applies preferences both reactively and at startup.

Changes

Font Selection and Loading System

Layer / File(s) Summary
Proto schemas and server integration
proto/api/v1/user_service.proto, proto/store/user_setting.proto, server/router/api/v1/user_service.go, web/src/types/proto/api/v1/user_service_pb.ts
Proto API and storage add ui_font and code_font fields to GeneralSetting and GeneralUserSetting. Server defaults, update initialization, update-mask handling, and API↔storage conversion all extended to include fonts. Generated TypeScript types updated to match.
Font utilities and system
web/src/utils/font.ts
Core font system exports UI/code font option lists, validates Google Fonts family names, constructs css2 stylesheet URLs, manages DOM <link> and <style> elements, safely wraps localStorage, loads and persists fonts with fallback chain resolution, applies fonts early before React, and validates custom font input.
FontSelect UI component
web/src/components/FontSelect.tsx
Reusable dropdown component with preset font options and custom entry. Handles internal selection state via sentinel values, validates custom fonts, commits on blur or Enter, and synchronizes with prop changes.
Settings UI integration
web/src/components/Settings/PreferencesSection.tsx
Adds UI and code font change handlers that immediately apply and persist font choices. Initializes default general settings with empty font fields. Renders two new appearance rows using FontSelect to pick and apply fonts.
App initialization and early bootstrap
web/src/hooks/useUserFonts.ts, web/src/App.tsx, web/src/main.tsx
useUserFonts hook applies user font preferences reactively. App invokes the hook. main.tsx calls applyFontsEarly() during startup to apply stored fonts before React mounts, alongside theme and locale early application.
Localization
web/src/locales/en.json
English locale strings for UI font, code font, custom font option, and descriptions under setting.preference.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main feature addition: per-user UI and code font selection via Google Fonts across the Preferences interface.
Description check ✅ Passed The description comprehensively explains the feature, implementation details, security measures, and includes visual demonstration; it is directly related to the font selection changes throughout the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
web/src/utils/font.ts (1)

64-64: 💤 Low value

Consider documenting the + character in the regex comment.

The regex pattern allows + (e.g., for "M PLUS 1" font family), but line 62's comment only mentions "occasionally periods." While not incorrect, explicitly mentioning all special characters would improve clarity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/utils/font.ts` at line 64, The comment describing the regular
expression for FAMILY_PATTERN should explicitly mention the allowed special
characters (including the plus sign '+', hyphen '-', space and period '.') so
readers understand why characters like "M PLUS 1" are permitted; update the
comment that precedes the const FAMILY_PATTERN = /^[A-Za-z0-9 .\-+]{1,64}$/ to
list those characters and a brief rationale (e.g., common font names may include
'+' as in "M PLUS 1").
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/src/utils/font.ts`:
- Line 64: The comment describing the regular expression for FAMILY_PATTERN
should explicitly mention the allowed special characters (including the plus
sign '+', hyphen '-', space and period '.') so readers understand why characters
like "M PLUS 1" are permitted; update the comment that precedes the const
FAMILY_PATTERN = /^[A-Za-z0-9 .\-+]{1,64}$/ to list those characters and a brief
rationale (e.g., common font names may include '+' as in "M PLUS 1").

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fb1c679-7c9f-4976-9ccc-6a3e241aa933

📥 Commits

Reviewing files that changed from the base of the PR and between cf55f11 and ede6390.

⛔ Files ignored due to path filters (3)
  • proto/gen/api/v1/user_service.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • proto/gen/openapi.yaml is excluded by !**/gen/**
  • proto/gen/store/user_setting.pb.go is excluded by !**/*.pb.go, !**/gen/**
📒 Files selected for processing (11)
  • proto/api/v1/user_service.proto
  • proto/store/user_setting.proto
  • server/router/api/v1/user_service.go
  • web/src/App.tsx
  • web/src/components/FontSelect.tsx
  • web/src/components/Settings/PreferencesSection.tsx
  • web/src/hooks/useUserFonts.ts
  • web/src/locales/en.json
  • web/src/main.tsx
  • web/src/types/proto/api/v1/user_service_pb.ts
  • web/src/utils/font.ts

@boojack
Copy link
Copy Markdown
Member

boojack commented May 14, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ede639002f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/components/Settings/PreferencesSection.tsx Outdated
… succession

Track the applied UI and code font selections in local state and feed
that into loadFonts() so a follow-up change doesn't read a stale
setting snapshot before refetch completes. Also clarifies the
FAMILY_PATTERN regex comment to mention plus signs.
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