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

fix(feedback): Check for empty user #11993

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/feedback/src/modal/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ import type {
FeedbackFormData,
FeedbackModalIntegration,
IntegrationFn,
User,
} from '@sentry/types';
import { h, render } from 'preact';
import { DOCUMENT } from '../constants';
import { Dialog } from './components/Dialog';
import { createDialogStyles } from './components/Dialog.css';

function getUser(): User | undefined {
const currentUser = getCurrentScope().getUser();
const isolationUser = getIsolationScope().getUser();
const globalUser = getGlobalScope().getUser();
if (currentUser && Object.keys(currentUser).length) {
return currentUser;
}
if (isolationUser && Object.keys(isolationUser).length) {
return isolationUser;
}
return globalUser;
Copy link
Member

Choose a reason for hiding this comment

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

Can this also return the empty object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it can. We want to check all scopes to see if any have been set, and if not, it'll return an empty object. We were using null coalescing before, which didn't work for empty objects, and would return the empty object without checking the other scopes.

}

export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
return {
name: 'FeedbackModal',
Expand All @@ -19,7 +33,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
createDialog: ({ options, screenshotIntegration, sendFeedback, shadow }: CreateDialogProps) => {
const shadowRoot = shadow as unknown as ShadowRoot;
const userKey = options.useSentryUser;
const user = getCurrentScope().getUser() || getIsolationScope().getUser() || getGlobalScope().getUser();
const user = getUser();

const el = DOCUMENT.createElement('div');
const style = createDialogStyles();
Expand Down
Loading