Skip to content

feat: the admin Settings page keeps its tab in the address (?tab=) - #534

Merged
kikootwo merged 1 commit into
mainfrom
reland/517-settings-tab-url
Nov 2, 2026
Merged

kikootwo merged 1 commit into
mainfrom
reland/517-settings-tab-url

Conversation

@kikootwo

@kikootwo kikootwo commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reloading the admin Settings page always went back to the first tab. The open tab now lives in the page address, ?tab=, like the other admin pages keep their state: a reload keeps the tab, back and forward move between tabs, and a link can open a specific tab (for example /admin/settings?tab=paths).

Changes

  • src/app/admin/settings/hooks/useSettingsTabUrlState.ts (new): reads the tab from ?tab= on every render and only accepts a tab the current backend mode shows (getTabs(backendMode)). Anything else, such as auth in Plex mode or a typo, shows the first tab and the address is left alone, so there is no redirect loop and no flash of another tab. A click pushes a history entry with window.history.pushState, which Next.js syncs into useSearchParams without a server round trip, so switching tabs is as instant as before. The first tab is written as no parameter.
  • src/app/admin/settings/page.tsx: uses the hook instead of local state. Unsaved edits are kept when switching tabs, as before (same page instance, nothing remounts). The page is wrapped in a Suspense boundary for useSearchParams, with the existing spinner as the fallback.
  • tests/helpers/mock-next-url-history.ts (new): a next/navigation mock backed by jsdom's real URL and history, so tests see pushState, back and forward.
  • Docs: the ?tab= values in documentation/settings-pages.md; the new e2e spec in documentation/testing/e2e-harness.md.

Tests

  • tests/app/admin-settings.page.test.tsx, 6 new: the address opens its tab; auth in Plex mode and an unknown tab fall back to the first tab without rewriting the address or adding history; a click writes ?tab=paths (the first tab as no parameter, and clicking the open tab adds no entry); back and forward move between tabs; unsaved edits survive a tab switch. 3 of them fail on main (the other 3 guard behaviour main already has).
  • The two indexer suites now start each test at /admin/settings.
  • E2E e2e/specs/regressions/517-settings-tab-url.spec.ts on the built image: deep link, reload, click (no RSC or document request), back, forward, unknown tab.

Screenshots

Opened at /admin/settings?tab=paths:

Settings opened on the Paths tab from ?tab=paths

After clicking Download Client (the address becomes ?tab=download):

Settings on the Download Client tab

Checks

Risk and rollback

Small and contained to the Settings page. The one behaviour change beyond the address is a history entry per tab click, which is what makes back and forward work. Rollback is a revert of this commit; nothing is stored, so there is nothing to clean up.

Based on #517 by @NichCodes.

🤖 Generated with Claude Code

Reloading Settings always went back to the first tab. The open tab now
lives in `?tab=`: a reload keeps it, back and forward move between tabs,
and a link can open a specific tab. A click pushes a history entry with
the native History API, which Next.js syncs into useSearchParams, so the
switch stays instant and unsaved edits are kept. An unknown tab, or one
the backend mode does not show (`auth` in Plex mode), shows the first
tab and leaves the address alone.

Co-authored-by: NichCodes <90598280+NichCodes@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo marked this pull request as ready for review November 2, 2026 17:19
@kikootwo
kikootwo merged commit b6c5c68 into main Nov 2, 2026
1 check passed
@kikootwo
kikootwo deleted the reland/517-settings-tab-url branch November 2, 2026 17:19
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