Skip to content

Conversation

@asanehisa
Copy link
Contributor

@asanehisa asanehisa commented Dec 1, 2025

Ben:
Tested via FontApiServer srv deployed to dev + VLE dev mode

Confirmed that a custom font that I uploaded (Chillax) appeared in the font dropdown and was selectable.
Screenshot 2025-12-04 at 10 44 21 AM

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

Warning: Component files have been updated but no migrations have been added. See https://github.com/yext/visual-editor/blob/main/packages/visual-editor/src/components/migrations/README.md for more information.

@asanehisa asanehisa marked this pull request as ready for review December 2, 2025 14:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

Introduces runtime custom-font support by adding and exporting createDefaultThemeConfig(customFonts?: FontRegistry): ThemeConfig and deriving defaultThemeConfig from it. TemplateMetadata gains an optional customFonts?: FontRegistry. Editor now detects when the active themeConfig equals defaultThemeConfig and templateMetadata.customFonts is present, then calls createDefaultThemeConfig(customFonts) to produce finalThemeConfig and passes that to ThemeEditor and LayoutEditor. New tests were added to verify merging and overriding behavior of h1 font options.

Sequence Diagram(s)

sequenceDiagram
  participant TemplateMetadata
  participant Editor
  participant DefaultThemeConfig as createDefaultThemeConfig()
  participant ThemeEditor
  participant LayoutEditor

  TemplateMetadata->>Editor: mount/update (may include customFonts)
  Editor->>Editor: compare themeConfig === defaultThemeConfig
  alt templateMetadata.customFonts present AND themeConfig is defaultThemeConfig
    Editor->>DefaultThemeConfig: createDefaultThemeConfig(customFonts)
    DefaultThemeConfig-->>Editor: finalThemeConfig
    Editor->>ThemeEditor: render(finalThemeConfig)
    Editor->>LayoutEditor: render(finalThemeConfig)
  else
    Editor->>ThemeEditor: render(themeConfig)
    Editor->>LayoutEditor: render(themeConfig)
  end
Loading

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature being added: enabling custom fonts to appear and be selectable in the theme editor.
Description check ✅ Passed The description relates to the changeset by documenting testing of the custom fonts feature in the theme editor, including a screenshot demonstrating the functionality.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch use-custom-fonts

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbedc7b and db04265.

📒 Files selected for processing (2)
  • packages/visual-editor/src/components/DefaultThemeConfig.test.ts (1 hunks)
  • packages/visual-editor/src/internal/types/templateMetadata.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/visual-editor/src/components/DefaultThemeConfig.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/visual-editor/src/internal/types/templateMetadata.ts (1)
