Commit 31a9062
User
perf: fix memory leak by delegating tab events to parent containers
Refactored the event handling mechanism for both normal and pinned tabs to use event delegation, significantly reducing memory usage and solving listener accumulation issues.
Changes:
- **Event Delegation**: Removed all individual event listeners and the `EventSink` pattern from [menulist-tab.ts](cci:7://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/menulist-tab.ts:0:0-0:0). Events (click, auxclick, contextmenu, drag & drop) are now handled exclusively by parent containers ([menulist-container.ts](cci:7://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/menulist-container.ts:0:0-0:0) and [panel-windows.ts](cci:7://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/panel-windows.ts:0:0-0:0)).
- **Unified Handlers**: Implemented centralized event handlers in parent components that utilize `ev.composedPath()` and `element.closest()` to identify targets within the Shadow DOM.
- **Attributes**: Added `data-action` (e.g., "close", "pin") and `data-tab-id` attributes to tab elements and buttons to facilitate target identification without direct listener attachment.
- **Drag & Drop**: Removed individual [dragstart](cci:1://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/panel-windows.ts:305:4-323:6)/[dragover](cci:1://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/panel-windows.ts:325:4-339:6)/[drop](cci:1://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/components/panel-windows.ts:341:4-365:6) listeners from [PopupRenderer.ts](cci:7://file:///c:/Users/Predator/Desktop/TabArray_Ops/TabArray_Ops/src/pages/popup-v2/legacy/PopupRenderer.ts:0:0-0:0). Drag operations are now managed at the container level.
- **Cleanup**: Eliminated "event badges" from `menulist-tab` elements in the inspector, ensuring that thousands of tabs no longer create thousands of event listeners.1 parent c1115e3 commit 31a9062
5 files changed
Lines changed: 311 additions & 109 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
146 | 303 | | |
147 | 304 | | |
148 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 36 | | |
41 | 37 | | |
42 | 38 | | |
| |||
49 | 45 | | |
50 | 46 | | |
51 | 47 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 48 | | |
74 | 49 | | |
75 | 50 | | |
| |||
93 | 68 | | |
94 | 69 | | |
95 | 70 | | |
| 71 | + | |
96 | 72 | | |
97 | 73 | | |
98 | 74 | | |
99 | 75 | | |
| 76 | + | |
100 | 77 | | |
101 | 78 | | |
102 | 79 | | |
| |||
109 | 86 | | |
110 | 87 | | |
111 | 88 | | |
| 89 | + | |
112 | 90 | | |
113 | 91 | | |
114 | 92 | | |
115 | 93 | | |
| 94 | + | |
116 | 95 | | |
117 | 96 | | |
118 | 97 | | |
119 | 98 | | |
120 | 99 | | |
| 100 | + | |
| 101 | + | |
121 | 102 | | |
122 | 103 | | |
123 | 104 | | |
| |||
147 | 128 | | |
148 | 129 | | |
149 | 130 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | 131 | | |
158 | 132 | | |
159 | 133 | | |
| |||
0 commit comments