[BUGFIX] Sort version switcher correctly for versions like 0.10#1292
Open
CybotTM wants to merge 1 commit into
Open
[BUGFIX] Sort version switcher correctly for versions like 0.10#1292CybotTM wants to merge 1 commit into
CybotTM wants to merge 1 commit into
Conversation
51031c6 to
91f517b
Compare
0e4ec62 to
27b98a5
Compare
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>
27b98a5 to
8f5077c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
For a package with both
0.1and0.10(e.g. netresearch/nr-vault) the version switcher is wrong in two ways:0.10is sorted last instead of first — it should appear right aftermain.0.10page pre-selects0.1in the dropdown.Cause
versions.jssorted byparseFloat(v), andparseFloat("0.10") === 0.1, so0.10ties with the0.xgroup and lands at the bottom. Pre-selection compared against the rendereddata-current-versionattribute, which is"0.1"on the0.10page because the version string"0.10"is numerically coerced to"0.1"server-side (a separate, deeper bug in the render pipeline).Fix
mainfirst, then highest version), so0.10>0.9> … >0.1.…/0.10/en-us/…) instead of the coercibledata-current-versionattribute. This makes pre-selection correct regardless of that server-side coercion.resources/public/js/theme.min.jsis rebuilt (grunt uglify).Before / after
The version dropdown on the
nr-vault0.10page:Before
After
Tests
New
tests/js/versions.test.js(vitest/jsdom) asserts both the sort order (main, 0.10, 0.9, … 0.1) and that the0.10page pre-selects0.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.10page is served withdata-current-version="0.1"(and title / meta0.1) becauseguides.xml'sversion="0.10"is numerically coerced to the float0.1while parsing (SymfonyXmlUtilsphpize). 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.