Active links: a query-less link stays aria-current="page" after navigating to the same path with a query (two current links)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- deno, typescript
- Domain
- accessibility, frontend
Research direction
Start at matchesUrl() in packages/fresh/src/runtime/shared_internal.ts, which is the single place the comparison is decided; the client caller is updateLinks() in packages/fresh/src/runtime/client/partials.ts, and the server pass uses the same helper, so one fix covers both. Read how needleSearch/currentSearch are derived (missing vs empty string) before changing the branch, then make equal paths return Current only when the searches match and decide whether a query-less link falls back to Ancestor or None as the issue suggests. Reproduce with the /list tab example, and check done by confirming only /list?tab=open carries aria-current="page" on both a client navigation and a direct load, with existing active-link tests still passing.
Written by the indexing model from the issue text.
Description
Summary
After a client navigation to a URL that has a query (/list?tab=open), a link to the same path without a query (/list) is still marked aria-current="page", so two links claim to be the current page. The server-side active-link pass has the same result for a document load of /list?tab=open.
Found on Fresh 2.3.3, after #3755. Current main has the same code.
Cause
matchesUrl() (packages/fresh/src/runtime/shared_internal.ts) compares the search only when the link has one:
if (current === href) {
// If the link has query params, only mark as current if they match
if (needleSearch && currentSearch !== undefined && needleSearch !== currentSearch) {
return UrlMatchKind.Ancestor;
}
return UrlMatchKind.Current;
}
A link with no query (needleSearch === "") is therefore Current for every query on that path. updateLinks() (runtime/client/partials.ts) then sets data-current and aria-current="page" on it.
Reproducer
// routes/list.tsx
export default function List(ctx) {
const tab = ctx.url.searchParams.get("tab") ?? "all";
return (
<body f-client-nav>
<nav>
<a href="/list">All</a>
<a href="/list?tab=open">Open</a>
<a href="/list?tab=done">Done</a>
</nav>
<Partial name="list"><p>Showing: {tab}</p></Partial>
</body>
);
}
- Load
/list, then click "Open" (a client navigation). - Inspect the links: both
<a href="/list">and<a href="/list?tab=open">carryaria-current="page"anddata-current="true". - Loading
/list?tab=opendirectly gives the same two current links (server pass).
Expected: only /list?tab=open is current. The query-less /list should not be Current when the current URL has a different, non-empty query.
The same thing happens with <a href="/list" f-partial="/partials/list"> tabs that swap one region. #3755's escape hatch (an explicit aria-current on the link) works, but it puts the burden on every app with query-driven tabs or filters.
Related observation
The same rule marks every same-path link with a different query as Ancestor, i.e. aria-current="true": row links such as /list?item=42, pager links (/list?page=2), a drawer's close link. Screen readers announce each of them as "current". These are siblings of the current URL, not ancestors, so None would fit better for a same-path link whose query differs.
Suggested fix
In matchesUrl(), when the paths are equal, return Current only if the searches are equal (treating missing and empty as equal). Otherwise return None, or Ancestor only when the link has no query, if keeping "section" highlighting for a query-less base link is a goal.
- Dominant language
- TypeScript
- Stars
- 13.8k
- Forks
- 757
- Avg merge
- 3m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from freshframework/fresh
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
freshframework/fresh#3833 ·
-
feat
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
freshframework/fresh#3803 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
freshframework/fresh#3918 · 1 comment · 4 reactions ·
-
Tab title doesn't update to <Head> <title> when navigating to a page with another <title>Possibly taken @1AbdullahButt claimed this 7 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 57/100
freshframework/fresh#3916 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
freshframework/fresh#3911 ·
All issues in freshframework/fresh
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tintinweb/pi-subagents#459 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
danielmiessler/LifeOS#2830 ·
Maintainers usually reply within 6 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area: client enhancement priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
opensro-dev/opensro#3681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day