Skip to content

Moved settings onto the admin router - #29780

Merged
9larsons merged 2 commits into
mainfrom
slars/settings-native-router
Aug 5, 2026
Merged

9larsons merged 2 commits into
mainfrom
slars/settings-native-router

Conversation

@9larsons

@9larsons 9larsons commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Settings was the last consumer of the deprecated admin-x-framework RoutingProvider — a second hash-string router layered onto the URL react-router already owns, showing modals through NiceModal against a 37-path string table, with exit implemented as raw window.location.hash writes. This PR makes settings routing native. Follows #29762 (navigation seam) and #29763 (modal-chrome close seam), which shrank this diff to the swap itself.

What changed

  • Route table: apps/admin/src/settings/routes.tsx is a settingsRouteChildren fragment mounted under the shell's settings route node (same pattern as analyticsRouteChildren). Every legacy modal path is a data route with route-level lazy — each dialog is its own chunk, loaded when its route matches (replaces the old 1s-preload + loading backdrop; the router defers navigation while a chunk loads). locksite and theme/edit/* guards are <Navigate replace> routes; offers/success/:offerId is promoted to a real route; recommendations/edit redirects to the section (see below).
  • Shell: app.tsx renders the settings providers + chrome + Outlet; RoutingProvider, SettingsRouter, the modal registry, and the duplicate NiceModal provider are gone.
  • Routed dialogs are the same screen components with the NiceModal wrapper stripped: params via useParams/useSearchParams, closing navigates back to the owning section through the SettingsModal/PreviewModalContent onClose seam. Flat sibling routes share one component identity, so switching staff tabs or history filters updates params in place without remounting (the legacy reshow behavior, preserved). Imperative modals stay on NiceModal (ConfirmationModal, LimitModal, editor prompts, code/webhook/yaml dialogs) — their removal is follow-up burn-down.
  • Recommendations: the add-wizard's confirm step is internal state of the routed component (URL stays recommendations/add, as before); the edit dialog opens from the list with the loaded record and no route change (as before) — now as a controlled dialog instead of an imperative NiceModal show.
  • Seam: useSettingsNavigation normalizes every legacy link shape to absolute /settings/... over useNavigate; same-path re-navigation re-scrolls the section without pushing a history entry (the legacy provider's contract, now pinned by a spec); {isExternal} goes through externalNavigate; {replace} maps to router replace.
  • useQueryParams reads useSearchParams instead of listening for hashchange — router pushes never fire that event (caught by the staff-invitations spec during integration).
  • Framework: routing-provider.tsx, routing.ts, and the ./routing export are deleted; ExternalLink/InternalLink moved to framework-provider.

Accepted behavior deltas

  • Back button now closes an open dialog (previously modals survived popstate; dirty edits in that path get no confirmation — a follow-up may wire useBlocker for dirty dialogs).
  • locksite redirect replaces instead of pushing (no more back-button trap).
  • Two design/theme limit-denial paths now navigate to /settings/theme instead of closing the modal while leaving the URL stranded.
  • One legacy bug fixed in passing: the failed-theme-upload retry closed the whole theme modal instead of the error dialog; it now closes the error dialog (sibling pattern from advanced-theme-settings).

Verification

  • Acceptance: 56 files / 429 tests pass, including 3 new history-semantics specs (back closes a dialog; back after exit returns to settings; same-section re-click pushes no history entry)
  • Unit: admin 128 files / 1369; shade 34 files / 292 (incl. new SettingsModal onClose branch tests)
  • tsc -b, full lint, dependency-cruiser boundaries clean
  • Build green; every routed dialog is its own lazy chunk

Manual check matrix (pre-merge)

  • Deep links: staff/<slug>/email-notifications (from a staff email), theme/edit/%2Fedition, newsletters/?verifyEmail=<token>, design/edit?ref=setup, theme/install?source=github&ref=TryGhost/Taste, staff?tab=invited
  • Ember entries: /settings/migration from the migrate flow; ⌘K staff result
  • Back/forward through: open dialog → close via X → back → forward
  • Editor/author/contributor role views (permissions suite covers; spot-check contributor profile deep link)
  • Escape layering: dropdown open inside dialog → Escape closes dropdown only; again closes dialog; again exits settings

- settings was the last consumer of the deprecated admin-x-framework RoutingProvider: a second hash-string router layered onto the URL react-router already owns, showing modals through NiceModal against a 37-path table
- the settings route table now lives in the shell's data router as a settingsRouteChildren fragment with route-level lazy per dialog; the shell element renders the settings providers and chrome, dialogs mount through its Outlet
- routed dialogs are the same screen components with the NiceModal wrapper stripped: params come from the router, closing navigates back to the owning section through the SettingsModal onClose seam; imperative confirmations (ConfirmationModal, LimitModal, editor prompts) stay on NiceModal for now
- useSettingsNavigation now normalizes every legacy link shape to absolute /settings paths over useNavigate; same-path re-navigation re-scrolls without pushing a history entry, matching the old provider's contract
- useQueryParams reads useSearchParams instead of listening for hashchange events, which router pushes never fire
- deleted the framework RoutingProvider, its ./routing export, and the settings modal registry; ExternalLink/InternalLink moved to framework-provider
- accepted behavior deltas: the browser back button now closes an open dialog (previously it survived popstate), the locksite redirect replaces instead of pushing, and two design/theme limit denials now navigate to the theme section instead of stranding the URL
- new coverage: three history-semantics acceptance specs and SettingsModal onClose branch tests
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR replaces the legacy settings routing provider with nested framework routes. Settings navigation now uses router hooks, URL search parameters, typed internal and external links, and route-based modal rendering. Settings modals no longer rely on NiceModal wrappers or routing props for lifecycle control. Modal closure uses onClose callbacks and route updates. Recommendation flows manage form and confirmation states locally. Framework routing exports and obsolete routing files are removed. Acceptance and unit tests cover navigation history, query preservation, external links, and modal closure.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: moving Settings from the deprecated routing provider to the admin router.
Description check ✅ Passed The description directly explains the routing migration, affected components, behavior changes, and verification results.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch slars/settings-native-router

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.

@nx-cloud

nx-cloud Bot commented Aug 5, 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 86b623d

Command Status Duration Result
nx run-many -t test:unit -p @tryghost/admin-x-f... ✅ Succeeded 3m 24s View ↗
nx run @tryghost/admin:test:acceptance ✅ Succeeded 6m 11s View ↗
nx run @tryghost/admin:build ✅ Succeeded 2m 5s View ↗
nx run @tryghost/activitypub:test:acceptance ✅ Succeeded 48s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 23s View ↗
nx run ghost-admin:test ✅ Succeeded 2m 59s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded <1s View ↗
nx run-many -t lint -p @tryghost/admin-x-framew... ✅ Succeeded 2m 9s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-08-05 15:39:37 UTC

@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.59%. Comparing base (c241f6f) to head (86b623d).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #29780   +/-   ##
=======================================
  Coverage   75.59%   75.59%           
=======================================
  Files        1613     1613           
  Lines      142639   142639           
  Branches    17644    17644           
=======================================
  Hits       107823   107823           
  Misses      33738    33738           
  Partials     1078     1078           
Flag Coverage Δ
admin-tests 55.99% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

ref #29780
Preserved legacy navigation data and made the new history coverage deterministic.
@9larsons
9larsons marked this pull request as ready for review August 5, 2026 15:45
@9larsons
9larsons enabled auto-merge (squash) August 5, 2026 15:50
@9larsons
9larsons merged commit f33f455 into main Aug 5, 2026
48 of 49 checks passed
@9larsons
9larsons deleted the slars/settings-native-router branch August 5, 2026 15:51

@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/shade/test/unit/components/patterns/settings-modal.test.tsx (1)

75-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the shared render helper for the NiceModal wrapper.

This test requires NiceModal.Provider. Use the shared test render helper instead of mounting the provider with the direct Testing Library render import.

As per coding guidelines, use the shared render helper when a wrapper is needed.

🤖 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/shade/test/unit/components/patterns/settings-modal.test.tsx` around
lines 75 - 92, Update the NiceModal test around the BridgeModal case to use the
shared test render helper with NiceModal.Provider as its wrapper, replacing the
direct Testing Library render call while preserving the existing modal-close
assertions.

Source: Coding guidelines

🤖 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/src/settings/app/components/settings/membership/tiers/tier-detail-modal.tsx`:
- Around line 414-427: Move the tier lookup from the conditional block to before
the useEffect in TierDetailModal, so the effect evaluates the current tiers on
every render. Update the effect dependencies to include tiers, and continue
calling fetchNextPage while tierId is set, tier is missing, and isEnd is false.

In `@apps/admin/src/settings/app/hooks/use-query-params.ts`:
- Around line 1-7: Update DesignAndThemeModal to use the router search-parameter
API for reading and clearing the ref query parameter instead of parsing
window.location.href or window.location.hash. Replace the existing theme-install
query handling while preserving the current ref-driven behavior and ensuring
router URLs with ?ref=... are cleared after use.

---

Nitpick comments:
In `@apps/shade/test/unit/components/patterns/settings-modal.test.tsx`:
- Around line 75-92: Update the NiceModal test around the BridgeModal case to
use the shared test render helper with NiceModal.Provider as its wrapper,
replacing the direct Testing Library render call while preserving the existing
modal-close assertions.
🪄 Autofix

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 Plus

Run ID: 3b3520a9-706a-4f31-9892-2e6e5b70407b

📥 Commits

Reviewing files that changed from the base of the PR and between a71a649 and 86b623d.

📒 Files selected for processing (54)
  • apps/admin-x-framework/package.json
  • apps/admin-x-framework/src/api/actions.ts
  • apps/admin-x-framework/src/providers/framework-provider.tsx
  • apps/admin-x-framework/src/providers/routing-provider.tsx
  • apps/admin-x-framework/src/routing.ts
  • apps/admin/src/routes.tsx
  • apps/admin/src/settings/advanced/advanced.acceptance.test.tsx
  • apps/admin/src/settings/app/app.tsx
  • apps/admin/src/settings/app/components/exit-settings-button.tsx
  • apps/admin/src/settings/app/components/providers/routing/modals.tsx
  • apps/admin/src/settings/app/components/providers/settings-router.tsx
  • apps/admin/src/settings/app/components/settings/advanced/history-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/add-integration-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/content-api-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/custom-integration-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/first-promoter-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/pintura-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/slack-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/transistor-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/unsplash-modal.tsx
  • apps/admin/src/settings/app/components/settings/advanced/integrations/zapier-modal.tsx
  • apps/admin/src/settings/app/components/settings/email/newsletters/add-newsletter-modal.tsx
  • apps/admin/src/settings/app/components/settings/email/newsletters/newsletter-detail-modal.tsx
  • apps/admin/src/settings/app/components/settings/general/about.tsx
  • apps/admin/src/settings/app/components/settings/general/invite-user-modal.tsx
  • apps/admin/src/settings/app/components/settings/general/user-detail-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/embed-signup/embed-signup-form-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/explore/testimonials-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/add-offer-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/edit-offer-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/edit-retention-offer-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/offer-success.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/offers-container-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/offers/offers-index.tsx
  • apps/admin/src/settings/app/components/settings/growth/recommendations/add-recommendation-modal-confirm.tsx
  • apps/admin/src/settings/app/components/settings/growth/recommendations/add-recommendation-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/recommendations/edit-recommendation-modal.tsx
  • apps/admin/src/settings/app/components/settings/growth/recommendations/recommendation-list.tsx
  • apps/admin/src/settings/app/components/settings/membership/portal/portal-modal.tsx
  • apps/admin/src/settings/app/components/settings/membership/stripe/stripe-connect-modal.tsx
  • apps/admin/src/settings/app/components/settings/membership/tiers/tier-detail-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/announcement-bar-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/design-and-theme-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/design-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/navigation-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/theme-modal.tsx
  • apps/admin/src/settings/app/components/settings/site/theme/theme-code-editor-modal.tsx
  • apps/admin/src/settings/app/hooks/use-query-params.ts
  • apps/admin/src/settings/app/hooks/use-settings-navigation.ts
  • apps/admin/src/settings/app/main-content.tsx
  • apps/admin/src/settings/growth/recommendations.acceptance.test.tsx
  • apps/admin/src/settings/navigation-history.acceptance.test.tsx
  • apps/admin/src/settings/routes.tsx
  • apps/shade/test/unit/components/patterns/settings-modal.test.tsx
💤 Files with no reviewable changes (5)
  • apps/admin-x-framework/src/routing.ts
  • apps/admin/src/settings/app/components/providers/settings-router.tsx
  • apps/admin-x-framework/src/providers/routing-provider.tsx
  • apps/admin/src/settings/app/components/providers/routing/modals.tsx
  • apps/admin-x-framework/package.json

Comment on lines +414 to +427
const TierDetailModal: React.FC = () => {
const {tierId} = useParams();
const {data: {tiers, isEnd} = {}, fetchNextPage} = useBrowseTiers();

let tier: Tier | undefined;

useEffect(() => {
if (params?.id && !tier && !isEnd) {
if (tierId && !tier && !isEnd) {
fetchNextPage();
}
}, [fetchNextPage, isEnd, params?.id, tier]);
}, [fetchNextPage, isEnd, tierId, tier]);

if (params?.id) {
tier = tiers?.find(({id}) => id === params?.id);
if (tierId) {
tier = tiers?.find(({id}) => id === tierId);

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Continue pagination until the route tier is found.

Line 420 evaluates tier before Lines 426-427 assign it. If a loaded page does not contain tierId, the dependency value remains undefined. Later page data can then leave the effect unchanged, so the component stops fetching and returns null for a tier on a later page.

Derive tier before the effect. Re-run the effect when tiers changes.

Proposed fix
 const TierDetailModal: React.FC = () => {
     const {tierId} = useParams();
     const {data: {tiers, isEnd} = {}, fetchNextPage} = useBrowseTiers();
-
-    let tier: Tier | undefined;
+    const tier = tierId ? tiers?.find(({id}) => id === tierId) : undefined;
 
     useEffect(() => {
         if (tierId && !tier && !isEnd) {
-            fetchNextPage();
+            void fetchNextPage();
         }
-    }, [fetchNextPage, isEnd, tierId, tier]);
-
-    if (tierId) {
-        tier = tiers?.find(({id}) => id === tierId);
+    }, [fetchNextPage, isEnd, tier, tierId, tiers]);
 
+    if (tierId) {
         if (!tier) {
             return null;
         }
🤖 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/src/settings/app/components/settings/membership/tiers/tier-detail-modal.tsx`
around lines 414 - 427, Move the tier lookup from the conditional block to
before the useEffect in TierDetailModal, so the effect evaluates the current
tiers on every render. Update the effect dependencies to include tiers, and
continue calling fetchNextPage while tierId is set, tier is missing, and isEnd
is false.

Comment on lines +1 to +7
import {useSearchParams} from '@tryghost/admin-x-framework';

const useQueryParams = () => {
const [params, setParams] = useState(new URLSearchParams());

useEffect(() => {
const updateParams = () => {
const hash = window.location.hash;
const queryString = hash.split('?')[1];

if (queryString) {
setParams(new URLSearchParams(queryString));
} else {
setParams(new URLSearchParams());
}
};

// Initialize
updateParams();

// Listen for hash changes
window.addEventListener('hashchange', updateParams);

// Cleanup
return () => {
window.removeEventListener('hashchange', updateParams);
};
}, []);
const [searchParams] = useSearchParams();

const getParam = (key: string) => {
return params.get(key);
return searchParams.get(key);

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Migrate the remaining theme-install query handling.

This hook now reads location.search. DesignAndThemeModal still gets ref from window.location.href.split('#') and clears parameters with window.location.hash.split('?'). Router URLs with ?ref=... will return no ref and will not clear the query parameter.

Update that modal to read and clear router search parameters. The affected code is in apps/admin/src/settings/app/components/settings/site/design-and-theme-modal.tsx.

🤖 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/src/settings/app/hooks/use-query-params.ts` around lines 1 - 7,
Update DesignAndThemeModal to use the router search-parameter API for reading
and clearing the ref query parameter instead of parsing window.location.href or
window.location.hash. Replace the existing theme-install query handling while
preserving the current ref-driven behavior and ensuring router URLs with
?ref=... are cleared after use.

9larsons added a commit that referenced this pull request Aug 10, 2026
no ref

First slice of the settings NiceModal burn-down (follows the router swap
#29780 and un-portal #29789).

`ConfirmationModal` and `LimitModal` were NiceModal-shown from **54 call
sites across 27 files** — the bulk of settings' remaining NiceModal
usage. They now go through a settings-local `ConfirmationProvider`:
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