Skip to content

fix: properly remove scroll listener in tracing beam#278

Open
Aaron-zon wants to merge 1 commit intounovue:mainfrom
Aaron-zon:feature/tracingBeam
Open

fix: properly remove scroll listener in tracing beam#278
Aaron-zon wants to merge 1 commit intounovue:mainfrom
Aaron-zon:feature/tracingBeam

Conversation

@Aaron-zon
Copy link
Copy Markdown

@Aaron-zon Aaron-zon commented Apr 17, 2026

In onMounted, the scroll event is bound to window, so in onUnmounted it should also be removed from window.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed scroll event listener cleanup to prevent potential memory leaks and ensure proper resource management during component unmounting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

A one-line bug fix in TracingBeam.vue corrects the onUnmounted cleanup logic to properly remove the scroll event listener from the window object, aligning with where the listener was registered in onMounted.

Changes

Cohort / File(s) Summary
Event Listener Cleanup
app/components/inspira/ui/tracing-beam/TracingBeam.vue
Fixed scroll event listener removal in onUnmounted hook to correctly target window instead of tracingBeamRef.value, ensuring proper cleanup of the listener registered on the global window object during mount.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A scroll listener wandered so far,
Forgot where it came from, didn't know where to scar.
Now cleanup's correct, the window's at peace—
One tiny fix brings the beam sweet release! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: properly remove scroll listener in tracing beam' directly and clearly summarizes the main change: fixing the scroll listener removal logic in the TracingBeam component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/components/inspira/ui/tracing-beam/TracingBeam.vue (1)

60-67: Optional: also disconnect the ResizeObserver on unmount.

While addressing listener cleanup, consider also disconnecting the ResizeObserver created in onMounted to avoid a lingering observer on the detached content node. Hoist it out of the closure so onUnmounted can reach it.

♻️ Proposed refactor
+let resizeObserver: ResizeObserver | undefined;
+
 onMounted(() => {
   window.addEventListener("scroll", updateScrollYProgress);
   window.addEventListener("resize", updateScrollYProgress);
   updateScrollYProgress();

-  const resizeObserver = new ResizeObserver(() => {
+  resizeObserver = new ResizeObserver(() => {
     updateSVGHeight();
   });

   resizeObserver.observe(tracingBeamContentRef.value!);

   updateSVGHeight();
 });

 onUnmounted(() => {
   window.removeEventListener("scroll", updateScrollYProgress);
   window.removeEventListener("resize", updateScrollYProgress);
+  resizeObserver?.disconnect();
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/components/inspira/ui/tracing-beam/TracingBeam.vue` around lines 60 - 67,
The ResizeObserver created in the onMounted closure (named resizeObserver) is
not disconnected on component unmount; hoist the ResizeObserver variable
(resizeObserver) so it’s defined in the component scope (beside
tracingBeamContentRef and updateSVGHeight) and create it inside onMounted, then
add an onUnmounted handler that calls resizeObserver.disconnect() to stop
observing tracingBeamContentRef.value and avoid a lingering observer; ensure you
still call resizeObserver.observe(tracingBeamContentRef.value!) after creation
and that updateSVGHeight() usage remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/components/inspira/ui/tracing-beam/TracingBeam.vue`:
- Around line 60-67: The ResizeObserver created in the onMounted closure (named
resizeObserver) is not disconnected on component unmount; hoist the
ResizeObserver variable (resizeObserver) so it’s defined in the component scope
(beside tracingBeamContentRef and updateSVGHeight) and create it inside
onMounted, then add an onUnmounted handler that calls
resizeObserver.disconnect() to stop observing tracingBeamContentRef.value and
avoid a lingering observer; ensure you still call
resizeObserver.observe(tracingBeamContentRef.value!) after creation and that
updateSVGHeight() usage remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04b01c1e-e1d2-46c2-90a3-6669ed067b25

📥 Commits

Reviewing files that changed from the base of the PR and between 738ac57 and 7e1da11.

📒 Files selected for processing (1)
  • app/components/inspira/ui/tracing-beam/TracingBeam.vue

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