Skip to content

fix(coding-conventions): Ensure stable component identity for InlineEventAttachment#120032

Open
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/static-component-definitions-inline-attachment
Open

fix(coding-conventions): Ensure stable component identity for InlineEventAttachment#120032
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/static-component-definitions-inline-attachment

Conversation

@sentry

@sentry sentry Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a static-component-definitions violation reported by the React Compiler in static/app/views/issueDetails/groupEventAttachments/inlineEventAttachment.tsx.

Problem:
The InlineEventAttachment component was dynamically determining the AttachmentComponent to render by calling getInlineAttachmentRenderer(attachment) inside its render function. The React Compiler interprets this pattern as creating a new component identity on every render, which can lead to state resets and prevents compiler optimizations.

Solution:
To resolve this, the dynamic component selection logic has been encapsulated within a new, static functional component called AttachmentViewer. InlineEventAttachment now renders this AttachmentViewer directly. The AttachmentViewer component then uses conditional rendering (if statements) to return the appropriate static viewer component (e.g., ImageViewer, VideoViewer, JsonViewer).

This ensures that the component type used in JSX (<AttachmentViewer />) is always a stable, statically defined reference, satisfying the React Compiler's StaticComponents rule and preventing the static-component-definitions violation.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes CODING-CONVENTIONS-36F

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@sentry
sentry Bot requested a review from a team as a code owner July 19, 2026 19:55
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a5c380f. Configure here.

return <JsonViewer {...commonProps} />;
}
return null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicated attachment viewer selection

Medium Severity

AttachmentViewer reimplements the mime-type selection already owned by getInlineAttachmentRenderer, including local copies of logFileMimeTypes and jsonMimeTypes. The copy also omits the nonPreviewableExtensions guard, so the gate and renderer can drift and pick different viewers later.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a5c380f. Configure here.

Comment on lines +33 to +43
'text/csv',
'text/html',
'text/javascript',
'text/plain',
];
const jsonMimeTypes = [
'application/json',
'application/ld+json',
'text/json',
'text/x-json',
];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bug: The logFileMimeTypes and jsonMimeTypes arrays 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 logFileMimeTypes and jsonMimeTypes arrays from previewAttachmentTypes.tsx. Then, import and use these arrays directly in inlineEventAttachment.tsx instead of using locally-defined duplicates.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
static/app/views/issueDetails/groupEventAttachments/inlineEventAttachment.tsx#L31-L43

Potential issue: The `logFileMimeTypes` and `jsonMimeTypes` arrays are locally
re-defined in `inlineEventAttachment.tsx`, duplicating the same un-exported arrays from
`previewAttachmentTypes.tsx`. While currently synchronized, this creates a
maintainability issue. If the source arrays in `previewAttachmentTypes.tsx` are updated
in the future to support new MIME types, the duplicated arrays in this component will
not be updated automatically. This divergence would cause the attachment viewer to fail
to render an attachment (returning `null`) even after the initial guard check passes,
because the local MIME type list would be stale.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

1 participant