Return 0 from sortFunc when values are equal - #7169
Open
Ujjwal-Gowda wants to merge 1 commit into
Open
Conversation
sortFunc never returned 0. For equal values `a > b` is false, so it fell through to -1 in ASC and 1 in DESC, reporting both a < b and b < a for identical input. Array.prototype.sort is only stable when the comparator returns 0 for equal elements, so equal entries were reordered rather than keeping their original order. With 12 entries where 11 share a name, the equal ones came out fully reversed. The result also varied with list length because V8 changes sorting strategy for larger arrays. This sorts the piped and application lists in the four application forms and in the encrypt secret drawer, where duplicate names are normal. sortDateFunc delegates to sortFunc and had the same problem for equal timestamps. Add web/src/utils/common.test.ts, which did not exist before, covering ordering, equality, and the stability regression. Signed-off-by: Ujjwal Gowda <crystalninja0123@gmail.com>
Ujjwal-Gowda
requested review from
Warashi,
ffjlabo,
hongky-1994 and
khanhtc1202
August 12, 2026 09:49
Contributor
|
👋 Hi @Ujjwal-Gowda, welcome to PipeCD and thanks for opening your first pull request! We’re really happy to have you here Before your PR gets merged, please check a few important things below. Helpful resources
DCO Sign-offAll commits must include a In case you forget to sign-off your commit(s), follow these steps: For the last commit: git commit --amend --signoff
git push --force-with-leaseFor multiple commits: git rebase --signoff origin/master
git push --force-with-leaseRun checks locallyBefore pushing updates, please run: make checkThis runs the same checks as CI and helps catch issues early. 💬 Need help?If anything is unclear, feel free to ask in this PR or join us on the CNCF Slack in the #pipecd channel. Thanks for contributing to PipeCD! ❤️ |
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.
What this PR does:
sortFuncnever returned 0. For equal valuesa > bis false, so it fell through to-1in ASC and1in DESC, reporting botha < bandb < afor identical input.Array.prototype.sortis only stable when the comparator returns 0 for equal elements, so equal entries were reordered instead of keeping their original order. With 12 entries where 11 share a name, the equal ones came out fully reversed. The result also varied with list length, because V8 switches sorting strategy for larger arrays.This adds the
a === bshort-circuit, and addsweb/src/utils/common.test.ts(the file did not exist before) covering ordering, equality, and the stability regression.Why we need it:
This function sorts the piped and application lists in the four application forms and in the encrypt secret drawer, where duplicate names are normal.
sortDateFuncdelegates tosortFuncand had the same problem for equal timestamps.The visible effect is that the dropdown order for same-named entries is unstable: it changes depending on how many items are in the list, so a user picking "the second
apipiped" is not picking a consistent thing.Which issue(s) this PR fixes:
None — found while reading the application form code. Happy to open an issue first if that is preferred.
Does this PR introduce a user-facing change?: