From 0824610e3975bdd355766d8359e498fb2944bea4 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 18 Apr 2026 20:55:01 +0200 Subject: [PATCH] Remove `SubmitEvent` polyfill (#37276) Remove this obsolete polyfill as per https://github.com/go-gitea/gitea/pull/37270#issuecomment-4273399551. Co-authored-by: Claude (Opus 4.7) --- web_src/js/features/common-fetch-action.ts | 8 ++++---- web_src/js/features/repo-diff.ts | 6 +++--- web_src/js/index.ts | 2 -- web_src/js/utils/dom.ts | 22 ---------------------- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/web_src/js/features/common-fetch-action.ts b/web_src/js/features/common-fetch-action.ts index f3decf53b2a..24f4ad2e02f 100644 --- a/web_src/js/features/common-fetch-action.ts +++ b/web_src/js/features/common-fetch-action.ts @@ -1,6 +1,6 @@ import {GET, request} from '../modules/fetch.ts'; import {hideToastsAll, showErrorToast} from '../modules/toast.ts'; -import {addDelegatedEventListener, createElementFromHTML, submitEventSubmitter} from '../utils/dom.ts'; +import {addDelegatedEventListener, createElementFromHTML} from '../utils/dom.ts'; import {confirmModal, createConfirmModal} from './comp/ConfirmModal.ts'; import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; import {registerGlobalSelectorFunc} from '../modules/observer.ts'; @@ -146,7 +146,7 @@ async function performActionRequest(el: HTMLElement, opt: FetchActionOpts) { } type SubmitFormFetchActionOpts = { - formSubmitter?: HTMLElement; + formSubmitter?: HTMLElement | null; formData?: FormData; }; @@ -396,10 +396,10 @@ export function initGlobalFetchAction() { // * it has "-header" and "-content" variants to set the header and content of the "confirm modal" // * it can refer an existing modal element by "#the-modal-id" - addDelegatedEventListener(document, 'submit', '.form-fetch-action', async (el: HTMLFormElement, e) => { + addDelegatedEventListener(document, 'submit', '.form-fetch-action', async (el, e) => { // "fetch-action" will use the form's data to send the request e.preventDefault(); - await submitFormFetchAction(el, {formSubmitter: submitEventSubmitter(e)}); + await submitFormFetchAction(el, {formSubmitter: e.submitter}); }); addDelegatedEventListener(document, 'click', '.link-action', async (el, e) => { diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts index 08e26cfc6d8..500c86fec6a 100644 --- a/web_src/js/features/repo-diff.ts +++ b/web_src/js/features/repo-diff.ts @@ -5,7 +5,7 @@ import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.ts'; import {initViewedCheckboxListenerFor, initExpandAndCollapseFilesButton} from './pull-view-file.ts'; import {initImageDiff} from './imagediff.ts'; import {showErrorToast} from '../modules/toast.ts'; -import {submitEventSubmitter, queryElemSiblings, hideElem, showElem, animateOnce, addDelegatedEventListener, createElementFromHTML, queryElems} from '../utils/dom.ts'; +import {queryElemSiblings, hideElem, showElem, animateOnce, addDelegatedEventListener, createElementFromHTML, queryElems} from '../utils/dom.ts'; import {POST, GET} from '../modules/fetch.ts'; import {createTippy} from '../modules/tippy.ts'; import {invertFileFolding} from './file-fold.ts'; @@ -41,8 +41,8 @@ function initRepoDiffConversationForm() { const formData = new FormData(form); // if the form is submitted by a button, append the button's name and value to the form data - const submitter = submitEventSubmitter(e); - const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); + const submitter = e.submitter; + const isSubmittedByButton = submitter instanceof HTMLButtonElement || (submitter instanceof HTMLInputElement && submitter.type === 'submit'); if (isSubmittedByButton && submitter.name) { formData.append(submitter.name, submitter.value); } diff --git a/web_src/js/index.ts b/web_src/js/index.ts index ba40bc9b9e4..c65972e3377 100644 --- a/web_src/js/index.ts +++ b/web_src/js/index.ts @@ -45,7 +45,6 @@ import {initCaptcha} from './features/captcha.ts'; import {initRepositoryActionView} from './features/repo-actions.ts'; import {initGlobalTooltips} from './modules/tippy.ts'; import {initGiteaFomantic} from './modules/fomantic.ts'; -import {initSubmitEventPolyfill} from './utils/dom.ts'; import {initRepoIssueList} from './features/repo-issue-list.ts'; import {initCommonIssueListQuickGoto} from './features/common-issue-list.ts'; import {initRepoContributors} from './features/contributors.ts'; @@ -69,7 +68,6 @@ import {initDevtest} from './modules/devtest.ts'; const initStartTime = performance.now(); const initPerformanceTracer = callInitFunctions([ - initSubmitEventPolyfill, initGiteaFomantic, initGlobalComponent, diff --git a/web_src/js/utils/dom.ts b/web_src/js/utils/dom.ts index 6833a196c3b..e0c6f351939 100644 --- a/web_src/js/utils/dom.ts +++ b/web_src/js/utils/dom.ts @@ -257,28 +257,6 @@ export function loadElem(el: LoadableElement, src: string) { }); } -// some browsers like PaleMoon don't have "SubmitEvent" support, so polyfill it by a tricky method: use the last clicked button as submitter -// it can't use other transparent polyfill patches because PaleMoon also doesn't support "addEventListener(capture)" -const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined'; - -export function submitEventSubmitter(e: any) { - e = e.originalEvent ?? e; // if the event is wrapped by jQuery, use "originalEvent", otherwise, use the event itself - return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter; -} - -function submitEventPolyfillListener(e: Event) { - const form = (e.target as HTMLElement).closest('form'); - if (!form) return; - form._submitter = (e.target as HTMLElement).closest('button:not([type]), button[type="submit"], input[type="submit"]'); -} - -export function initSubmitEventPolyfill() { - if (!needSubmitEventPolyfill) return; - console.warn(`This browser doesn't have "SubmitEvent" support, use a tricky method to polyfill`); - document.body.addEventListener('click', submitEventPolyfillListener); - document.body.addEventListener('focus', submitEventPolyfillListener); -} - export function isElemVisible(el: HTMLElement): boolean { // Check if an element is visible, equivalent to jQuery's `:visible` pseudo. // This function DOESN'T account for all possible visibility scenarios, its behavior is covered by the tests of "querySingleVisibleElem"