New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): stable route sorting #4331
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Codecov Report
@@ Coverage Diff @@
## dev #4331 +/- ##
==========================================
+ Coverage 91.05% 91.09% +0.03%
==========================================
Files 56 56
Lines 1845 1852 +7
Branches 466 467 +1
==========================================
+ Hits 1680 1687 +7
Misses 154 154
Partials 11 11
Continue to review full report at Codecov.
|
Azure fails (again, intermittently) on the components test. The route sorting should be stable now between v10 and v11. Maybe we can add v11 testing to CI before merging this to make sure it does? |
I will trigger azure rebuild. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Types of changes
Description
This PR fixes route sorting in Node v11 (fix #4188).
The problem was caused because the route sorting in Nuxt was inherently unstable due to default ordering to be dictated by the order in which elements where compared. This caused issues in v11 because quicksort compares
arr[0]
witharr[1]
but timsort doesarr[0]
witharr[arr.length - 1]
.E.g. if you look at the
dynamic-routes
test then with quicksort it comparedparent
totest
but in timsort it comparedtest
toparent
. As the default behaviour of route sorting was to return1
, this meant that if there was no 'special' casea
was always sorted afterb
regardless of its actual value (hence the inherently unstable). This PR changes this behaviour to alphabetically sort a and b (withlocaleCompare
) if there is no 'special' case.I have also moved route sorting outside the forEach loop, there is no need to sort the routes array on every intermediate step and it probably saves a little bit of time to only sort it once.
Checklist: