Skip to content

feat(viewas): convert ViewAsBar to React component using useHotkeys#112687

Draft
sentry-junior[bot] wants to merge 1 commit intomasterfrom
feat/viewas-bar-react-component
Draft

feat(viewas): convert ViewAsBar to React component using useHotkeys#112687
sentry-junior[bot] wants to merge 1 commit intomasterfrom
feat/viewas-bar-react-component

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior bot commented Apr 10, 2026

Summary

Converts the superuser "View As" toolbar from a vanilla JS implementation to a proper React component using useHotkeys from @sentry/scraps/hotkey.

This is the sentry-side change. A companion change in getsentry/getsentry updates getsentry/templates/viewas/header.html to use the __onSentryInit injection pattern instead of inline vanilla JS.

Changes

static/app/components/viewAsBar/index.tsx (new)

  • New ViewAsBar React component
  • Uses useHotkeys with cmd+`` / ctrl+`` (changed from bare ``` to avoid collision with code block shortcuts)
  • Input/textarea focus suppression comes for free via useHotkeys defaults — fixes the Seer code-block triple-backtick collision
  • Renders the same toolbar UI (username, switch user form) that the old Django template did
  • Passes csrfToken as a prop for the Django form submission

static/app/types/system.tsx

  • Added VIEW_AS_BAR = 'ViewAsBar' to SentryInitRenderReactComponent enum

static/app/bootstrap/processInitQueue.tsx

  • Registered ViewAsBar in COMPONENT_MAP with lazy import

getsentry changes (apply separately)

The companion getsentry/getsentry diff strips the old HTML/CSS/JS from getsentry/templates/viewas/header.html and replaces it with:

<div id="viewas-bar-root"></div>
<script>
  window.__onSentryInit = window.__onSentryInit || [];
  window.__onSentryInit.push({
    name: 'renderReact',
    component: 'ViewAsBar',
    container: '#viewas-bar-root',
    props: { currentUsername, actualUsername, csrfToken },
  });
</script>

Testing

  • Toggle toolbar with `cmd+`` — should open/close
  • Try pressing ``` inside any text input or Seer — toolbar should NOT trigger
  • Switch user via form and verify Django session handling works as before

Fixes: https://github.com/getsentry/sentry/issues (backtick hotkey collides with Seer code blocks)

Replaces the vanilla JS keydown handler in the superuser 'view as' toolbar
with a proper React component that uses `useHotkeys` from `@sentry/scraps/hotkey`.

Key changes:
- New `ViewAsBar` component at `sentry/components/viewAsBar`
- Uses `useHotkeys` with `cmd+`` / `ctrl+`` — suppresses when input/textarea
  has focus (fixes the Seer code-block collision)
- Registered in `SentryInitRenderReactComponent` enum and `COMPONENT_MAP`
- Template updated separately in getsentry to use `__onSentryInit` injection

Ref: fix/viewas-compound-hotkey (supersedes that branch)
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants