-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Sorting: assume standard sort is stable, try out the new toSorted method #52213
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -60 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in 2b8cbad. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5505873098
|
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.
Neat idea to revisit the that sorting stability again 👍 There's definitely opportunities for cleanup.
We added it because it was not stable in React Native and we needed to upgrade, but my understanding is that it's stable now. See #45146 (comment) for more context.
There seem to be some tests failing - I havent' thoroughly looked at them, but could it be that Array.prototype.toSorted()
isn't that well supported?
Also, I'm concerned about Array.prototype.toSorted()
and its support in RN - we'll need to get a confirmation that it's safe to use.
cc @geriux for confirmation that Array.prototype.sort()
is now stable in the Hermes version we're using and Array.prototype.toSorted()
is fully supported.
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.
I'm also a bit concerned about the browser support of Array.prototype.toSorted()
. For example, it's not supported in Chrome 109, but Chrome 109 is still used on over 2% of the devices, which according to the WordPress browser support policy means it's not supported:
Browsers with > 1% usage based on can I use browser usage table
I expected that it gets polyfilled by |
ec1ed49
to
2b8cbad
Compare
Hey there! It looks like it is not 😞 I confirmed this by checking the supported page and also by maually testing the app, the editor freezes until it ends up crashing. |
Ah, that's a bummer. Thanks for double-checking @geriux 🙌 |
2b8cbad
to
a393ca2
Compare
Array sort is specified as stable since 2019: https://stackoverflow.com/questions/3026281/what-is-the-stability-of-the-array-sort-method-in-different-browsers
This PR removes additional stabilizing code from
orderBy
-- all our supported browsers should be compliant by now. I'm not sure myself whether this change is really safe. Let's experiment and discuss.Also I'm trying out the new
.toSorted()
method that doesn't mutate the original array. To use it, I had to upgradecore-js
,browserslist
andcaniuse-lite
to latest versions.