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(components): Add content diff slider common component #88418

Merged

Conversation

priscilawebdev
Copy link
Member

This PR adds a new common component named 'contentDiffSlider' (happy to rename if we have a better name).

Right now, we compare before-and-after replays for "hydration errors" on the issue details page (example – internal only). We want to use a similar component in the debugger modal to compare a bad and good stack trace.

image

This PR extracts part of the existing code to create a reusable component. It needs the before and after content, which can be either images or iframes (for session replays), making it flexible.

In a follow-up, it will be added to the debugger modal, and we can also reuse it on the issue details page to remove duplicate code.

@priscilawebdev priscilawebdev requested a review from ryan953 April 1, 2025 10:46
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 1, 2025
@priscilawebdev priscilawebdev marked this pull request as ready for review April 1, 2025 10:47
@priscilawebdev priscilawebdev requested a review from a team as a code owner April 1, 2025 10:47
@priscilawebdev priscilawebdev requested a review from a team April 1, 2025 10:47
Comment on lines 141 to 146
const handleDividerMouseDown: React.MouseEventHandler<HTMLElement> = useCallback(
(event: React.MouseEvent<HTMLElement>) => {
onDividerMouseDown?.(event);
resizableDrawer.onMouseDown(event);
},
[onDividerMouseDown, resizableDrawer]
Copy link
Contributor

Choose a reason for hiding this comment

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

note: there’s no need to wrap this function in useCallback. All we do is pass it to a functional component as a prop.

also, we have resizableDrawer as part of the dependency array here, which comes from useResizableDrawer, which returns a non-memoized object:

return {size, isHeld, onMouseDown, onDoubleClick, setSize: updateSize};

so this useCallback would be re-computed on every render anyways.

cursor: ew-resize;
width: var(--line-width);
height: 100%;
background: ${p => p.theme.purple400};
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably shouldn’t be using the theme colors directly, as they might not work with the chonk re-design. It would be better if we could use semantic tokens instead of the purple palette here.

@ryan953
Copy link
Member

ryan953 commented Apr 1, 2025

Shouldn't this also update that mentioned hydration error modal to use the same component?

Copy link
Member

Choose a reason for hiding this comment

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

can we run the images through an image optimizer feels like they should be 30-40kb

@priscilawebdev
Copy link
Member Author

Shouldn't this also update that mentioned hydration error modal to use the same component?

@ryan953 if we merge this component, I plan to do that in a follow-up.

…thub.com:getsentry/sentry into priscila/feat/components/add-content-diff-slider
Comment on lines +78 to +81
<DiffHeader>
<BeforeAfter label={t('Before')} help={beforeHelp} />
<BeforeAfter label={t('After')} help={afterHelp} />
</DiffHeader>
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably move this out of the main contentSliderDiff and let people add it themselves. Including it hard-codes some assumptions about the labels, whether this goes above/below or gets hidden at all. The two props that it takes are totally independant from the rest of the slider which will make it easy to be it's own thing.

@priscilawebdev priscilawebdev merged commit 6bd9983 into master Apr 3, 2025
40 checks passed
@priscilawebdev priscilawebdev deleted the priscila/feat/components/add-content-diff-slider branch April 3, 2025 08:12
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.

4 participants