Repository navigation
✨ Added inline editor for redirects.yaml and routes.yaml - #29200
Conversation
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.
|
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. |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis 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 Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 valueKeyboard listener
useEffecthas no dependency array — re-subscribes on every render.The effect runs after every render, removing and re-adding the
keydownlistener each time. This is functionally correct but wasteful. Consider using a ref to hold the latesthandleSaveand 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
📒 Files selected for processing (4)
apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsxapps/admin-x-settings/src/components/settings/advanced/labs/lab-item.tsxapps/admin-x-settings/src/components/settings/advanced/labs/yaml-file-editor-modal.tsxapps/admin-x-settings/test/acceptance/advanced/labs.test.ts
|
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. |
added `loadError` to the guard so it maches `canSave` exactly
|
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. |
|
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. |
|
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
left a comment
There was a problem hiding this comment.
I made a small tweak to the layout of the buttons but other than that it looks good to me.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx (1)
80-133: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSwap 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
Inlinelayout 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
📒 Files selected for processing (1)
apps/admin-x-settings/src/components/settings/advanced/labs/beta-features.tsx
# Conflicts: # apps/admin-x-settings/test/acceptance/advanced/labs.test.ts
…orlu/Ghost into feat/redirects-routes-yaml-editor
|
@weylandswart thank you. I fixed the conflict. Do we need anything else to merge this? |
|
| 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
left a comment
There was a problem hiding this comment.
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.

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
routerandredirectsconfigurations. 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.
Clicking "Edit" opens the same type of "Code Injection" dialog for the asked config file:
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:
Please check your PR against these items:
We appreciate your contribution! 🙏