Repository navigation
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.71 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a user I want to be able to create a navigation overlay for a specific navigation block in
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the Link exact-match default change.
No open issues 🎉
What changed in this PR
Updates @wordpress/route’s Link to use exact-path matching by default, preventing parent links from also receiving aria-current="page" in breadcrumbs and nested navigation.
Changes:
- Wraps TanStack Router’s
Linkwith an overridable exact-match default. - Adds regression tests, a router-backed navigation story, and documentation.
- Updates dependencies and TypeScript references, and exempts development files from bundled-package private API import restrictions.
| File | Description |
|---|---|
tools/eslint/suppressions.json |
Removes the obsolete router-story suppression. |
tools/eslint/config.mjs |
Exempts development files from private API import restrictions. |
packages/route/tsconfig.json |
Adds the element development-project reference. |
packages/route/tsconfig.build.json |
Adds the element build-project reference. |
packages/route/src/test/link.jsdom.test.tsx |
Tests exact matching and explicit partial matching. |
packages/route/src/link.tsx |
Implements the exact-match default while forwarding refs and props. |
packages/route/src/index.ts |
Exports the wrapped Link. |
packages/route/README.md |
Documents the default matching behavior. |
packages/route/package.json |
Adds element and testing dependencies. |
packages/route/CHANGELOG.md |
Records the breaking default change and override option. |
packages/admin-ui/src/stories/with-router.tsx |
Supports a configurable initial route in stories. |
packages/admin-ui/src/page/stories/index.story.tsx |
Adds a nested router-navigation example. |
package-lock.json |
Records the updated dependencies. |
Review effort: Balanced
ciampo
left a comment
There was a problem hiding this comment.
Alternatively, could / should we handle this in Admin UI? Breadcrumbs already knows the last item is current, and Page navigation gets currentHref. An Admin UI adapter could use useLinkProps for client-side navigation, then apply its own aria-current after spreading the router props onto the anchor. That gives each navigation control over which link it marks as current and preserves the shared Link matching behavior.
Just a thought, I guess it depends on the type of fix we want to make
| ref={ ref } | ||
| // An active link gets `aria-current="page"`, which must not be on | ||
| // links to parent pages. | ||
| activeOptions={ { exact: true, ...activeOptions } } |
There was a problem hiding this comment.
At /settings/privacy?filter=active, the link to /settings/privacy loses aria-current="page" because exact also requires the search parameters to match. Could we keep the shared default and opt into exact pathname matching where the navigation treats query parameters as page state?
There was a problem hiding this comment.
At
/settings/privacy?filter=active, the link to/settings/privacylosesaria-current="page"becauseexactalso requires the search parameters to match. Could we keep the shared default and opt into exact pathname matching where the navigation treats query parameters as page state?
It's good to highlight the query parameter aspect. I had not considered it. Though I don't know that it would change how I feel about the default here. Sure, query parameters can be added for all kinds of reasons, but one of those reasons could well be to distinguish the active page. If we matched only on pathname, it would add the ability to distinguish active pages on query parameters (as well as being additional complexity). Being exact still feels like the better default, all things considered.
There was a problem hiding this comment.
Breadcrumbs also supports a link as its last item. I tried a linked Privacy breadcrumb at /settings/privacy?filter=active and neither link had aria-current="page". Could we set it explicitly on the linked last item and add a test for that case? That would let the shared Link keep exact matching.
|
|
||
| ### Breaking Changes | ||
|
|
||
| - `Link` is active only when the current path matches its `to` path exactly, so it no longer adds `aria-current="page"` on subpages. Pass `activeOptions` to change this. |
I'll look at this again today, but my impression is that the |
e3a02b9 to
94d1be4
Compare
So I think we want both the updated default in
And as mentioned above, we still want the defaults changed in That being said, some of the documentation added here only referenced "pathname" in evaluating exactness, so I updated this in 94d1be4 to also include querystring. |
|
I should say that my feelings about overriding the default are a "strong opinion loosely held". It does appear that it's not quite as accidental as I might have initially thought. They are quite explicit about all this in their documentation around active options, and they show an example of needing
But there's still some problems with this:
|
|
I’m ok with exact matching as the default for
There’s one case here: |
|
For Breadcrumbs, you're right that the last item can be a link, and I guess my next question would be: Do we want that? It's valid (APG Breadcrumb pattern uses it), but our own examples don't use it. We could decide to standardize around the last item always being a static text and not a link. And in fact, my own #86982 goes so far as to codify that fact, making the last item always rendered as a heading. So the question is: Should we support links on the last item of a breadcrumb?
I think our own Breadcrumb usage guidelines suggest the latter: "The current item is not a link and defaults to |
ciampo
left a comment
There was a problem hiding this comment.
Good reflection.
I'd go with a heading for the last item. That's what our routes already render. If #86982 lands first, that covers my concern here. If this ships first, could we keep the linked final item marked as current while we still support it?
| render( <RouterProvider router={ router } /> ); | ||
| } | ||
|
|
||
| describe( 'Link', () => { |
There was a problem hiding this comment.
Nit: Could we add a case with two links to the same path, one with search={ { filter: 'active' } } and one without? At ?filter=active, only the filtered link should have aria-current="page".
There was a problem hiding this comment.
Nit: Could we add a case with two links to the same path, one with
search={ { filter: 'active' } }and one without? At?filter=active, only the filtered link should havearia-current="page".
Good idea 👍 Added in 143400c.
81c9679 to
143400c
Compare
| }, | ||
| "packages/admin-ui/src/stories/with-router.tsx": { | ||
| "no-restricted-imports": { | ||
| "packages/block-directory/src/components/auto-block-uninstaller/index.js": { |
There was a problem hiding this comment.
Could we drop the change to tools/eslint/suppressions.json? It only swaps two entries, and CI puts them back in their original order.
There was a problem hiding this comment.
Thanks, this was the result of a bad rebase where I manually resolved the conflicts. I'll fix it up.
This is the conventional integration with `@wordpress/route`, and is the only place we can see the actual issue with navigation breadcrumb aria-current
… in bundled packages" This reverts commit 94ce5b9.
143400c to
4be0668
Compare
|
I'm starting to second-guess myself on the approach here. I think we want the same end-result as far as But I'm thinking maybe we should avoid the breaking change to The more conservative option is to keep |
This proliferates a little bit with #86982, since the routing concerns are pushed into each route's Which touches on the problem of what each route should be responsible for. #86982 already pushes responsibility of wiring links to the router to each route, and with my revised proposal here we'd also be pushing expectations around how each page controls its links by passing I still think it's the better option for now, and not a blocker. Separately we should look into ways to better share this default behavior. |
|
The changes after 03f0d5c are certainly simpler, but it's made it clearer that the problem is more to do with wiring I think we really have to bite the bullet and find a solution to the React context problem with duplicate packages, which might mean some shared global value that can be future-compatible. If we had a solution there, we could ensure that |
ciampo
left a comment
There was a problem hiding this comment.
The more conservative option is to keep
Linkas it is and update each of our individual affected call-sites to useactiveOptions.exact: trueexplicitly.
I'd keep the Breadcrumbs fix here and leave the shared Link default alone. It's low risk either way. None of our routes hit the bug today, since no parent crumb is a path prefix of its page.
We're basically taking away something that "just worked" (i.e.
@wordpress/admin-uifollows@wordpress/routerouting) without a clear alternative in place.
I think this concern belongs to #86982 more than to this PR. There, a Boot page that doesn't pass components.link renders a plain anchor like <a href="/settings">, which leaves wp-admin because Boot keeps the route in ?p=. The copied adapters also mark the parent crumb as current on nested paths. In the Settings fixture at /settings/general, the Settings link gets aria-current="page".
I think we really have to bite the bullet and find a solution to the React context problem with duplicate packages, which might mean some shared global value that can be future-compatible.
Boot and each route do inline their own Admin UI, but they share one @wordpress/route module. Could the link context live in a script module too? @wordpress/widget-primitives already does that for the dashboard's links. That might save us a new global.
One note on this PR itself. The description still covers the @wordpress/route change. The testing steps also pass without the Breadcrumbs fix, because the story's adapter sets activeOptions itself. Could we point them at a nested breadcrumb instead? None of our routes show the bug, but the ThreeLevels story would with initialPath: '/settings/connectors/example'. Both parent links are current there on trunk, and neither should be with this change.
| Link: ( ( { | ||
| to, | ||
| activeOptions, | ||
| children, | ||
| ...props | ||
| }: ComponentProps< 'a' > & { | ||
| to: string; | ||
| activeOptions?: unknown; | ||
| } ) => ( | ||
| <a href={ to } { ...props }> | ||
| { children } | ||
| </a> |
There was a problem hiding this comment.
Could we render Settings and Privacy with a memory router at /settings/privacy?filter=active and assert that only Privacy is current? The mock drops activeOptions, so this test still passes if we remove the fix from the parent link.
What?
Updates
@wordpress/route'sLinkcomponent implementation to wrap TanStack Router's default implementation and specifyactiveOptions.exactastrue.Why?
By default, TanStack considers a link "active" if its
topartially matches the current page. This is problematic for nested navigations, and especially for breadcrumb navigations, where the breadcrumb chain is often increasing specificity.For example:
In this example, both the Settings link and Privacy link will apply
aria-current="page"when the current URL is/settings/privacy, which is contrary to APG Breadcrumbs pattern guidance "The link to the current page hasaria-currentset to page."Personally I don't know that this should be the default behavior, and have followed-up on an issue describing this behavior which was closed in 2024.
This behavior was also flagged previously in #79746 (comment).
How?
Updates
@wordpress/route'sLinkto wrap the default TanStack RouterLinkcomponent and mergesactiveOptions.exact: trueas the default unless specifically overridden.Testing Instructions
npm run storybook:devlocallyaria-current="page"Use of AI Tools
Researched and implemented in coordination with Claude Code + Opus 5.5.