Skip to content

feat(profile): Back profile tab state with URL query#1158

Open
jeromehardaway wants to merge 1 commit into
masterfrom
feat/1057-url-backed-profile-tabs
Open

feat(profile): Back profile tab state with URL query#1158
jeromehardaway wants to merge 1 commit into
masterfrom
feat/1057-url-backed-profile-tabs

Conversation

@jeromehardaway

Copy link
Copy Markdown
Contributor

Problem

src/pages/profile/[id].tsx held the active tab in useState, so a page reload always reset the view to "command-center", tabs could not be deep-linked, and browser back/forward did not move between tabs (#1057).

Solution

  • New pure helper resolveProfileTab(queryValue) in src/lib/profile-tabs.ts: validates ?tab= against PROFILE_TABS ids and falls back to command-center for absent, invalid, or array garbage values (first array entry is considered).
  • The page derives activeTab from router.query.tab on every render — the URL is the single source of truth, so reload, deep links, and back/forward all work.
  • Tab clicks call router.push({ query: { ...router.query, tab } }, undefined, { shallow: true }) so getServerSideProps does not re-run.
  • Non-owners deep-linking the owner-only ?tab=settings fall back to command-center instead of rendering an empty pane.

Verification

  • npm run typecheck — 7 pre-existing errors in unrelated __tests__/pages/api/j0di3/* files, identical count on master baseline; no errors in changed files
  • npm run lint — 25 errors / 491 warnings, identical to master baseline; changed files introduce no new diagnostics
  • npm test — 42 files, 388 tests passed (includes new __tests__/lib/profile-tabs.test.ts covering valid/absent/invalid/array query values)
  • npm run build — succeeds; /profile/[id] compiles as SSR route

Closes #1057

Derive the active profile tab from router.query.tab instead of local
useState so reloads keep the current tab and tabs can be deep-linked
(e.g. /profile/<id>?tab=settings). Tab clicks shallow-push the query so
getServerSideProps does not re-run, and back/forward navigation works
because state is derived from the URL on every render.

Invalid or absent ?tab= values fall back to command-center via the new
resolveProfileTab helper; non-owners requesting the owner-only settings
tab fall back the same way.

Closes #1057
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vets-who-code-app Ready Ready Preview, Comment Jun 11, 2026 4:59pm

Request Review

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.

Profile tab state should be URL-backed (refresh loses active tab)

1 participant