Skip to content

Commit ae114c8

Browse files
authored
fix(trace-viewer): keep snapshot frame centered with margin (#41479)
1 parent b7a90d2 commit ae114c8

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/trace-viewer/src/ui/snapshotTab.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,16 @@ const SnapshotWrapper: React.FunctionComponent<React.PropsWithChildren<{
211211
height: Math.max(snapshotContainerSize.height + windowHeaderHeight, 320),
212212
};
213213

214-
const scale = Math.min(measure.width / renderedBrowserFrameSize.width, measure.height / renderedBrowserFrameSize.height, 1);
214+
// `measure` is the wrapper's border box (getBoundingClientRect), which includes the
215+
// 10px padding on every side. Fit and center the frame within the content box so it
216+
// keeps a padding-sized margin (with room for the box-shadow) when squeezed.
217+
const padding = 10;
218+
const availableWidth = measure.width - 2 * padding;
219+
const availableHeight = measure.height - 2 * padding;
220+
const scale = Math.min(availableWidth / renderedBrowserFrameSize.width, availableHeight / renderedBrowserFrameSize.height, 1);
215221
const translate = {
216-
x: (measure.width - renderedBrowserFrameSize.width) / 2,
217-
y: (measure.height - renderedBrowserFrameSize.height) / 2,
222+
x: (measure.width - renderedBrowserFrameSize.width) / 2 - padding,
223+
y: (measure.height - renderedBrowserFrameSize.height) / 2 - padding,
218224
};
219225

220226
return <div ref={ref} className='snapshot-wrapper'>

0 commit comments

Comments
 (0)