packages/visual-editor/src/utils/index.ts (1)
  • FontRegistry (44-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: call_unit_test / unit_tests (18.x)
  • GitHub Check: call_unit_test / unit_tests (20.x)
  • GitHub Check: semgrep/ci
🔇 Additional comments (1)
packages/visual-editor/src/internal/types/templateMetadata.ts (1)

22-22: Optional field addition is correct.

The customFonts field is properly added as optional. Since it's marked with ?, generateTemplateMetadata() doesn't need to populate it—other code paths or production configurations can populate this field as needed.


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
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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/visual-editor/src/internal/types/templateMetadata.ts (1)

1-23: customFonts field wiring looks good; consider import type

The optional customFonts?: FontRegistry addition integrates cleanly into TemplateMetadata and matches its usage in Editor.tsx.

Since FontRegistry is only used as a type here, you could switch to a type-only import to avoid any chance of it being treated as a runtime dependency:

-import { FontRegistry } from "@yext/visual-editor";
+import type { FontRegistry } from "@yext/visual-editor";

Not required, but slightly clearer and can help tree‑shaking.

packages/visual-editor/src/editor/Editor.tsx (1)

21-24: Custom-font application logic is sound but relies on reference equality and default presence

The finalThemeConfig logic is a nice, minimal way to layer custom fonts without affecting callers that supply their own configs:

let finalThemeConfig = themeConfig;
// ...
if (themeConfig === defaultThemeConfig && templateMetadata?.customFonts) {
  finalThemeConfig = createDefaultThemeConfig(templateMetadata?.customFonts);
}

A couple of edge cases to consider:

  1. Reference equality with defaultThemeConfig
    This will only trigger when callers pass the exact exported defaultThemeConfig object. If any caller clones or reconstructs the default config before passing it in, the condition will be false and custom fonts won’t be applied. If that’s acceptable given how Editor is used, this is fine; otherwise you may want a more robust check (e.g., treating an omitted themeConfig as “default” too, or providing an explicit flag upstream).

  2. No override when themeConfig is undefined
    If there are contexts where Editor is invoked without a themeConfig but templateMetadata.customFonts is still set, you might want to treat that as “use the default theme, but with custom fonts”, e.g.:

    let finalThemeConfig = themeConfig;
    
    if (templateMetadata?.customFonts) {
      if (!themeConfig || themeConfig === defaultThemeConfig) {
        finalThemeConfig = createDefaultThemeConfig(templateMetadata.customFonts);
      }
    }

    This preserves custom configs but still enables custom fonts when no config is provided.

Passing finalThemeConfig through to both ThemeEditor and LayoutEditor is otherwise consistent.

Also applies to: 163-167, 179-190

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c09fa1 and 1150b37.

⛔ Files ignored due to path filters (1)
  • packages/visual-editor/src/components/testing/screenshots/StaticMapSection/[mobile] default props with coordinate - with api key.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (5)
  • packages/visual-editor/src/components/DefaultThemeConfig.test.ts (1 hunks)
  • packages/visual-editor/src/components/DefaultThemeConfig.ts (1 hunks)
  • packages/visual-editor/src/components/index.ts (1 hunks)
  • packages/visual-editor/src/editor/Editor.tsx (4 hunks)
  • packages/visual-editor/src/internal/types/templateMetadata.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/visual-editor/src/internal/types/templateMetadata.ts (1)
packages/visual-editor/src/utils/index.ts (1)
  • FontRegistry (48-48)
packages/visual-editor/src/components/DefaultThemeConfig.test.ts (2)
packages/visual-editor/src/components/DefaultThemeConfig.ts (1)
  • createDefaultThemeConfig (11-368)
packages/visual-editor/src/components/index.ts (1)
  • createDefaultThemeConfig (26-26)
🔇 Additional comments (2)
packages/visual-editor/src/components/index.ts (1)

24-27: Re-export of createDefaultThemeConfig looks correct

Adding createDefaultThemeConfig next to defaultThemeConfig cleanly exposes the new API without changing existing exports. LGTM.

packages/visual-editor/src/components/DefaultThemeConfig.ts (1)

27-368: Overall createDefaultThemeConfig structure looks consistent with existing theme schema

Beyond the merge-order issue above, the rest of createDefaultThemeConfig looks well-factored:

  • Font options and weight options are derived once from the combined registry and reused across headings, body, buttons, and links.
  • Defaults for palette, typography, spacing, and other styles are explicit and align with the previous static config shape.
  • defaultThemeConfig being defined as createDefaultThemeConfig() keeps behavior unchanged for consumers that don’t use custom fonts.

Once the merge-order fix is applied, this should be a solid drop-in replacement for the prior static config.

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/visual-editor/src/components/DefaultThemeConfig.ts (1)

27-370: Config factory preserves existing defaults; consider DRYing typography blocks later

Embedding the existing theme structure in createDefaultThemeConfig keeps palette/layout defaults and all typography defaults (H1–H6, body, button, link) unchanged while enabling custom font injection via the shared fontOptions / fontWeightOptions. The duplication across heading/body/button/link sections is substantial but pre‑existing; if this file continues to evolve, you might eventually want a small helper to generate those repeated font config blocks to reduce maintenance overhead, though it’s not required for this PR.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1150b37 and 760aaf3.

📒 Files selected for processing (2)
  • packages/visual-editor/src/components/DefaultThemeConfig.test.ts (1 hunks)
  • packages/visual-editor/src/components/DefaultThemeConfig.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/visual-editor/src/components/DefaultThemeConfig.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/visual-editor/src/components/DefaultThemeConfig.ts (4)
packages/visual-editor/src/components/index.ts (2)
  • createDefaultThemeConfig (26-26)
  • defaultThemeConfig (25-25)
packages/visual-editor/src/utils/index.ts (5)
  • FontRegistry (48-48)
  • ThemeConfig (41-41)
  • defaultFonts (45-45)
  • constructFontSelectOptions (44-44)
  • ThemeOptions (36-36)
packages/visual-editor/src/utils/visualEditorFonts.ts (3)
  • FontRegistry (7-7)
  • defaultFonts (25-25)
  • constructFontSelectOptions (27-37)
packages/visual-editor/src/utils/themeConfigOptions.ts (1)
  • ThemeOptions (367-383)
🔇 Additional comments (1)
packages/visual-editor/src/components/DefaultThemeConfig.ts (1)

11-25: Font merge order and weight options closure look correct

Merging fonts as { ...defaultFonts, ...customFonts } ensures custom entries override defaults on name collisions while keeping all base fonts available, which matches the intended behavior and tests. The fontWeightOptions helper correctly closes over the merged fonts and exposes a zero‑arg function per CSS variable, so consumers using options as a thunk will see weights for both default and custom fonts without further changes.

mkilpatrick
mkilpatrick previously approved these changes Dec 2, 2025
@benlife5 benlife5 requested a review from mkilpatrick December 4, 2025 15:56
@benlife5 benlife5 merged commit f0cede8 into main Dec 4, 2025
15 checks passed
@benlife5 benlife5 deleted the use-custom-fonts branch December 4, 2025 16:37
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2025
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.

3 participants