From 112309423b5114c327e0f2a69d81c95886f176b2 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Mon, 24 Aug 2026 11:31:57 +0900 Subject: [PATCH] Work around jQuery UI sortable performance regression on long lists --- app/assets/javascripts/application-legacy.js | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/assets/javascripts/application-legacy.js b/app/assets/javascripts/application-legacy.js index d8317b3f1..3f08cb8d0 100644 --- a/app/assets/javascripts/application-legacy.js +++ b/app/assets/javascripts/application-legacy.js @@ -990,6 +990,28 @@ function beforeShowDatePicker(input, inst) { $(input).datepickerFallback("option", "defaultDate", default_date); } +// Workaround for a performance regression in jQuery UI 1.12+ that makes +// sortable initialization quadratic in the number of items, freezing +// Chromium-based browsers on long lists such as custom field enumerations +// (https://github.com/jquery/jquery-ui/issues/2062). +// Collects all handles first and calls _removeClass/_addClass only once +// each, which avoids the quadratic cost while keeping the widget class +// tracking intact. Remove this override once the upstream fix lands. +if ($.ui && $.ui.sortable) { + $.ui.sortable.prototype._setHandleClassName = function() { + var handles = []; + this._removeClass( + this.element.find(".ui-sortable-handle"), + "ui-sortable-handle" + ); + $.each(this.items, function() { + var handle = this.instance.options.handle; + $.merge(handles, (handle ? this.item.find(handle) : this.item).get()); + }); + this._addClass($(handles), "ui-sortable-handle"); + }; +} + (function($){ $.fn.positionedItems = function(sortableOptions, options){ var settings = $.extend({ -- 2.55.0