Skip to content

fix: keep the latest CLI major as the default docs version - #2067

Merged
v-kartykp merged 1 commit into
mainfrom
kartykp/cli-docs-latest-version-fix
Oct 22, 2026
Merged

v-kartykp merged 1 commit into
mainfrom
kartykp/cli-docs-latest-version-fix

Conversation

@v-kartykp

@v-kartykp v-kartykp commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The CLI docs build stops marking any CLI version as the default ("latest") when npm publishes a new patch before moving the latest dist-tag to it. This PR fixes the build logic and makes the version menu handle a missing latest version.

Problem

cli/lib/build.js marked a release as the default only when the newest version in that major exactly matched npm's latest dist-tag:

default: semver.eq(version, pack.latest)

npm 12.2.1 is published under the next-12 tag, while latest still points to 12.2.0. The build picks 12.2.1 as the newest v12 release, which isn't equal to 12.2.0, so no release is marked default and v12 falls through to type: legacy. The last automated CLI docs update wrote that result to main, which has two effects:

  • Version menu: nav.yml has no latest variant, so the "Select CLI Version" menu renders an empty, focusable "Current" item. It is focused first when the menu opens, and screen readers announce a blank menu item.
  • Unversioned redirects: the default version's pages carry the unversioned redirect_from entries (for example /cli/commands/npm-install). With v12 no longer default, those entries were removed from the v12 pages, so a clean build no longer produces those redirects.

The same drop-and-restore of type: latest has happened in earlier automated updates. It recurs whenever a patch is published before latest is moved.

Changes

  • cli/lib/build.js: the default release is now the one whose major matches the latest dist-tag:
    default: semver.major(version) === semver.major(pack.latest)
  • cli/test/index.js: new test for a newer patch (9.0.1) published while latest is still 9.0.0. It fails with the old logic (legacy) and passes with the fix.
  • src/components/variant-select.js: the "Current" group and each item in it are only rendered when that version exists, so a missing latest version can no longer produce an empty menu item.
  • content/nav.yml: v12 is set back to default: true / type: latest. This is the exact nav.yml output of the fixed build against the live registry, so the version menu shows v12 under "Current" as "(Latest)" again.
  • src/components/variant-select.js (focus after choosing a version): choosing a version closed the menu and returned focus to the menu button immediately, while the button still showed the previous version and was still expanded. The button then updated without being announced, so NVDA read the old version (for example "Version 12.2.1 (Latest), menu button, expanded" after choosing 11.21.1). The menu now stays open until the selected version has loaded, then closes and moves focus to the button once, so it is announced with the new version and as collapsed. Escape, Tab, choosing the version you're already on, and modifier-clicks (open in a new tab) behave as before.

