-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(coding-conventions): Ensure stable component identity for InlineEventAttachment #120032
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| import {getInlineAttachmentRenderer} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes'; | ||
| import {ImageViewer} from 'sentry/components/events/attachmentViewers/imageViewer'; | ||
| import {JsonViewer} from 'sentry/components/events/attachmentViewers/jsonViewer'; | ||
| import {LogFileViewer} from 'sentry/components/events/attachmentViewers/logFileViewer'; | ||
| import { | ||
| getInlineAttachmentRenderer, | ||
| imageMimeTypes, | ||
| webmMimeTypes, | ||
| } from 'sentry/components/events/attachmentViewers/previewAttachmentTypes'; | ||
| import {RRWebJsonViewer} from 'sentry/components/events/attachmentViewers/rrwebJsonViewer'; | ||
| import {VideoViewer} from 'sentry/components/events/attachmentViewers/videoViewer'; | ||
| import {PanelItem} from 'sentry/components/panels/panelItem'; | ||
| import type {Event} from 'sentry/types/event'; | ||
| import type {IssueAttachment} from 'sentry/types/group'; | ||
|
|
@@ -12,21 +21,67 @@ interface InlineAttachmentsProps { | |
| projectSlug: string; | ||
| } | ||
|
|
||
| interface AttachmentViewerProps { | ||
| attachment: IssueAttachment; | ||
| eventId: string; | ||
| orgSlug: string; | ||
| projectSlug: string; | ||
| } | ||
|
|
||
| const logFileMimeTypes = [ | ||
| 'text/css', | ||
| 'text/csv', | ||
| 'text/html', | ||
| 'text/javascript', | ||
| 'text/plain', | ||
| ]; | ||
| const jsonMimeTypes = [ | ||
| 'application/json', | ||
| 'application/ld+json', | ||
| 'text/json', | ||
| 'text/x-json', | ||
| ]; | ||
|
|
||
| function AttachmentViewer({ | ||
| attachment, | ||
| orgSlug, | ||
| projectSlug, | ||
| eventId, | ||
| }: AttachmentViewerProps) { | ||
| const commonProps = {attachment, orgSlug, projectSlug, eventId}; | ||
|
|
||
| if (imageMimeTypes.includes(attachment.mimetype)) { | ||
| return <ImageViewer {...commonProps} />; | ||
| } | ||
| if (webmMimeTypes.includes(attachment.mimetype)) { | ||
| return <VideoViewer {...commonProps} />; | ||
| } | ||
| if (logFileMimeTypes.includes(attachment.mimetype)) { | ||
| return <LogFileViewer {...commonProps} />; | ||
| } | ||
| if (jsonMimeTypes.includes(attachment.mimetype)) { | ||
| if (attachment.name === 'rrweb.json' || attachment.name.startsWith('rrweb-')) { | ||
| return <RRWebJsonViewer {...commonProps} />; | ||
| } | ||
| return <JsonViewer {...commonProps} />; | ||
| } | ||
| return null; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated attachment viewer selectionMedium Severity
Reviewed by Cursor Bugbot for commit a5c380f. Configure here. |
||
|
|
||
| export function InlineEventAttachment({ | ||
| attachment, | ||
| projectSlug, | ||
| eventId, | ||
| }: InlineAttachmentsProps) { | ||
| const organization = useOrganization(); | ||
| const AttachmentComponent = getInlineAttachmentRenderer(attachment); | ||
|
|
||
| if (!AttachmentComponent) { | ||
| if (!getInlineAttachmentRenderer(attachment)) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <AttachmentPreviewWrapper> | ||
| <AttachmentComponent | ||
| <AttachmentViewer | ||
| orgSlug={organization.slug} | ||
| projectSlug={projectSlug} | ||
| eventId={eventId} | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
logFileMimeTypesandjsonMimeTypesarrays are duplicated, creating a risk of them becoming out of sync with the source, which could lead to rendering failures.Severity: LOW
Suggested Fix
To prevent future divergence, export the
logFileMimeTypesandjsonMimeTypesarrays frompreviewAttachmentTypes.tsx. Then, import and use these arrays directly ininlineEventAttachment.tsxinstead of using locally-defined duplicates.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.