Skip to content

feat: add migrations for themeData#1161

Open
jwartofsky-yext wants to merge 11 commits intomainfrom
addThemeMigration
Open

feat: add migrations for themeData#1161
jwartofsky-yext wants to merge 11 commits intomainfrom
addThemeMigration

Conversation

@jwartofsky-yext
Copy link
Copy Markdown
Contributor

@jwartofsky-yext jwartofsky-yext commented Apr 16, 2026

Adds a migration to migrate theme data

Adds versioning to themes

The first migration simply removes __customFontPreloads as these have been replaced with __customFontAssets which are dynamically generated on theme load and change.

Refactors the code for loading themes to match the pattern used for Layouts

migrate is renamed to migrateLayout. migrate still works, but is marked deprecated

Adds a migration to migrate theme data.

Note that for __customFontAssets this is not sufficient as this
will only apply when the editor is opened. A user could upgrade
a site without opening the editor at all.

Adds versioning to themes

The first migration simply removes __customFontPreloads as these
have been replaced with __customFontAssets which are dynamically
generated on theme load and change.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@jwartofsky-yext has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 32 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 32 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f5ee3d0d-8ed4-4330-b4a4-1d6af619c8ad

📥 Commits

Reviewing files that changed from the base of the PR and between 174c54f and 16cf3f1.

⛔ Files ignored due to path filters (8)
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] default props - country - document data.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] default props - region - document data.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] default props - root - document data.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] version 40 with countryDocument and non-default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] version 8 - country - default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] version 8 - directory list - non-default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] version 8 - region - default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/Directory/[mobile] version 8 - root - default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (17)
  • packages/visual-editor/src/editor/Editor.tsx
  • packages/visual-editor/src/internal/components/LayoutEditor.tsx
  • packages/visual-editor/src/internal/components/ThemeEditor.tsx
  • packages/visual-editor/src/internal/hooks/layout/useMessageReceivers.ts
  • packages/visual-editor/src/internal/hooks/theme/useMessageReceivers.ts
  • packages/visual-editor/src/internal/hooks/useMessageReceivers.ts
  • packages/visual-editor/src/internal/puck/components/LayoutHeader.tsx
  • packages/visual-editor/src/internal/themeMigrations/0001_remove_custom_font_preloads.ts
  • packages/visual-editor/src/utils/applyTheme.test.ts
  • packages/visual-editor/src/utils/applyTheme.ts
  • packages/visual-editor/src/utils/index.ts
  • packages/visual-editor/src/utils/migrate.ts
  • packages/visual-editor/src/utils/migrateTheme.test.ts
  • packages/visual-editor/src/utils/migrateTheme.ts
  • packages/visual-editor/src/vite-plugin/templates/directory.tsx
  • packages/visual-editor/src/vite-plugin/templates/locator.tsx
  • packages/visual-editor/src/vite-plugin/templates/main.tsx

Walkthrough

The PR adds a theme migration system and applies it across the visual editor. A new migrateTheme utility, version key, and migration registry are introduced (first migration removes legacy __customFontPreloads). Editor now migrates theme data separately from layout data and passes migrated theme/layout to ThemeEditor and LayoutEditor. ThemeEditor and LayoutEditor apply migrateTheme when initializing theme histories (including dev-mode localStorage flows). migrateTheme is exported and covered by unit tests.

Sequence Diagram(s)

sequenceDiagram
  participant Editor
  participant migrateTheme
  participant migrateLayout (migrationRegistry)
  participant ThemeEditor
  participant LayoutEditor

  Editor->>migrateLayout: migrate(layoutData, migrationRegistry)
  migrateLayout-->>Editor: migratedLayoutData
  Editor->>migrateTheme: migrateTheme(themeData)
  migrateTheme-->>Editor: migratedThemeData
  Editor->>ThemeEditor: themeData = migratedThemeData, layoutData = migratedLayoutData
  Editor->>LayoutEditor: themeData = migratedThemeData, layoutData = migratedLayoutData
Loading
sequenceDiagram
  participant ThemeEditor
  participant LocalStorage
  participant migrateTheme
  participant DevServer

  ThemeEditor->>LocalStorage: read theme history (dev mode)
  LocalStorage-->>ThemeEditor: themeHistory[]
  ThemeEditor->>migrateTheme: migrateTheme(each history.data)
  migrateTheme-->>ThemeEditor: migrated history entries
  ThemeEditor->>DevServer: sendDevThemeSaveStateData(migrated latest)
  ThemeEditor-->>ThemeEditor: updateThemeInEditor(migrated latest)
Loading

Possibly related PRs

Suggested labels

create-dev-release

Suggested reviewers

  • mkilpatrick
  • briantstephan
  • benlife5
  • asanehisa
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: adding migrations for theme data, which is the primary objective of the pull request.
Description check ✅ Passed The PR description accurately describes the changeset, covering theme migrations, versioning, removal of __customFontPreloads, and refactoring to match layout patterns.

✏️ 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 addThemeMigration

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/visual-editor/src/utils/migrateTheme.test.ts (1)

