Skip to content

fix(notifications): return Notification-like stub so Teams can manage lifecycle#2329

Open
IsmaelMartinez wants to merge 5 commits intomainfrom
worktree-curried-conjuring-llama
Open

fix(notifications): return Notification-like stub so Teams can manage lifecycle#2329
IsmaelMartinez wants to merge 5 commits intomainfrom
worktree-curried-conjuring-llama

Conversation

@IsmaelMartinez
Copy link
Owner

@IsmaelMartinez IsmaelMartinez commented Mar 12, 2026

Summary

  • Teams calls addEventListener, close(), and dispatchEvent() on the object returned by new Notification(). Our bare { onclick, onclose, onerror } stubs lacked these methods, breaking Teams' internal notification state machine after the first notification.
  • Extracts a shared createNotificationStub() helper that returns a proper Notification-like object and applies it to all code paths (electron, custom, web fallback, disabled notifications).
  • Root cause was identified in feat: Add custom notification support for chat and activity events #2112 but only fixed for the custom notification method. This applies the same fix to all methods.

Fixes #2248

Test plan

  • Verify npm run lint passes
  • Verify npm run test:e2e passes
  • Test with notificationMethod: "electron" — subsequent chat messages should show message content, not just unread count
  • Test with notificationMethod: "web" — same verification
  • Test with notificationMethod: "custom" — same verification

🤖 Generated with Claude Code

… lifecycle

Teams calls addEventListener, close(), and dispatchEvent() on the object
returned by new Notification(). Our bare stubs lacked these methods,
breaking Teams' internal state machine after the first notification and
causing subsequent messages to only show title-based unread counts.

Fixes #2248

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

✅ Changelog entry generated and committed to this PR:

Fix: Ensure all notification methods return a Notification-like stub for Teams. - by @IsmaelMartinez (#2329)

The file .changelog/pr-2329.txt will be included when you merge this PR.

You can edit it directly in this PR if needed.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where Microsoft Teams' notification handling would fail after the initial notification due to an incomplete stub object lacking essential methods like addEventListener and close. By introducing a robust createNotificationStub() helper, the change ensures that all notification pathways consistently return a Notification-like object, thereby maintaining Teams' internal state machine and enabling proper lifecycle management for subsequent notifications.

Highlights

  • Notification Stub Enhancement: Introduced a shared createNotificationStub() helper function that returns a Notification-like object, including addEventListener, close, and dispatchEvent methods, to ensure proper lifecycle management.
  • Teams Compatibility Fix: Addressed an issue where Microsoft Teams' internal notification state machine would break after the first notification due to previously bare stub objects lacking essential methods.
  • Comprehensive Application: Applied the enhanced notification stub across all notification code paths, including Electron, custom, web fallback, and disabled notification scenarios, ensuring consistent and robust behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/browser/preload.js
    • Added a new createNotificationStub() function to generate Notification-like objects with addEventListener, close, and dispatchEvent methods.
    • Updated createWebNotification to return createNotificationStub() if a native notification cannot be created.
    • Modified createElectronNotification to consistently return createNotificationStub().
    • Adjusted the createCustomNotification helper to return createNotificationStub() instead of a bare object.
    • Ensured the CustomNotification constructor returns createNotificationStub() when notifications are disabled.
    • Simplified the CustomNotification constructor's web method handling to directly return the result of createWebNotification.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of Teams' notification lifecycle management by introducing a shared createNotificationStub helper. This ensures that a consistent, more complete Notification-like object is returned across all notification paths, which should fix the bug where subsequent notifications were failing. The refactoring is clean and the logic is sound. I have one suggestion to make the new stub function even more robust.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

📦 PR Snap Build Artifacts

Snap builds successful! Download artifacts:

🐧 Linux Snap Packages

x86_64 (107.29 MB)

arm64 (104.20 MB)

armv7l (98.43 MB)


📝 Note: Other package formats (.deb, .rpm, .AppImage, .dmg, .exe) are built in the main workflow

View workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

📦 PR Build Artifacts

Build successful! Download artifacts:

🐧 Linux

x86_64 (434.10 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

arm64 (425.30 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

armv7l (403.39 MB) - Contains: .deb, .rpm, .tar.gz, .AppImage

🍎 macOS

x86_64 (124.85 MB) - Contains: .dmg

🪟 Windows

x86_64 (105.43 MB) - Contains: .exe installer


📝 Note: Snap packages (.snap) are built in a separate workflow

View workflow run

🕐 Last updated: 2026-03-13 11:15 UTC

IsmaelMartinez and others added 3 commits March 12, 2026 23:31
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… only

Web notification path returns the real Notification object (or null on
failure), preserving Teams' ability to manage its own lifecycle. The
Notification-like stub is only needed for electron and custom methods
where the actual notification is handled out-of-process.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verifies that the preload.js Notification override returns objects with
the lifecycle methods Teams expects (addEventListener, removeEventListener,
close, dispatchEvent). Covers electron, custom, and web notification methods.

Tests run without authentication, so they work both locally and in the
cross-distro Docker containers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
20.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate notifications for first message and missing content for subsequent ones

1 participant