Skip to content

Conversation

davidjbradshaw
Copy link
Owner

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds automatic teardown of event listeners in the child page and standardizes console styling for observer attach/detach logs.

  • Introduces a child-scoped listeners helper that tracks teardown callbacks.
  • Switches child code to use the new listener helpers and tweaks READY_STATE_CHANGE handling.
  • Updates observer logs to use styled console output with HIGHLIGHT/FOREGROUND.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/child/listeners.js New listener helpers that auto-register teardown callbacks and log add/remove operations
packages/child/index.js Uses new listener helpers, updates READY_STATE_CHANGE logic, adds setup console event, adjusts setup order and removes some inline logging
packages/child/observers/visibility.js Adds styled logging via HIGHLIGHT/FOREGROUND
packages/child/observers/resize.js Adds styled logging via HIGHLIGHT/FOREGROUND
packages/child/observers/perf.js Adds styled logging via HIGHLIGHT/FOREGROUND
packages/child/observers/overflow.js Adds styled logging for detach via HIGHLIGHT
packages/child/observers/mutation.js Switches to styled logging, but missing required imports for style tokens
packages/child/observers/utils.js Adjusts log message to add styling, but missing required imports for style tokens

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +11 to +18
export const removeEventListener = (el, evt, func) => {
el.removeEventListener(evt, func, false)
logEvent('Remove', evt)
}

export const addEventListener = (el, evt, func, options) => {
el.addEventListener(evt, func, options || false)
tearDown.push(() => removeEventListener(el, evt, func))
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeEventListener always uses false for the third argument, which fails to remove listeners added with capture: true (or a capture option). Store and pass the original options (or at least the capture boolean) to ensure removal matches the add call. For example, compute capture as typeof options === 'boolean' ? options : options?.capture ?? false and pass it to removeEventListener; also store options in the teardown callback.

Suggested change
export const removeEventListener = (el, evt, func) => {
el.removeEventListener(evt, func, false)
logEvent('Remove', evt)
}
export const addEventListener = (el, evt, func, options) => {
el.addEventListener(evt, func, options || false)
tearDown.push(() => removeEventListener(el, evt, func))
export const removeEventListener = (el, evt, func, options) => {
// Compute the capture value as per the DOM spec
const capture = typeof options === 'boolean' ? options : options?.capture ?? false
el.removeEventListener(evt, func, capture)
logEvent('Remove', evt)
}
export const addEventListener = (el, evt, func, options) => {
el.addEventListener(evt, func, options || false)
tearDown.push(() => removeEventListener(el, evt, func, options))

Copilot uses AI. Check for mistakes.

addEventListener(document, READY_STATE_CHANGE, () =>
checkReadyYet(readyCallback),
)
addEventListener(document, READY_STATE_CHANGE, () => {

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace document,·READY\_STATE\_CHANGE, with ⏎········document,⏎········READY\_STATE\_CHANGE,⏎·······

Copilot Autofix

AI about 21 hours ago

To fix the problem, break up the argument list to the addEventListener call on line 275 so each argument appears on a separate line with increased indentation (~8 spaces). This adheres to the ESLint suggestion, which prioritizes consistent formatting for multiline argument calls, improving readability for calls with a callback function as an argument. The change is fully local to the affected line and does not affect functionality—only indentation and line breaks. There are no dependencies, imports, or definitions required; just reformat the arguments.

Suggested changeset 1
packages/child/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/child/index.js b/packages/child/index.js
--- a/packages/child/index.js
+++ b/packages/child/index.js
@@ -272,10 +272,15 @@
   function checkReadyYet(readyCallback) {
     if (document.readyState === 'complete') isolateUserCode(readyCallback)
     else
-      addEventListener(document, READY_STATE_CHANGE, () => {
-        sendSize(READY_STATE_CHANGE, 'Ready state change')
-        checkReadyYet(readyCallback)
-      }, { once: true })
+      addEventListener(
+        document,
+        READY_STATE_CHANGE,
+        () => {
+          sendSize(READY_STATE_CHANGE, 'Ready state change')
+          checkReadyYet(readyCallback)
+        },
+        { once: true }
+      )
   }
 
   function checkAndSetupTags() {
EOF
@@ -272,10 +272,15 @@
function checkReadyYet(readyCallback) {
if (document.readyState === 'complete') isolateUserCode(readyCallback)
else
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
}, { once: true })
addEventListener(
document,
READY_STATE_CHANGE,
() => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
},
{ once: true }
)
}

function checkAndSetupTags() {
Copilot is powered by AI and may make mistakes. Always verify output.
checkReadyYet(readyCallback),
)
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Insert ··

Copilot Autofix

AI about 21 hours ago

The best way to fix this formatting issue is to indent the callback function body on line 276 by two additional spaces. This is inside the callback arrow function passed to addEventListener(document, READY_STATE_CHANGE, ...) and should match the indentation of other block-level statements throughout the file. Specifically, change:

276:         sendSize(READY_STATE_CHANGE, 'Ready state change')

to

276:           sendSize(READY_STATE_CHANGE, 'Ready state change')

(retaining all existing code, just adding two spaces).

No new methods, imports, or definitions are needed; just the whitespace change for formatting compliance.

Suggested changeset 1
packages/child/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/child/index.js b/packages/child/index.js
--- a/packages/child/index.js
+++ b/packages/child/index.js
@@ -273,8 +273,8 @@
     if (document.readyState === 'complete') isolateUserCode(readyCallback)
     else
       addEventListener(document, READY_STATE_CHANGE, () => {
-        sendSize(READY_STATE_CHANGE, 'Ready state change')
-        checkReadyYet(readyCallback)
+          sendSize(READY_STATE_CHANGE, 'Ready state change')
+          checkReadyYet(readyCallback)
       }, { once: true })
   }
 
EOF
@@ -273,8 +273,8 @@
if (document.readyState === 'complete') isolateUserCode(readyCallback)
else
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
}, { once: true })
}

