Skip to content

Conversation

wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Sep 14, 2025

Overview

This PR refactors the useVisibilityEvent hook to use usePreservedCallback for the visibility change handler.

By doing so, the handleVisibilityChange function reference remains stable across component re-renders, preventing useEffect from unnecessarily re-executing and re-attaching event listeners.

This reduces the overhead of continuously adding and removing the visibilitychange event listener, providing a performance boost.

Additionally, even when the callback changes, usePreservedCallback ensures the latest callback is always invoked, maintaining correctness.

Added initial values ​​to the options.immediate documentation.

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@Copilot Copilot AI review requested due to automatic review settings September 14, 2025 06:56
Copy link

@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

This PR optimizes the useVisibilityEvent hook by replacing useCallback with usePreservedCallback to maintain a stable function reference for the visibility change handler, preventing unnecessary re-execution of the effect and re-attachment of event listeners.

  • Replaced useCallback with usePreservedCallback for the visibility change handler
  • Updated documentation to clarify the default value for options.immediate
  • Removed unnecessary useCallback import

Reviewed Changes

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

File Description
src/hooks/useVisibilityEvent/useVisibilityEvent.ts Refactored to use usePreservedCallback and updated imports
src/hooks/useVisibilityEvent/useVisibilityEvent.md Added clarification about the default value for options.immediate
src/hooks/useVisibilityEvent/ko/useVisibilityEvent.md Added clarification about the default value for options.immediate in Korean

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

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5bdb4ff) to head (68255b5).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #276   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         1093      1091    -2     
  Branches       324       324           
=========================================
- Hits          1093      1091    -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants