feat(profile): Back profile tab state with URL query#1158
Open
jeromehardaway wants to merge 1 commit into
Open
feat(profile): Back profile tab state with URL query#1158jeromehardaway wants to merge 1 commit into
jeromehardaway wants to merge 1 commit into
Conversation
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
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
src/pages/profile/[id].tsxheld the active tab inuseState, 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
resolveProfileTab(queryValue)insrc/lib/profile-tabs.ts: validates?tab=againstPROFILE_TABSids and falls back tocommand-centerfor absent, invalid, or array garbage values (first array entry is considered).activeTabfromrouter.query.tabon every render — the URL is the single source of truth, so reload, deep links, and back/forward all work.router.push({ query: { ...router.query, tab } }, undefined, { shallow: true })sogetServerSidePropsdoes not re-run.?tab=settingsfall back tocommand-centerinstead 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 filesnpm run lint— 25 errors / 491 warnings, identical to master baseline; changed files introduce no new diagnosticsnpm test— 42 files, 388 tests passed (includes new__tests__/lib/profile-tabs.test.tscovering valid/absent/invalid/array query values)npm run build— succeeds;/profile/[id]compiles as SSR routeCloses #1057