Skip to content

🎨 Added syntax-highlighted diff view to theme editor review modal#27921

Closed
betschki wants to merge 3 commits into
TryGhost:mainfrom
magicpages:feat/theme-editor-diff-view
Closed

🎨 Added syntax-highlighted diff view to theme editor review modal#27921
betschki wants to merge 3 commits into
TryGhost:mainfrom
magicpages:feat/theme-editor-diff-view

Conversation

@betschki
Copy link
Copy Markdown
Contributor

@betschki betschki commented May 15, 2026

  • the review modal previously showed before/after as two raw <pre> blocks, leaving readers to spot differences by eye
  • swaps the modified-file panel for a CodeMirror merge view (react-codemirror-merge), giving line-level add/remove highlighting and synced scrolling
  • lazy-loads the same language extensions the editor uses, so the diff renders with matching syntax colors per file type
  • extracts getLanguageExtension / getLanguageLabel into theme-editor-languages.ts so the review modal can reuse them without creating a circular dep between sibling modals
27921-diff-view

Got some code for us? Awesome 🎊!

Please take a minute to explain the change you're making:

  • Why are you making it?
  • What does it do?
  • Why is this something Ghost users or developers need?

Please check your PR against these items:

  • I've read and followed the Contributor Guide
  • I've explained my change
  • I've written an automated test to prove my change works

We appreciate your contribution! 🙏

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

Walkthrough

Adds a CodeMirror-based merge diff to the theme review modal. Introduces theme-editor-languages.ts with getLanguageExtension/getLanguageLabel, adds react-codemirror-merge to dependencies and the workspace catalog, refactors theme-code-editor-modal to use the new helpers, replaces the prior preformatted modified-file preview with a keyed CodeMirrorMerge diff (lazy-loading language extensions), and adds a Playwright acceptance test verifying the merge view renders with two editor panes.

Possibly related PRs

  • TryGhost/Ghost#27656: Touches theme code editor language-extension selection and dynamic loading logic; related feature area.

Suggested reviewers

  • EvanHahn
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a syntax-highlighted diff view to the theme editor review modal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description check ✅ Passed The PR description clearly explains the changes: replacing raw pre blocks with a CodeMirror merge view for better diff visualization, lazy-loading language extensions, and extracting helper functions to avoid circular dependencies.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.87%. Comparing base (73a6a7e) to head (1b91515).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #27921   +/-   ##
=======================================
  Coverage   73.86%   73.87%           
=======================================
  Files        1521     1521           
  Lines      128441   128441           
  Branches    15402    15406    +4     
=======================================
+ Hits        94870    94881   +11     
+ Misses      32641    32606   -35     
- Partials      930      954   +24     
Flag Coverage Δ
admin-tests 53.52% <ø> (ø)
e2e-tests 73.87% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@betschki betschki marked this pull request as ready for review May 16, 2026 10:34
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

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

Inline comments:
In
`@apps/admin-x-settings/src/components/settings/site/theme/theme-review-modal.tsx`:
- Around line 93-104: The useEffect that loads the language extension for diffs
(checking diffPath, diffStatus, diffIsEditable) should clear any previous
extension before starting the async load and handle rejections from
getLanguageExtension to avoid unhandled promise rejections and stale state;
inside the effect call setDiffLanguageExtension(null) before invoking
getLanguageExtension(diffPath), chain a .catch handler to
setDiffLanguageExtension(null) (or another safe fallback) and log if desired,
and keep the existing cancelled flag check so the fulfilled or rejected result
does not update state after unmount/cancel.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ac2ed01-8b17-484d-a8b6-200d8c8de648

📥 Commits

Reviewing files that changed from the base of the PR and between 8b512d8 and ad849ad.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • apps/admin-x-settings/package.json
  • apps/admin-x-settings/src/components/settings/site/theme/theme-code-editor-modal.tsx
  • apps/admin-x-settings/src/components/settings/site/theme/theme-editor-languages.ts
  • apps/admin-x-settings/src/components/settings/site/theme/theme-review-modal.tsx
  • apps/admin-x-settings/test/acceptance/site/theme.test.ts
  • pnpm-workspace.yaml

betschki added 2 commits May 16, 2026 15:11
- the review modal previously showed before/after as two raw <pre> blocks, leaving readers to spot differences by eye
- swaps the modified-file panel for a CodeMirror merge view (react-codemirror-merge), giving line-level add/remove highlighting and synced scrolling
- lazy-loads the same language extensions the editor uses, so the diff renders with matching syntax colors per file type
- extracts getLanguageExtension / getLanguageLabel into theme-editor-languages.ts so the review modal can reuse them without creating a circular dep between sibling modals
- ghost/sort-imports-es6-autofix wants 'single' specifier imports before 'multiple' within the same source group; the new ./theme-editor-languages multi-name import landed between a multi-name local import and a single-name @TryGhost import, which broke that ordering
- ran the rule's --fix to move the import to its correct slot
@betschki betschki force-pushed the feat/theme-editor-diff-view branch from ad849ad to 2a6b3fb Compare May 16, 2026 13:38
- the language-extension loader could leak an unhandled promise rejection when getLanguageExtension's dynamic @codemirror/lang-* import failed, and left the previous file's highlighting in place while a new file's extension loaded
- clears the cached extension before the load so switching files never renders against stale highlighting, and adds a catch fallback that drops to plain text on import failure
- caught by CodeRabbit review on PR TryGhost#27921
@ErisDS
Copy link
Copy Markdown
Member

ErisDS commented May 29, 2026

Closing, ref #28250, the theme editor is not intended to be for developer workflows at the moment.

@ErisDS ErisDS closed this May 29, 2026
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