Skip to content
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

List.sortBy produces different order between Chromium/Chrome and Firefox #958

Open
wknapik opened this issue May 13, 2018 · 4 comments
Open

Comments

@wknapik
Copy link

wknapik commented May 13, 2018

Edit: @evancz moved this gist directly into the issue.

2 6 3 4 5 1 7 10 9 11 8  -- Chromium/Chrome 66.0.3359.139 and 66.0.3359.170
2 6 1 3 4 5 7 9 10 11 8  -- Firefox 59.0.2 and 60.0

Tested on Linux.

import Html exposing (div, text)
import List
import Tuple

main =
   Html.beginnerProgram { model = [], view = view, update = (\_ -> \x -> x) }

view _ =
   div [] <| List.map (div [] << List.singleton << text << Tuple.first) (List.sortBy Tuple.second tuples)

tuples =
   [ ( "1", "foo" )
   , ( "2", "bar" )
   , ( "3", "foo" )
   , ( "4", "foo" )
   , ( "5", "foo" )
   , ( "6", "baz" )
   , ( "7", "foo" )
   , ( "8", "quux" )
   , ( "9", "foo" )
   , ( "10", "foo" )
   , ( "11", "foo" )
   ]

Thanks to @showell for helping out with this on slack.

@wknapik

This comment has been minimized.

@eriktim
Copy link

eriktim commented May 19, 2019

I am running into the same issue with Node 10 vs 11 (running elm-test on Travis).
For Chrome it seems to be fixed since v70: https://mobile.twitter.com/mathias/status/1036626116654637057?s=19. The latest Chrome indeed shows the correct result for me (like Firefox).

@eriktim
Copy link

eriktim commented May 19, 2019

To add some background: Elm's List.sortBy uses Array.prototype.sort under the hood. That sorting function is not guaranteed to be stable, i.e. the original order is not guaranteed for equally sorted values.

@robinheghan
Copy link
Contributor

robinheghan commented May 20, 2019

As of EC2020, Array.prototype.sort must be stable. See here: https://tc39.github.io/ecma262/#sec-array.prototype.sort

So this will come to all evergreen JS environments in time.

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

No branches or pull requests

3 participants