fix(next): disables active nav item (#11434)

When visiting a collection's list view, the nav item corresponding to
that collection correctly appears in an active state, but is still
rendered as an anchor tag. This makes it possible to reload the current
page by simply clicking the link, which is a problem because this
performs an unnecessary server roundtrip. This is especially apparent
when search params exist in the current URL, as the href on the link
does not.

Unrelated: also cleans up leftover code that was missed in this PR:
#11155
This commit is contained in:
Jacob Fletcher
2025-02-27 15:21:28 -05:00
committed by GitHub
parent f7b1cd9d63
commit c4bc0ae48a
11 changed files with 138 additions and 73 deletions

View File

@@ -11,7 +11,6 @@ import {
ensureCompilationIsDone,
exactText,
initPageConsoleErrorCatch,
openNav,
saveDocAndAssert,
} from '../../../helpers.js'
import { AdminUrlUtil } from '../../../helpers/adminUrlUtil.js'
@@ -46,6 +45,7 @@ const description = 'Description'
let payload: PayloadTestSDK<Config>
import { navigateToDoc } from 'helpers/e2e/navigateToDoc.js'
import { openNav } from 'helpers/e2e/toggleNav.js'
import path from 'path'
import { fileURLToPath } from 'url'

View File

@@ -9,7 +9,6 @@ import {
exactText,
getRoutes,
initPageConsoleErrorCatch,
openNav,
saveDocAndAssert,
saveDocHotkeyAndAssert,
// throttleTest,
@@ -51,6 +50,7 @@ let payload: PayloadTestSDK<Config>
import { navigateToDoc } from 'helpers/e2e/navigateToDoc.js'
import { openDocControls } from 'helpers/e2e/openDocControls.js'
import { openNav } from 'helpers/e2e/toggleNav.js'
import path from 'path'
import { fileURLToPath } from 'url'
@@ -406,6 +406,15 @@ describe('General', () => {
await expect(link).toBeHidden()
})
test('should disable active nav item', async () => {
await page.goto(postsUrl.list)
await openNav(page)
const activeItem = page.locator('.nav .nav__link.active')
await expect(activeItem).toBeVisible()
const tagName = await activeItem.evaluate((el) => el.tagName.toLowerCase())
expect(tagName).toBe('div')
})
test('breadcrumbs — should navigate from list to dashboard', async () => {
await page.goto(postsUrl.list)
await page.locator(`.step-nav a[href="${adminRoutes.routes.admin}"]`).click()