From 252047ed2e09e3f1f1ab394cd62995cf4cabe506 Mon Sep 17 00:00:00 2001 From: charles <30816317+charles7668@users.noreply.github.com> Date: Thu, 29 Feb 2024 04:23:49 +0800 Subject: [PATCH 01/73] Fix counter display number incorrectly displayed on the page (#29448) issue : #28239 The counter number script uses the 'checkbox' attribute to determine whether an item is selected or not. However, the input event only increments the counter value, and when more items are displayed, it does not update all previously loaded items. As a result, the display becomes incorrect because it triggers the update counter script, but checkboxes that are selected without the 'checked' attribute are not counted --- web_src/js/features/pull-view-file.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_src/js/features/pull-view-file.js b/web_src/js/features/pull-view-file.js index 90881ee989..2472e5a0bd 100644 --- a/web_src/js/features/pull-view-file.js +++ b/web_src/js/features/pull-view-file.js @@ -43,9 +43,11 @@ export function initViewedCheckboxListenerFor() { // Mark the file as viewed visually - will especially change the background if (this.checked) { form.classList.add(viewedStyleClass); + checkbox.setAttribute('checked', ''); prReview.numberOfViewedFiles++; } else { form.classList.remove(viewedStyleClass); + checkbox.removeAttribute('checked'); prReview.numberOfViewedFiles--; } From 850fc2516e67049ec195c72d861896b275bd09d1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 28 Feb 2024 21:26:12 +0100 Subject: [PATCH 02/73] Apply compact padding to small buttons with svg icons (#29471) The buttons on the repo release tab were larger in height than on other tabs because one of them contained the RSS icon which stretched the button height by 3px. Workaround this problem by applying the "compact" padding to any such button. They are within 0.4px in height now to non-icon buttons. Before: Screenshot 2024-02-28 at 15 30 23 After: Screenshot 2024-02-28 at 15 38 43 For comparison, button on issue tab: Screenshot 2024-02-28 at 15 31 46 --- templates/repo/release_tag_header.tmpl | 2 +- web_src/css/modules/button.css | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/templates/repo/release_tag_header.tmpl b/templates/repo/release_tag_header.tmpl index f474fb89ea..31c151da08 100644 --- a/templates/repo/release_tag_header.tmpl +++ b/templates/repo/release_tag_header.tmpl @@ -13,7 +13,7 @@ {{if .EnableFeed}} - {{svg "octicon-rss" 18}} {{ctx.Locale.Tr "rss_feed"}} + {{svg "octicon-rss" 16}} {{ctx.Locale.Tr "rss_feed"}} {{end}} {{if and (not .PageIsTagList) .CanCreateRelease}} diff --git a/web_src/css/modules/button.css b/web_src/css/modules/button.css index 36cb499aeb..26f8fcf94c 100644 --- a/web_src/css/modules/button.css +++ b/web_src/css/modules/button.css @@ -85,6 +85,13 @@ It needs some tricks to tweak the left/right borders with active state */ box-shadow: none; } +/* apply the vertical padding of .compact to non-compact buttons when they contain a svg as they + would otherwise appear too large. Seen on "RSS Feed" button on repo releases tab. */ +.ui.small.button:not(.compact):has(.svg) { + padding-top: 0.58928571em; + padding-bottom: 0.58928571em; +} + .ui.labeled.button.disabled > .button, .ui.basic.buttons .button, .ui.basic.button, From 6d9b7253a2de00b5dfc27550cf7e015e819d6fd2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 28 Feb 2024 23:20:53 +0100 Subject: [PATCH 03/73] Fix/Improve `processWindowErrorEvent` (#29407) - `e.error` can be undefined in some cases which would raise an error inside this error handler, fixed that. - The displayed message mentions looking into the console, but in my case of error from `ResizeObserver` there was nothing there, so add this logging. I think this logging was once there but got lost during refactoring. --- web_src/js/bootstrap.js | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index e46c91e5e6..c0047b0ac2 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -1,5 +1,6 @@ // DO NOT IMPORT window.config HERE! -// to make sure the error handler always works, we should never import `window.config`, because some user's custom template breaks it. +// to make sure the error handler always works, we should never import `window.config`, because +// some user's custom template breaks it. // This sets up the URL prefix used in webpack's chunk loading. // This file must be imported before any lazy-loading is being attempted. @@ -26,29 +27,42 @@ export function showGlobalErrorMessage(msg) { } /** - * @param {ErrorEvent} e + * @param {ErrorEvent|PromiseRejectionEvent} event - Event + * @param {string} event.message - Only present on ErrorEvent + * @param {string} event.error - Only present on ErrorEvent + * @param {string} event.type - Only present on ErrorEvent + * @param {string} event.filename - Only present on ErrorEvent + * @param {number} event.lineno - Only present on ErrorEvent + * @param {number} event.colno - Only present on ErrorEvent + * @param {string} event.reason - Only present on PromiseRejectionEvent + * @param {number} event.promise - Only present on PromiseRejectionEvent */ -function processWindowErrorEvent(e) { - const err = e.error ?? e.reason; +function processWindowErrorEvent({error, reason, message, type, filename, lineno, colno}) { + const err = error ?? reason; const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin)); + const {runModeIsProd} = window.config ?? {}; - // error is likely from browser extension or inline script. Do not show these in production builds. - if (!err.stack?.includes(assetBaseUrl) && window.config?.runModeIsProd) return; - - let message; - if (e.type === 'unhandledrejection') { - message = `JavaScript promise rejection: ${err.message}.`; - } else { - message = `JavaScript error: ${e.message} (${e.filename} @ ${e.lineno}:${e.colno}).`; + // `error` and `reason` are not guaranteed to be errors. If the value is falsy, it is likly a + // non-critical event from the browser. We log them but don't show them to users. Examples: + // - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors + // - https://github.com/mozilla-mobile/firefox-ios/issues/10817 + // - https://github.com/go-gitea/gitea/issues/20240 + if (!err) { + if (message) console.error(new Error(message)); + if (runModeIsProd) return; } - if (!e.error && e.lineno === 0 && e.colno === 0 && e.filename === '' && window.navigator.userAgent.includes('FxiOS/')) { - // At the moment, Firefox (iOS) (10x) has an engine bug. See https://github.com/go-gitea/gitea/issues/20240 - // If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0. - return; // ignore such nonsense error event + // If the error stack trace does not include the base URL of our script assets, it likely came + // from a browser extension or inline script. Do not show such errors in production. + if (err instanceof Error && !err.stack?.includes(assetBaseUrl) && runModeIsProd) { + return; } - showGlobalErrorMessage(`${message} Open browser console to see more details.`); + let msg = err?.message ?? message; + if (lineno) msg += ` (${filename} @ ${lineno}:${colno})`; + const dot = msg.endsWith('.') ? '' : '.'; + const renderedType = type === 'unhandledrejection' ? 'promise rejection' : type; + showGlobalErrorMessage(`JavaScript ${renderedType}: ${msg}${dot} Open browser console to see more details.`); } function initGlobalErrorHandler() { @@ -59,13 +73,14 @@ function initGlobalErrorHandler() { if (!window.config) { showGlobalErrorMessage(`Gitea JavaScript code couldn't run correctly, please check your custom templates`); } - // we added an event handler for window error at the very beginning of diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index 82622366e7..fd5960c31e 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -57,7 +57,7 @@