Skip to content

refactor: streamline notification closing logic in useBrowserNotifica…#1670

Open
paustint wants to merge 2 commits intomainfrom
bug/ensure-notification-close-no-ex
Open

refactor: streamline notification closing logic in useBrowserNotifica…#1670
paustint wants to merge 2 commits intomainfrom
bug/ensure-notification-close-no-ex

Conversation

@paustint
Copy link
Copy Markdown
Contributor

@paustint paustint commented Apr 14, 2026

Ensure that failures are handled instead of reporting to rollbar

Copilot AI review requested due to automatic review settings April 14, 2026 15:48
Copy link
Copy Markdown
Contributor

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

Refactors the useBrowserNotifications hook to centralize and reuse browser notification closing behavior across multiple lifecycle/event handlers.

Changes:

  • Introduces a shared closeNotification() callback (with a try/catch guard) to close the active Notification.
  • Updates visibilitychange and unload handlers to call the shared close function instead of duplicating close logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/shared/ui-utils/src/lib/hooks/useBrowserNotifications.ts Outdated
Comment thread libs/shared/ui-utils/src/lib/hooks/useBrowserNotifications.ts
Comment thread libs/shared/ui-utils/src/lib/hooks/useBrowserNotifications.ts
Comment thread libs/shared/ui-utils/src/lib/hooks/useBrowserNotifications.ts
@paustint
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

@copilot apply changes based on the comments in this thread

Applied all the review changes in commit 42b932f:

  • logger.infologger.error for the close error so it's always visible in production
  • notification.current = null after successful close to clear the stale ref
  • Renamed unused event_event in both visibilitychange and handleUnload callbacks

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/shared/ui-utils/src/lib/hooks/useBrowserNotifications.ts
@paustint paustint force-pushed the bug/ensure-notification-close-no-ex branch from 42b932f to 8836832 Compare April 15, 2026 15:17
@paustint paustint requested a review from Copilot April 15, 2026 15:29
Copy link
Copy Markdown
Contributor

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
if (notification.current && typeof notification.current.close === 'function') {
notification.current.close();
notification.current = null;
}
} catch (ex) {
logger.error('[NOTIFICATION][CLOSE][ERROR]', ex);
} finally {
notification.current = null;
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

closeNotification sets notification.current = null both inside the if block and again in finally. The inner assignment is redundant and makes the control flow harder to follow; consider keeping the single assignment in finally (or only after a successful close) to reduce duplication.

Copilot uses AI. Check for mistakes.
Comment on lines +17 to 27
const closeNotification = useCallback(() => {
try {
if (notification.current && typeof notification.current.close === 'function') {
notification.current.close();
notification.current = null;
}
} catch (ex) {
logger.error('[NOTIFICATION][CLOSE][ERROR]', ex);
} finally {
notification.current = null;
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

closeNotification assigns notification.current = null, but the ref is declared as useRef<Notification>(null) (and is written to elsewhere). With strictNullChecks enabled for this lib, the ref should be typed as nullable and mutable (e.g., useRef<Notification | null>(null)) so these assignments are type-safe.

Copilot uses AI. Check for mistakes.
@paustint
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

@copilot apply changes based on the comments in this thread

Applied both changes in commit 95fac3c:

  • Removed the redundant notification.current = null from inside the if block — finally now handles the single cleanup
  • Changed to useRef<Notification | null>(null) for proper strictNullChecks compatibility

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.

3 participants