21-31: Add a forward-version regression test.

Please add coverage for a payload where [THEME_VERSION_KEY] is greater than the local registry length, so we explicitly guard against version rollback behavior.

🧪 Suggested test case
+  it("does not downgrade a theme stamped by a newer editor", () => {
+    const migratedTheme = migrateTheme({
+      "--fontFamily-body-fontFamily": "'Inter', sans-serif",
+      [THEME_VERSION_KEY]: 99,
+    });
+
+    expect(migratedTheme).toEqual({
+      "--fontFamily-body-fontFamily": "'Inter', sans-serif",
+      [THEME_VERSION_KEY]: 99,
+    });
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/visual-editor/src/utils/migrateTheme.test.ts` around lines 21 - 31,
Add a regression test for migrateTheme to cover forward-version payloads: create
a test that calls migrateTheme with a theme object containing
[THEME_VERSION_KEY] set to a value greater than the local migration registry
length and assert that migrateTheme returns the theme unchanged (i.e., it should
only stamp current version and must not attempt to rollback or apply older
migrations). Reference the migrateTheme function and THEME_VERSION_KEY constant
when adding this test so it explicitly verifies behavior when incoming version >
registry length.
packages/visual-editor/src/internal/themeMigrations/migrationRegistry.ts (1)

1-1: Consider using import type for clarity, though not required by current configuration.

ThemeMigrationRegistry is a type-only export, and while TypeScript will automatically elide the import at compile time with the current configuration (which does not have verbatimModuleSyntax or preserveValueImports enabled), explicitly marking it as import type clarifies the intent and follows best practice.

Suggested improvement
-import { ThemeMigrationRegistry } from "../../utils/migrateTheme.ts";
+import type { ThemeMigrationRegistry } from "../../utils/migrateTheme.ts";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/visual-editor/src/internal/themeMigrations/migrationRegistry.ts` at
line 1, The import in migrationRegistry.ts currently pulls a type-only symbol as
a value import; change the statement importing ThemeMigrationRegistry from
"../../utils/migrateTheme.ts" to an explicit type-only import (use "import type
{ ThemeMigrationRegistry } from ...") so the intent is clear and the
compiler/tree-shaker knows it's only a type; update the import line that
references ThemeMigrationRegistry accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/visual-editor/src/utils/migrateTheme.ts`:
- Around line 22-42: The current migration sets [THEME_VERSION_KEY] to
migrationRegistry.length which can downgrade a theme saved with a higher
version; update the final assignment so the saved version is never reduced:
compute the incoming numeric version (version), run migrations from
migrationRegistry.slice(version) into migratedThemeValues as you do, and when
returning set [THEME_VERSION_KEY] to Math.max(version, migrationRegistry.length)
(or simply keep the existing higher version) so THEME_VERSION_KEY is never
lowered; use the existing symbols version, migrationRegistry,
migratedThemeValues and THEME_VERSION_KEY to implement this change.

---

Nitpick comments:
In `@packages/visual-editor/src/internal/themeMigrations/migrationRegistry.ts`:
- Line 1: The import in migrationRegistry.ts currently pulls a type-only symbol
as a value import; change the statement importing ThemeMigrationRegistry from
"../../utils/migrateTheme.ts" to an explicit type-only import (use "import type
{ ThemeMigrationRegistry } from ...") so the intent is clear and the
compiler/tree-shaker knows it's only a type; update the import line that
references ThemeMigrationRegistry accordingly.

In `@packages/visual-editor/src/utils/migrateTheme.test.ts`:
- Around line 21-31: Add a regression test for migrateTheme to cover
forward-version payloads: create a test that calls migrateTheme with a theme
object containing [THEME_VERSION_KEY] set to a value greater than the local
migration registry length and assert that migrateTheme returns the theme
unchanged (i.e., it should only stamp current version and must not attempt to
rollback or apply older migrations). Reference the migrateTheme function and
THEME_VERSION_KEY constant when adding this test so it explicitly verifies
behavior when incoming version > registry length.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4f4d7324-3d2a-4686-aa9c-90df5820c6f1

📥 Commits

Reviewing files that changed from the base of the PR and between 122261d and ffa958b.

📒 Files selected for processing (8)
  • packages/visual-editor/src/editor/Editor.tsx
  • packages/visual-editor/src/internal/components/LayoutEditor.tsx
  • packages/visual-editor/src/internal/components/ThemeEditor.tsx
  • packages/visual-editor/src/internal/themeMigrations/0001_remove_custom_font_preloads.ts
  • packages/visual-editor/src/internal/themeMigrations/migrationRegistry.ts
  • packages/visual-editor/src/utils/index.ts
  • packages/visual-editor/src/utils/migrateTheme.test.ts
  • packages/visual-editor/src/utils/migrateTheme.ts

Comment thread packages/visual-editor/src/utils/migrateTheme.ts
@jwartofsky-yext jwartofsky-yext marked this pull request as ready for review April 16, 2026 16:36
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.

1 participant