Skip to content

feat: add theme editor to local-editor#1212

Merged
briantstephan merged 13 commits into
2026-custom-components-templatesfrom
local-editor-default-theme
May 21, 2026
Merged

feat: add theme editor to local-editor#1212
briantstephan merged 13 commits into
2026-custom-components-templatesfrom
local-editor-default-theme

Conversation

@briantstephan
Copy link
Copy Markdown
Contributor

@briantstephan briantstephan commented May 12, 2026

This adds the full theme editor within local-editor, allowing developers to customize theme variables and more easily test newly generated built-in templates that use brand styles rather than hardcoded values.

There is now a button to the right of the template selector that toggles between the layout editor and theme editor.

Screenshot 2026-05-19 at 2 45 34 PM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR introduces an editor mode selection system (layout vs. theme) in the local editor, refactors theme style tag management to ensure tag creation before modification, adds themeEntityId computation for template metadata, and improves localStorage resilience. The mode selection is driven by a URL query parameter and controls whether the editor displays layout or theme editing capabilities. Theme application now uses a helper to guarantee the style tag exists before updating both the main document and iframe, addressing potential issues with style injection timing. Template metadata generation derives a stable themeEntityId from themeScopeKey, enabling consistent theme entity identification across template types.

Suggested labels

create-dev-release

Suggested reviewers

  • mkilpatrick
  • jwartofsky-yext

Possibly related PRs

  • yext/visual-editor#1143: Extends the local-editor shell and selection flow by adding a selectedMode dimension ("layout" vs "theme") and propagating it through URL sync and local-dev options with themeScopeKey injection.
  • yext/visual-editor#1024: Also modifies applyTheme.ts theme and CSS-variable application paths, including style tag update behavior.
  • yext/visual-editor#959: Also modifies applyTheme.ts style block production and update logic for theme-related content.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add theme editor to local-editor' directly and clearly describes the main change: integrating a full theme editor into the local-editor component.
Description check ✅ Passed The description is related to the changeset, explaining that the PR adds the full theme editor within local-editor with a toggle button between layout and theme editors.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch local-editor-default-theme

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

@benlife5 benlife5 left a comment

Choose a reason for hiding this comment

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

I'm good with this if this is more correct/more extensible, but it might be possible to just put applyTheme(document, relativePrefixToRoot, defaultThemeConfig), in the local-editor getHeadConfig if we only care about the defaults for now

Copy link
Copy Markdown
Contributor

@jwartofsky-yext jwartofsky-yext left a comment

Choose a reason for hiding this comment

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

nitpicks, but otherwise lgtm

Comment thread packages/visual-editor/src/internal/utils/loadMapboxIntoIframe.tsx Outdated
Comment thread packages/visual-editor/src/internal/utils/loadMapboxIntoIframe.tsx Outdated
Comment thread packages/visual-editor/src/internal/utils/loadMapboxIntoIframe.tsx
Comment thread packages/visual-editor/src/utils/applyTheme.ts Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/generatedFiles.ts Outdated
@briantstephan briantstephan changed the title feat: inject default theme variables into local-editor feat: add theme editor to local-editor May 19, 2026
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)
packages/visual-editor/src/internal/types/templateMetadata.test.ts (1)

39-51: ⚡ Quick win

Consider adding test cases for edge scenarios.

The current test validates the core behavior (same scope key → same ID), but could be more comprehensive. Consider adding tests for:

  • themeScopeKey: undefinedthemeEntityId: undefined
  • Different scope keys produce different IDs
  • Empty string handling
🧪 Proposed additional test cases
  });
+
+ it("returns undefined themeEntityId when themeScopeKey is not provided", () => {
+   const metadata = generateTemplateMetadata(undefined, {
+     templateId: "directory",
+   });
+
+   expect(metadata.themeEntityId).toBeUndefined();
+ });
+
+ it("produces different themeEntityId for different scope keys", () => {
+   const metadata1 = generateTemplateMetadata(undefined, {
+     templateId: "directory",
+     themeScopeKey: "scope-a",
+   });
+   const metadata2 = generateTemplateMetadata(undefined, {
+     templateId: "directory",
+     themeScopeKey: "scope-b",
+   });
+
+   expect(metadata1.themeEntityId).toBeDefined();
+   expect(metadata2.themeEntityId).toBeDefined();
+   expect(metadata1.themeEntityId).not.toBe(metadata2.themeEntityId);
+ });
 });
