Copilot commented on code in PR #1352:
URL: https://github.com/apache/airflow-site/pull/1352#discussion_r2649067839


##########
landing-pages/src/js/drawer.js:
##########
@@ -27,4 +29,10 @@ const toggleDrawer = () => {
   closeIcon.classList.toggle("visible");
 };
 
-window.document.querySelector("#navbar-toggle-button").addEventListener("click",
 toggleDrawer);
+if (toggleButton) {
+  if (toggleButton.handler) {
+    toggleButton.removeEventListener("click", toggleButton.handler);
+  }
+  toggleButton.handler = toggleDrawer;
+  toggleButton.addEventListener("click", toggleButton.handler);

Review Comment:
   Storing the handler function as a property on the DOM element 
(toggleButton.handler) is non-standard and can be problematic. This approach 
works but:
   1. Pollutes the DOM element with custom properties
   2. Could potentially conflict with future DOM APIs or other code that uses 
the same property name
   3. Is not a common JavaScript pattern
   
   A better approach would be to store the handler in a module-level variable 
or use an AbortController for managing event listeners. For example, you could 
declare a variable at the top of the file to track if the listener has been 
added, or store the handler function separately from the DOM element.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to