From 87c509a405be9cbdb7f68eac42e52d775617fc8d Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 13 Nov 2026 22:45:39 +0000 Subject: [PATCH] fix(web): fix memory leak in dropdown ARIA patch (#40349) (#40364) Backport #40349 by @silverwind Dropdowns initialized without an options object shared the default Fomantic templates, so the ARIA patch kept wrapping `templates.menu` on the defaults and retained every dropdown ever created. This grows memory on the Actions run list, which re-renders its dropdowns on each refresh. Each dropdown now gets its own templates copy, which the ARIA patch modifies in place. Fixes: https://github.com/go-gitea/gitea/issues/40347 Assisted-by: Claude Code:claude-opus-5-5 Co-authored-by: silverwind --- web_src/fomantic/build/components/dropdown.js | 2 +- web_src/js/modules/fomantic/dropdown.test.ts | 9 ++++++++- web_src/js/modules/fomantic/dropdown.ts | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/web_src/fomantic/build/components/dropdown.js b/web_src/fomantic/build/components/dropdown.js index 3f78151ece7..473a554882c 100644 --- a/web_src/fomantic/build/components/dropdown.js +++ b/web_src/fomantic/build/components/dropdown.js @@ -49,7 +49,7 @@ $.fn.dropdown = function(parameters) { var settings = ( $.isPlainObject(parameters) ) ? $.extend(true, {}, $.fn.dropdown.settings, parameters) - : $.extend({}, $.fn.dropdown.settings), + : $.extend({}, $.fn.dropdown.settings, {templates: {...$.fn.dropdown.settings.templates}}), // GITEA-PATCH: copy "templates" so per-dropdown changes never reach the defaults className = settings.className, message = settings.message, diff --git a/web_src/js/modules/fomantic/dropdown.test.ts b/web_src/js/modules/fomantic/dropdown.test.ts index 4ea51b3d2ce..8eea7c0eb35 100644 --- a/web_src/js/modules/fomantic/dropdown.test.ts +++ b/web_src/js/modules/fomantic/dropdown.test.ts @@ -1,8 +1,12 @@ import '../../../fomantic/build/fomantic.js'; +import {initGiteaFomantic} from '../fomantic.ts'; import {createElementFromHTML} from '../../utils/dom.ts'; import {hideScopedEmptyDividers} from './dropdown.ts'; -test('dropdown-item-literal-text', () => { +initGiteaFomantic(); + +test('dropdown-item-literal-text-and-default-templates-untouched', () => { + const defaultTemplates = {...$.fn.dropdown.settings.templates}; // a "choice" workflow_dispatch input can offer the string "false" as an option. // jQuery `.data()` would coerce `data-text="false"` to the boolean `false`, which then renders as empty text. const $dropdown = $(`