Skip to content

[BUGFIX] Sort version switcher correctly for versions like 0.10#1292

Open
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:fix/version-select-sort
Open

[BUGFIX] Sort version switcher correctly for versions like 0.10#1292
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:fix/version-select-sort

Conversation

@CybotTM

@CybotTM CybotTM commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

For a package with both 0.1 and 0.10 (e.g. netresearch/nr-vault) the version switcher is wrong in two ways:

  • 0.10 is sorted last instead of first — it should appear right after main.
  • Opening the 0.10 page pre-selects 0.1 in the dropdown.

Cause

versions.js sorted by parseFloat(v), and parseFloat("0.10") === 0.1, so 0.10 ties with the 0.x group and lands at the bottom. Pre-selection compared against the rendered data-current-version attribute, which is "0.1" on the 0.10 page because the version string "0.10" is numerically coerced to "0.1" server-side (a separate, deeper bug in the render pipeline).

Fix

  • Sort each dotted version component numerically (main first, then highest version), so 0.10 > 0.9 > … > 0.1.
  • Derive the active version from the page URL (the authoritative source, e.g. …/0.10/en-us/…) instead of the coercible data-current-version attribute. This makes pre-selection correct regardless of that server-side coercion.

resources/public/js/theme.min.js is rebuilt (grunt uglify).

Before / after

The version dropdown on the nr-vault 0.10 page:

Before

before

After

after

Tests

New tests/js/versions.test.js (vitest/jsdom) asserts both the sort order (main, 0.10, 0.9, … 0.1) and that the 0.10 page pre-selects 0.10. Both pass with the fix and fail without it.

Related

The wrong pre-selection has a second, deeper cause that this PR does not rely on: the 0.10 page is served with data-current-version="0.1" (and title / meta 0.1) because guides.xml's version="0.10" is numerically coerced to the float 0.1 while parsing (Symfony XmlUtils phpize). That is tracked in #1293 and fixed upstream in phpDocumentor/guides#1345. This PR makes the switcher correct regardless — it derives the active version from the page URL — so the two fixes are independent.

@CybotTM CybotTM force-pushed the fix/version-select-sort branch 3 times, most recently from 51031c6 to 91f517b Compare June 16, 2026 21:58
@CybotTM CybotTM force-pushed the fix/version-select-sort branch 4 times, most recently from 0e4ec62 to 27b98a5 Compare June 24, 2026 15:31
The version switcher sorted entries with parseFloat(), so parseFloat("0.10")
=== 0.1 and "0.10" sorted together with the 0.x group at the bottom instead
of first. It also pre-selected the entry matching data-current-version, which
is rendered as "0.1" on the 0.10 page (the version "0.10" is coerced to
"0.1" server-side), so the wrong entry was pre-selected.

Sort each dotted version component numerically ("main" first, then the
highest version) and derive the active version from the page URL — the
authoritative source — instead of the coercible data-current-version
attribute. resources/public/js/theme.min.js is rebuilt accordingly.

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@CybotTM CybotTM force-pushed the fix/version-select-sort branch from 27b98a5 to 8f5077c Compare July 1, 2026 12:00
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.

1 participant