Skip to content

✨ Added inline editor for redirects.yaml and routes.yaml - #29200

Merged
9larsons merged 14 commits into
TryGhost:mainfrom
muratcorlu:feat/redirects-routes-yaml-editor
Jul 21, 2026
Merged

9larsons merged 14 commits into
TryGhost:mainfrom
muratcorlu:feat/redirects-routes-yaml-editor

Conversation

@muratcorlu

@muratcorlu muratcorlu commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

I'm helping onboarding many people to Ghost from other platforms. During this process setting up theme is one of the biggest frustration that people have. Built-in theme editor reduced the general frustration a lot for small edits. But almost all site migrations needs to edit router and redirects configurations. If you don't have a code editor on your local, editing Yaml files are even harder than any other formats. Since we already have inline code editing in other places, I thought using same approach for router.yaml and redirects.yaml files makes so much sense.

This PR adds an "Edit" button next to Router and Redirects settings under Labs.

image

Clicking "Edit" opens the same type of "Code Injection" dialog for the asked config file:

image image

There is no change on backend at all. Frontend fetches the config file from current download endpoint and saves with the upload endpoint.

I think this will increase the general experience of setting up Ghost sites a lot.

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! 🙏

no ref

Settings → Advanced → Labs only supported downloading and
re-uploading these files, so any edit meant round-tripping through
an external editor and the file picker. Added an "Edit" button next
to each Upload/Download pair that opens a full-size CodeMirror YAML
editor (same UI shape as the Code Injection modal), loads the
current file, and saves back through the existing upload endpoints
on success — keeping the dialog open with the server's validation
message on failure so the user can fix and retry.

No backend changes were needed: the download/upload endpoints
already round-trip plain YAML and apply changes live, same as the
existing file-upload flow.
@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for this team, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

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 change adds an inline YAML editor for redirects and routes in the Labs settings. The modal loads, edits, and saves YAML while handling load and save errors. The beta features UI opens configured editors and forwards test IDs through LabItem. Acceptance tests cover successful saves and invalid YAML handling.

Suggested reviewers: evanhahn

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding inline editors for redirects and routes YAML.
Description check ✅ Passed The description is directly related to the changeset and explains the inline editor workflow and motivation.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
apps/admin-x-settings/src/components/settings/advanced/labs/yaml-file-editor-modal.tsx (1)

126-139: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Keyboard listener useEffect has no dependency array — re-subscribes on every render.

The effect runs after every render, removing and re-adding the keydown listener each time. This is functionally correct but wasteful. Consider using a ref to hold the latest handleSave and a stable effect:

+const handleSaveRef = useRef(handleSave);
+handleSaveRef.current = handleSave;
+
 useEffect(() => {
     const handleKeydown = (event: KeyboardEvent) => {
         if ((event.metaKey || event.ctrlKey) && event.key === 's') {
             event.preventDefault();
-            void handleSave();
+            void handleSaveRef.current();
         }
     };

     window.addEventListener('keydown', handleKeydown);

     return () => {
         window.removeEventListener('keydown', handleKeydown);
     };
-});
+}, []);
🤖 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
`@apps/admin-x-settings/src/components/settings/advanced/labs/yaml-file-editor-modal.tsx`
around lines 126 - 139, The keyboard shortcut effect in
yaml-file-editor-modal.tsx is re-registering the window keydown listener on
every render because the useEffect has no dependency array. Update the effect
around handleKeydown/handleSave so the listener is attached once with a stable
callback, and use a ref or equivalent pattern to access the latest handleSave
without resubscribing on each render.
🤖 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/advanced/labs/yaml-file-editor-modal.tsx`:
- Around line 95-98: The modal close flow can trigger afterClose twice because
closeModal already calls afterClose?.() and the Modal component also receives
the same callback prop. Update the yaml-file-editor-modal.tsx modal wiring so
only one path invokes afterClose: keep the callback in closeModal (or the
equivalent close handler) and remove afterClose from the Modal props, using the
existing closeModal/Modal integration points to locate the fix.
- Around line 100-103: The handleSave guard in yaml-file-editor-modal.tsx is out
of sync with canSave, allowing Cmd+S to save even when the Save button is
disabled. Update handleSave to use the same conditions as canSave by also
blocking when loadError is present, and make sure the keyboard shortcut path and
the save button both rely on the same save eligibility logic in
handleSave/canSave.

---

Nitpick comments:
In
`@apps/admin-x-settings/src/components/settings/advanced/labs/yaml-file-editor-modal.tsx`:
- Around line 126-139: The keyboard shortcut effect in
yaml-file-editor-modal.tsx is re-registering the window keydown listener on
every render because the useEffect has no dependency array. Update the effect
around handleKeydown/handleSave so the listener is attached once with a stable
callback, and use a ref or equivalent pattern to access the latest handleSave
without resubscribing on each render.
🪄 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: 15a4e5b4-09ad-438d-8e9a-172aa62eb75a

📥 Commits

Reviewing files that changed from the base of the PR and between d956a89 and 89dc403.

📒 Files selected for processing (4)
  • apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx
  • apps/admin-x-settings/src/components/settings/advanced/labs/lab-item.tsx
  • apps/admin-x-settings/src/components/settings/advanced/labs/yaml-file-editor-modal.tsx
  • apps/admin-x-settings/test/acceptance/advanced/labs.test.ts

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for this team, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for this team, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for this team, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for this team, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@weylandswart
weylandswart self-requested a review July 15, 2026 17:06

@weylandswart weylandswart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I made a small tweak to the layout of the buttons but other than that it looks good to me.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx (1)

80-133: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Swap the 'Edit' and 'Upload' buttons to match the intended design.

Based on the PR objectives, the design indicates that the "Edit" button should appear before the "Upload" button, establishing a natural left-to-right progression (edit first, upload if needed). The current Inline layout renders them in the reverse order. Swap them to accurately reflect the design intent.

🎨 Proposed layout fix for Redirects and Routes

For Redirects:

                     <Inline gap='sm'>
+                        <Button color='grey' label='Edit' size='sm' onClick={openRedirectsEditor} />
                         <FileUpload
                             id='upload-redirects'
                             onUpload={async (file) => {
                                 try {
                                     setRedirectsUploading(true);
                                     await uploadRedirects(file);
                                     showToast({
                                         title: 'Redirects uploaded',
                                         type: 'success'
                                     });
                                 } catch (e) {
                                     handleError(e);
                                 } finally {
                                     setRedirectsUploading(false);
                                 }
                             }}
                         >
                             <Button color='grey' label={redirectsUploading ? 'Uploading ...' : 'Upload redirects file'} size='sm' tag='div' />
                         </FileUpload>
-                        <Button color='grey' label='Edit' size='sm' onClick={openRedirectsEditor} />
                     </Inline>

Apply the identical swap for the Routes section:

                     <Inline gap='sm'>
+                        <Button color='grey' label='Edit' size='sm' onClick={openRoutesEditor} />
                         <FileUpload
                             id='upload-routes'
                             onUpload={async (file) => {
                                 try {
                                     setRoutesUploading(true);
                                     await uploadRoutes(file);
                                     showToast({
                                         type: 'success',
                                         title: 'Routes uploaded'
                                     });
                                 } catch (e) {
                                     handleError(e);
                                 } finally {
                                     setRoutesUploading(false);
                                 }
                             }}
                         >
                             <Button color='grey' label={routesUploading ? 'Uploading ...' : 'Upload routes file'} size='sm' tag='div' />
                         </FileUpload>
-                        <Button color='grey' label='Edit' size='sm' onClick={openRoutesEditor} />
                     </Inline>
🤖 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
`@apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx`
around lines 80 - 133, In the Redirects and Routes action layouts, update the
Inline children so the Edit button using openRedirectsEditor/openRoutesEditor
appears before the corresponding FileUpload control. Preserve the existing
upload handlers, labels, and styling while applying the same left-to-right order
in both sections.
🤖 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
`@apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx`:
- Around line 80-133: In the Redirects and Routes action layouts, update the
Inline children so the Edit button using openRedirectsEditor/openRoutesEditor
appears before the corresponding FileUpload control. Preserve the existing
upload handlers, labels, and styling while applying the same left-to-right order
in both sections.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1e48e650-8e52-461d-bd24-da5677fa1df7

📥 Commits

Reviewing files that changed from the base of the PR and between 0c09aa5 and ca17376.

📒 Files selected for processing (1)
  • apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx

muratcorlu and others added 3 commits July 17, 2026 11:07
@muratcorlu

Copy link
Copy Markdown
Contributor Author

@weylandswart thank you. I fixed the conflict. Do we need anything else to merge this?

@nx-cloud

nx-cloud Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 18a3811

Command Status Duration Result
nx run @tryghost/admin:test:acceptance ✅ Succeeded 5m 41s View ↗
nx run-many -t test:unit -p @tryghost/admin-x-s... ✅ Succeeded 2m 17s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 15s View ↗
nx run-many -t lint -p @tryghost/admin-x-settin... ✅ Succeeded 52s View ↗
nx run @tryghost/admin:build ✅ Succeeded 17s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded 1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-21 00:40:46 UTC

@9larsons 9larsons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't actually like the ux here - we provide an editor and any save action auto-closes it, whether or not data is written, and the written data is often different than you put in (e.g. 301 or 302 blocks can get cleared, comments are removed).

We're providing this as an editor and it has very strict accepted values.

At any rate, it's still helpful and it's 'advanced' config, so I'll still merge.

@9larsons
9larsons merged commit 7e63c30 into TryGhost:main Jul 21, 2026
42 checks passed
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