fix(details): match book tab keys case-insensitively - #2962
Open
posthog[bot] wants to merge 7 commits into
Open
Conversation
Instructor-resource deep links arrive as lower-case `?instructor%20resources`, but `findSelectedTab` compared the decoded search keys against the capitalized labels with case-sensitive equality. The match failed, so the page fell back to the Book details tab. `replaceSearchTerm` had the same asymmetry: its lookup missed the lower-case key, so it added a second key instead of replacing the old one, leaving a stale `instructor resources` parameter in the URL. It also encoded only the new value, so the result never matched the browser-normalized `window.location.search` and the redundant-replace guard in desktop-view fired a history write on every tab click. Compare keys against labels case-insensitively in both functions, and encode every key so the two functions agree on encoding and the guard can match. Also lower-case the URL check in `useVariant` and `getLinks`, which degraded the dialog copy and links on the same lower-case URLs. Generated-By: PostHog Desktop Task-Id: be65106a-fb19-4f89-b0cd-d588022762c9
Contributor
There was a problem hiding this comment.
Pull request overview
Makes details-page tab keys case-insensitive and normalizes their URL encoding.
Changes:
- Matches and replaces tab keys regardless of case.
- Updates resource variants and donation links for lowercase URLs.
- Adds tab utility tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tab-utils.ts |
Adds case-insensitive tab matching and encoding. |
left-content.tsx |
Normalizes resource variant detection. |
use-give-links.ts |
Normalizes donation-link selection. |
tab-utils.test.ts |
Tests lowercase matching and replacement. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: mwvolo <3905516+mwvolo@users.noreply.github.com>
Co-authored-by: mwvolo <3905516+mwvolo@users.noreply.github.com>
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
/details/books/arrive as the lower-case form, against a tiny fraction in any other form.findSelectedTab(src/app/pages/details/common/tab-utils.ts) reads the search keys withURLSearchParams— which decodes%20but keeps case — then matches them against the capitalized labels insrc/app/lang/en.jswith case-sensitive equality. Real links arrive as?instructor%20resourcesin lower case, so the match fails and the page falls back tolabels[0],Book details.replaceSearchTermhas the same asymmetry: its lookup misses the lower-case key, so it adds a second key instead of replacing the old one. The staleinstructor resourceskey survives and the URL becomes?Student%20resources&instructor resources.window.location.search, so the redundant-replace guard indesktop-view.tsxcan never match and fires a history write on every tab click.findSelectedTab, so the whole details-page tab system is affected.Changes
findSelectedTabreplaceSearchTermuseVariant,getLinkssearch.includes('Instructor')case-sensitive → degraded copy/linksdesktop-view.tsxguard matches and the repeated history writes stop.Scope
left-content.tsxanduse-give-dialog.tsxis already open in fix(donations): cap the give dialog per session and fix two nearby bugs #2961, so the download fix belongs there rather than in a competing PR.Test plan
test/src/pages/details/common/tab-utils.test.tscovering the lower-case deep link, the case-mismatched replace, and the fallback.yarn testandyarn lint(run in CI — the private@openstaxnpm registry is not reachable from the authoring environment).Created with PostHog Desktop from this inbox report.