Skip to content

fix(admin): match sidebar active state when a plugin page path is "/" - #3008

Open
marks-zyz wants to merge 2 commits into
emdash-cms:mainfrom
marks-zyz:fix/sidebar-active-trailing-slash
Open

fix(admin): match sidebar active state when a plugin page path is "/"#3008
marks-zyz wants to merge 2 commits into
emdash-cms:mainfrom
marks-zyz:fix/sidebar-active-trailing-slash

Conversation

@marks-zyz

@marks-zyz marks-zyz commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

A plugin admin page declared with path: "/" never gets the active state in the sidebar. The link works and the page renders; only the highlight is missing, so the sidebar shows no selected item while you are on that page. This affects the shipped @emdash-cms/plugin-forms, whose first page is declared as { path: "/", label: "Forms" }.

Sidebar.tsx builds the target by concatenation (/plugins/${pluginId}${page.path}), so path: "/" yields /plugins/<id>/ with a trailing slash, while the router navigates to /plugins/<id>. isItemActive compared the two exactly, so the item could never match.

This normalizes the trailing slash on both sides before comparing, keeping "/" exact for the admin root. The fix is in the comparison rather than in the item builder, so it covers any nav item whose target ends in a slash, not just plugin pages.

Closes #2988

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — no new strings
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion — not a feature
  • I have included screenshots below if this PR changes the UI

Environment note, so the three unchecked boxes above are not a mystery: I could not run the repo's own typecheck, lint and test locally. A scoped install (pnpm install --filter @emdash-cms/admin...) leaves the other workspace packages unbuilt, so pnpm typecheck in packages/admin fails on @emdash-cms/blocks, @emdash-cms/plugin-types and @emdash-cms/registry-client — pre-existing resolution errors unrelated to this change, and CONTRIBUTING says pnpm build is required first. The admin suite also runs in browser mode, which I did not set up. What I did run is below. CI is the source of truth here.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5 (Claude Code). A human reviewed the diff and the measurements before it was opened.

Screenshots / test output

Both screenshots are from EmDash 0.36.0 running in astro dev, same sidebar, same session. The site has two plugins with admin pages: the shipped forms plugin (path: "/", hits the bug) and a local email provider that works around it with path: "/status".

Before — the forms plugin page is open (/plugins/emdash-forms), and no sidebar item is highlighted:

After — the same sidebar with a page whose path has a segment (/plugins/ses-email/status), where the highlight appears as expected. This is the state the patch gives back to path: "/" pages:

The rendered pixels do not change; what changes is which item receives the active state. The measurement behind the screenshots, reading data-active on the sidebar anchors in the page:

current path /_emdash/admin/plugins/emdash-forms
  /_emdash/admin/plugins/ses-email/status        act=
  /_emdash/admin/plugins/emdash-forms            act=          <- should be active
  /_emdash/admin/plugins/emdash-forms/submissions act=

current path /_emdash/admin/plugins/ses-email/status
  /_emdash/admin/plugins/ses-email/status        act=true
  /_emdash/admin/plugins/emdash-forms            act=
  /_emdash/admin/plugins/emdash-forms/submissions act=

Targeted verification of the new comparison, including the cases the existing behavior must keep:

PASS  isItemActive("/taxonomies/course?locale=de", "/taxonomies/course") -> true   existing: query is ignored
PASS  isItemActive("/plugins/emdash-forms/", "/plugins/emdash-forms") -> true   new: plugin page declared with path "/"
PASS  isItemActive("/plugins/emdash-forms/", "/plugins/emdash-forms/submissions") -> true   new: nested route stays active
PASS  isItemActive("/plugins/emdash-forms/", "/plugins/emdash-forms-extra") -> false   new: sibling sharing a prefix must not match
PASS  isItemActive("/", "/media") -> false   new: admin root stays exact
PASS  isItemActive("/", "/") -> true   new: admin root matches itself
PASS  isItemActive("/media", "/media") -> true   existing: plain route
PASS  isItemActive("/media", "/media/123") -> true   existing: nested under a plain route
PASS  isItemActive("/media", "/mediation") -> false   existing: prefix collision

9/9 passed

Four of these are added to the existing isItemActive block in packages/admin/tests/components/Sidebar.test.tsx.

A plugin admin page declared with path "/" builds the sidebar target as
/plugins/<id>/, but the router navigates to the same URL without the
trailing slash, so isItemActive never matched and the item stayed
unhighlighted. This hits the shipped forms plugin (its "Forms" page).

Normalize the trailing slash on both sides, keeping "/" exact for the
admin root, and cover the case in the Sidebar tests.
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e015c29

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/release-service Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin admin page declared with path "/" never gets the sidebar active state (hits the official forms plugin)

1 participant