🤖 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 `@packages/visual-editor/src/internal/types/templateMetadata.test.ts` around
lines 39 - 51, Add unit tests covering edge cases for generateTemplateMetadata:
(1) verify that when themeScopeKey is undefined the returned themeEntityId is
undefined (use generateTemplateMetadata with templateId like "directory" and no
themeScopeKey), (2) verify different themeScopeKey values produce different
themeEntityId values (call generateTemplateMetadata twice with different
themeScopeKey strings and assert IDs differ), and (3) verify handling of empty
string themeScopeKey (pass themeScopeKey: "" and assert the resulting
themeEntityId behavior—either undefined if intended or a stable ID if
implementation treats "" as a valid scope). Ensure each case asserts on the
themeEntityId property.
🤖 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 `@packages/visual-editor/src/internal/types/templateMetadata.test.ts`:
- Around line 39-51: Add unit tests covering edge cases for
generateTemplateMetadata: (1) verify that when themeScopeKey is undefined the
returned themeEntityId is undefined (use generateTemplateMetadata with
templateId like "directory" and no themeScopeKey), (2) verify different
themeScopeKey values produce different themeEntityId values (call
generateTemplateMetadata twice with different themeScopeKey strings and assert
IDs differ), and (3) verify handling of empty string themeScopeKey (pass
themeScopeKey: "" and assert the resulting themeEntityId behavior—either
undefined if intended or a stable ID if implementation treats "" as a valid
scope). Ensure each case asserts on the themeEntityId property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3dbc5711-9c52-477e-8076-abd471ed957b

📥 Commits

Reviewing files that changed from the base of the PR and between 5603239 and 0a91458.

📒 Files selected for processing (10)
  • packages/visual-editor/src/editor/types.ts
  • packages/visual-editor/src/internal/hooks/useMessageReceivers.test.ts
  • packages/visual-editor/src/internal/types/templateMetadata.test.ts
  • packages/visual-editor/src/internal/types/templateMetadata.ts
  • packages/visual-editor/src/local-editor/LocalEditorControls.tsx
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx
  • packages/visual-editor/src/local-editor/selection.ts
  • packages/visual-editor/src/local-editor/types.ts
  • packages/visual-editor/src/utils/applyTheme.test.ts
  • packages/visual-editor/src/vite-plugin/registry/registryTemplateGenerator.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/visual-editor/src/vite-plugin/registry/registryTemplateGenerator.test.ts
  • packages/visual-editor/src/internal/hooks/useMessageReceivers.test.ts
  • packages/visual-editor/src/editor/types.ts
  • packages/visual-editor/src/utils/applyTheme.test.ts

@briantstephan briantstephan marked this pull request as draft May 19, 2026 14:10
@briantstephan
Copy link
Copy Markdown
Contributor Author

I'm good with this if this is more correct/more extensible, but it might be possible to just put applyTheme(document, relativePrefixToRoot, defaultThemeConfig), in the local-editor getHeadConfig if we only care about the defaults for now

Updated so now the whole theme editor is accessible in the local editor.

@briantstephan briantstephan marked this pull request as ready for review May 19, 2026 19:16
Comment thread packages/visual-editor/src/internal/components/ThemeEditor.tsx Outdated
Comment thread packages/visual-editor/src/utils/applyTheme.ts Outdated
Comment thread packages/visual-editor/src/utils/applyTheme.ts
@briantstephan briantstephan requested a review from benlife5 May 20, 2026 21:31
@briantstephan briantstephan merged commit 10ca4e0 into 2026-custom-components-templates May 21, 2026
17 checks passed
@briantstephan briantstephan deleted the local-editor-default-theme branch May 21, 2026 15:57
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.

4 participants