Copilot is powered by AI and may make mistakes. Always verify output.
)
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Insert ··

Copilot Autofix

AI about 21 hours ago

To fix this issue, we should ensure that line 277 is correctly indented to match the project's two-space per indentation level policy, as indicated by the surrounding lines. Each nested code block is expected to increase indentation by two spaces, and within the arrow function starting on line 275, each statement should be consistently indented. Line 277 likely needs two additional spaces at its beginning. The fix is to add two spaces to the start of line 277, ensuring it aligns with line 276 and other lines at the same block level.

No method, import, or definition changes are required; only code indentation within packages/child/index.js.


Suggested changeset 1
packages/child/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/child/index.js b/packages/child/index.js
--- a/packages/child/index.js
+++ b/packages/child/index.js
@@ -274,7 +274,7 @@
     else
       addEventListener(document, READY_STATE_CHANGE, () => {
         sendSize(READY_STATE_CHANGE, 'Ready state change')
-        checkReadyYet(readyCallback)
+          checkReadyYet(readyCallback)
       }, { once: true })
   }
 
EOF
@@ -274,7 +274,7 @@
else
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
checkReadyYet(readyCallback)
}, { once: true })
}

Copilot is powered by AI and may make mistakes. Always verify output.
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
}, { once: true })

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace },·{·once:·true·} with ··},⏎········{·once:·true·},⏎······

Copilot Autofix

AI about 21 hours ago

To fix the problem, move the object literal { once: true } to a new line after the callback function, properly indented to align with the rest of the arguments in the function call. This keeps multi-line calls consistent, improves readability, and satisfies the linting rule. Specifically, replace the single line:

addEventListener(document, READY_STATE_CHANGE, () => {
  sendSize(READY_STATE_CHANGE, 'Ready state change')
  checkReadyYet(readyCallback)
}, { once: true })

with the following formatting:

addEventListener(
  document,
  READY_STATE_CHANGE,
  () => {
    sendSize(READY_STATE_CHANGE, 'Ready state change')
    checkReadyYet(readyCallback)
  },
  { once: true },
)

However, since only code directly shown can be updated, and from the snippet, the affected lines are:

275:       addEventListener(document, READY_STATE_CHANGE, () => {
276:         sendSize(READY_STATE_CHANGE, 'Ready state change')
277:         checkReadyYet(readyCallback)
278:       }, { once: true })

The fix should move { once: true } to a new line and indent accordingly.

Suggested changeset 1
packages/child/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/child/index.js b/packages/child/index.js
--- a/packages/child/index.js
+++ b/packages/child/index.js
@@ -272,10 +272,15 @@
   function checkReadyYet(readyCallback) {
     if (document.readyState === 'complete') isolateUserCode(readyCallback)
     else
-      addEventListener(document, READY_STATE_CHANGE, () => {
-        sendSize(READY_STATE_CHANGE, 'Ready state change')
-        checkReadyYet(readyCallback)
-      }, { once: true })
+      addEventListener(
+        document,
+        READY_STATE_CHANGE,
+        () => {
+          sendSize(READY_STATE_CHANGE, 'Ready state change')
+          checkReadyYet(readyCallback)
+        },
+        { once: true },
+      )
   }
 
   function checkAndSetupTags() {
EOF
@@ -272,10 +272,15 @@
function checkReadyYet(readyCallback) {
if (document.readyState === 'complete') isolateUserCode(readyCallback)
else
addEventListener(document, READY_STATE_CHANGE, () => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
}, { once: true })
addEventListener(
document,
READY_STATE_CHANGE,
() => {
sendSize(READY_STATE_CHANGE, 'Ready state change')
checkReadyYet(readyCallback)
},
{ once: true },
)
}

function checkAndSetupTags() {
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant