Skip to content

Commit 55d01aa

Browse files
author
Brian Vaughn
authored
Scheduling profiler: Canvas views clip by default (#22100)
1 parent bc4e751 commit 55d01aa

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

packages/react-devtools-scheduling-profiler/src/content-views/SnapshotsView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export class SnapshotsView extends View {
118118
const visibleArea = this.visibleArea;
119119

120120
// Prevent snapshot from visibly overflowing its container when clipped.
121+
// View clips by default, but since this view may draw async (on Image load) we re-clip.
121122
const shouldClip = !rectEqualToRect(imageRect, visibleArea);
122123
if (shouldClip) {
123124
const clippedRect = intersectionOfRects(imageRect, visibleArea);

packages/react-devtools-scheduling-profiler/src/content-views/SuspenseEventsView.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,13 @@ export class SuspenseEventsView extends View {
168168
return; // Not in view
169169
}
170170

171-
const drawableRect = intersectionOfRects(suspenseRect, rect);
172-
173-
// Clip diamonds so they don't overflow if the view has been resized (smaller).
174-
const region = new Path2D();
175-
region.rect(
176-
drawableRect.origin.x,
177-
drawableRect.origin.y,
178-
drawableRect.size.width,
179-
drawableRect.size.height,
180-
);
181-
context.save();
182-
context.clip(region);
183171
context.beginPath();
184172
context.fillStyle = fillStyle;
185173
context.moveTo(xStart, y - halfSize);
186174
context.lineTo(xStart + halfSize, y);
187175
context.lineTo(xStart, y + halfSize);
188176
context.lineTo(xStart - halfSize, y);
189177
context.fill();
190-
context.restore();
191178
} else {
192179
const xStop = timestampToPosition(
193180
timestamp + duration,

packages/react-devtools-scheduling-profiler/src/view-base/View.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,24 @@ export class View {
199199
this.layoutSubviews();
200200
if (this._needsDisplay) this._needsDisplay = false;
201201
if (this._subviewsNeedDisplay) this._subviewsNeedDisplay = false;
202+
203+
// Clip anything drawn by the view to prevent it from overflowing its visible area.
204+
const visibleArea = this.visibleArea;
205+
const region = new Path2D();
206+
region.rect(
207+
visibleArea.origin.x,
208+
visibleArea.origin.y,
209+
visibleArea.size.width,
210+
visibleArea.size.height,
211+
);
212+
context.save();
213+
context.clip(region);
214+
context.beginPath();
215+
202216
this.draw(context, viewRefs);
217+
218+
// Stop clipping
219+
context.restore();
203220
}
204221
}
205222

0 commit comments

Comments
 (0)