From 698ae7aa5b12439dddcde59b040580dafdfa7381 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 1 Mar 2025 10:02:10 +0800 Subject: [PATCH] Fix dynamic content loading init problem (#33748) 1. Rewrite `dirauto.ts` to `observer.ts`. * We have been using MutationObserver for long time, it's proven that it is quite performant. * Now we extend its ability to handle more "init" works. 2. Use `observeAddedElement` to init all non-custom "dropdown". 3. Use `data-global-click` to handle click events from dynamically loaded elements. * By this new approach, the old fragile selector-based (`.comment-reaction-button`) mechanism is removed. 4. By the way, remove unused `.diff-box` selector, it was abused and never really used. A lot of FIXMEs in "repo-diff.ts" are completely fixed, newly loaded contents could work as expected. --- templates/repo/diff/box.tmpl | 6 +- .../repo/issue/view_content/add_reaction.tmpl | 2 +- .../repo/issue/view_content/conversation.tmpl | 2 +- .../repo/issue/view_content/reactions.tmpl | 6 +- templates/shared/search/code/results.tmpl | 2 +- web_src/css/repo.css | 4 - web_src/js/features/common-page.ts | 79 ++++++++-------- web_src/js/features/comp/ReactionSelector.ts | 48 +++++----- web_src/js/features/repo-diff.ts | 15 ++-- web_src/js/features/repo-graph.ts | 5 +- web_src/js/index.ts | 4 +- web_src/js/modules/dirauto.ts | 44 --------- web_src/js/modules/observer.ts | 89 +++++++++++++++++++ 13 files changed, 171 insertions(+), 135 deletions(-) delete mode 100644 web_src/js/modules/dirauto.ts create mode 100644 web_src/js/modules/observer.ts diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 8de54b932a..1a0a5c04a8 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -1,6 +1,6 @@ {{$showFileTree := (and (not .DiffNotAvailable) (gt .Diff.NumFiles 1))}}
-
+
{{if $showFileTree}}