The generated v12 pages (content/cli/v12/**) are not changed here. The scheduled "Update CLI" workflow regenerates them with the fixed build on its next v12 update, which restores the unversioned redirect_from entries.

Testing

  • CLI build tests (node --test ./test/index.js ./test/transform.js): 10/10 pass. The new test fails without the build.js change.
  • Running the fixed build against the live registry produces v12 default: true / type: latest and restores the unversioned redirect_from entries on the v12 pages, with no other content changes.
  • npm run build -w cli -- --check-only passes.
  • npm test (jest) and npm run lint pass.
  • content/nav.yml is identical to the nav.yml produced by the fixed build.
  • Focus after choosing a version, recorded at the moment the menu button receives focus:
    • With Enter and with a mouse click, the button receives focus once, already showing the new version ("Version 11.21.1 (Legacy)", "Version 9.9.4 (Legacy)") with aria-expanded="false".
    • Escape closes the menu and returns focus to the collapsed button. Tab closes the menu and moves on.
    • Choosing the version you're already on closes the menu and returns focus to the button. Cmd/Ctrl+click opens that version in a new tab and leaves the current page unchanged.
    • The browser Back button between versions still focuses the button with the right version. Navigating within the same version doesn't move focus to it.
  • Verified locally with gatsby develop: the version menu shows "Version 12.2.1" under "Current" and the other versions under "Legacy", with no empty items. Opening the menu focuses "Version 12.2.1" ("Current", 1 of 1). Selecting it opens /cli/v12/using-npm labelled "(Latest)" and returns focus to the menu button. With v12 set to legacy, the menu shows no "Current" group and no empty item.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix, regression test, menu guards, and restored redirects are consistent with existing behavior and have no identified blocking defects.

No open issues 🎉

What changed in this PR

Keeps CLI documentation on the major version identified by npm’s latest tag, even when a newer patch is published first.

Changes:

  • Matches the default release by major version and adds a regression test.
  • Restores v12’s latest status and unversioned redirects.
  • Prevents missing versions from producing empty menu items.
File Description
src/​components/​variant-select.js Guards missing versions and empty Current groups.
content/​nav.yml Marks v12 as the default/latest version.
content/​cli/​v12/​using-npm/​workspaces.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​scripts.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​scope.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​removal.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​registry.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​package-spec.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​orgs.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​logging.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​index.mdx Restores section redirects.
content/​cli/​v12/​using-npm/​developers.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​dependency-selectors.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​config.mdx Restores unversioned redirects.
content/​cli/​v12/​using-npm/​changelog.mdx Restores unversioned redirects.
content/​cli/​v12/​index.mdx Restores CLI landing-page redirects.
content/​cli/​v12/​configuring-npm/​package-lock-json.mdx Restores unversioned redirects.
content/​cli/​v12/​configuring-npm/​package-json.mdx Restores unversioned redirects.
content/​cli/​v12/​configuring-npm/​npmrc.mdx Restores unversioned redirects.
content/​cli/​v12/​configuring-npm/​npm-extension.mdx Restores unversioned redirects.
content/​cli/​v12/​configuring-npm/​install.mdx Restores unversioned redirects.
content/​cli/​v12/​configuring-npm/​index.mdx Restores section redirects.
content/​cli/​v12/​configuring-npm/​folders.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npx.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-whoami.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-view.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-version.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-update.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-unpublish.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-uninstall.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-undeprecate.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-trust.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-token.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-test.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-team.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-stop.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-start.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-stage.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-set.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-search.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-sbom.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-run.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-root.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-restart.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-repo.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-rebuild.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-query.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-publish.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-prune.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-profile.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-prefix.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-pkg.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-ping.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-patch.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-pack.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-owner.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-outdated.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-org.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-ls.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-logout.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-login.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-ll.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-link.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-install.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-install-test.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-install-scripts.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-install-ci-test.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-init.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-help.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-help-search.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-get.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-fund.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-find-dupes.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-explore.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-explain.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-exec.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-edit.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-doctor.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-docs.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-dist-tag.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-diff.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-deprecate.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-deny-scripts.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-dedupe.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-config.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-completion.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-ci.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-cache.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-bugs.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-audit.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-approve-scripts.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​npm-access.mdx Restores unversioned redirects.
content/​cli/​v12/​commands/​index.mdx Restores section redirects.
cli/​test/​index.js Tests a newer patch preceding the latest tag update.
cli/​lib/​build.js Selects the default release by matching major versions.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused logic and rendering changes address the reported failures, with regression coverage and no unresolved blocking findings.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes address the default-version and empty-menu issues, with regression coverage and no unresolved findings.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes address the documented failure, include regression coverage, and have no identified blocking issues.

No open issues 🎉

Review effort: Balanced

The CLI docs build marked a release as the default only when its newest
version exactly matched the `latest` dist-tag. When a new patch is
published before `latest` is moved (for example 12.2.1 while `latest` is
still 12.2.0), no release was marked latest, so the version menu rendered
an empty "Current" item and the unversioned redirects were dropped from
the default version's pages.

Selecting a version also returned focus to the menu button while it still
showed the previous version and was still expanded, so screen readers
announced the old version and never announced the new one.

- Mark the release whose major matches the `latest` dist-tag as default
- Set v12 back to the default/latest variant in nav.yml
- Only render the "Current" version group and items when they exist
- Keep the version menu open until the selected version has loaded, then
  close it and move focus to the menu button once

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes address the default-version regression and menu behavior, with no unresolved blocking issues identified.

No open issues 🎉

Review effort: Balanced

@v-kartykp
v-kartykp merged commit 7e98ab4 into main Oct 22, 2026
12 checks passed
@v-kartykp
v-kartykp deleted the kartykp/cli-docs-latest-version-fix branch October 22, 2026 00:21

This branch was successfully deployed

1 active deployment
github-pages — ad90ff99 Deployed Oct 21, 2026 by v-kartykp via deploy #3183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants