Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add VisynEvents to send global events, incl. better Sentry integration #757

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

puehringer
Copy link
Contributor

@puehringer puehringer commented Mar 7, 2025

Developer Checklist (Definition of Done)

Issue

  • All acceptance criteria from the issue are met
  • Tested in latest Chrome/Firefox

UI/UX/Vis

  • Requires UI/UX/Vis review
    • Reviewer(s) are notified (tag assignees)
    • Review has occurred (link to notes)
    • Feedback is included in this PR
    • Reviewer(s) approve of concept and design

Code

  • Branch is up-to-date with the branch to be merged with, i.e., develop
  • Code is cleaned up and formatted
  • Unit tests are written (frontend/backend if applicable)
  • Integration tests are written (if applicable)

PR

  • Descriptive title for this pull request is provided (will be used for release notes later)
  • Reviewer and assignees are defined
  • Add type label (e.g., bug, feature) to this pull request
  • Add release label (e.g., release: minor) to this PR following semver
  • The PR is connected to the corresponding issue (via Closes #...)
  • Summary of changes is written

Summary of changes

  • Why? I was looking for a way to let apps react to the Sentry.init event (both in React but also globally). We previously had the globalEventHandler mechanism, but that is completely untyped and uses a custom event system (inspired by jQuery). The modern way to do this is via window.dispatchEvent, and the VisynEvent is just a typed wrapper around it.
  • Migrates the useVisynUser, watcher, ... to the new mechanism, while keeping the old fire in place to ensure backwards compatibility. Removes usage of session storage to store user, as that is not recommended and has been replaced in favor of a "memory" store, i.e. a variable
  • Exposes hooks useVisynEventCallback and useVisynEventValue to listen to the changes/values of the events.
  • Adds a main_app entrypoint to the server to finally give us a way of what the primary plugin is. With that, we can send proper Sentry release information.

Screenshots

Additional notes for the reviewer(s)

Thanks for creating this pull request 🤗

@puehringer puehringer requested a review from a team as a code owner March 7, 2025 22:21
@puehringer puehringer requested review from thinkh and Copilot March 7, 2025 22:21
@puehringer puehringer added release: minor PR merge results in a new minor version type: feature New feature or request labels Mar 7, 2025

Choose a reason for hiding this comment

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

PR Overview

This PR introduces a typed event mechanism ("VisynEvents") to replace and augment the legacy global event handling for key application events such as Sentry initialization and user session changes. Key changes include:

  • Adding new hooks (useVisynEventCallback and useVisynEventValue) to listen to typed events.
  • Defining the VisynEventMap and supporting functions (dispatchVisynEvent, addVisynEventListener, removeVisynEventListener) for global event dispatching.
  • Migrating existing event usage (in UserSession, SessionWatcher, VisynAppProvider, etc.) from the legacy globalEventHandler mechanism to the new VisynEvents system.

Reviewed Changes

File Description
src/hooks/useVisynEventValue.tsx New hook to subscribe to event values via the new mechanism.
src/hooks/useVisynEventCallback.tsx New hook to listen for event triggers using a stable callback.
src/app/VisynEvents.ts Defines the typed event interface and helper functions.
src/demo/index.initialize.tsx Demonstrates usage of sending and listening to a sentryInitialized event.
src/security/UserSession.ts Migrates user login/logout events to use dispatchVisynEvent.
src/hooks/useVisynUser.ts Simplifies user retrieval by leveraging the updated VisynAppContext.
src/base/event.ts Marks legacy event handling APIs as deprecated.
src/app/VisynAppProvider.ts Updates Sentry initialization and user session propagation to use new events.
src/security/watcher.ts Adjusts session watcher to listen to new user events.
src/demo/MainApp.tsx Switches from the old context hook to the new useVisynUser hook.

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

@puehringer puehringer changed the title feat: add VisynEvents to send global events feat: add VisynEvents to send global events, incl. better Sentry integration Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: minor PR merge results in a new minor version type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants