Skip to content

Commit

Permalink
Highlight React events with the same wakeable ID (#111)
Browse files Browse the repository at this point in the history
Summary
---

Resolves #44.

Intended to highlight all related React events. However, it looks like
separate promises can have the same wakeable ID, which is a bit strange.

TODO
---

* Ensure that we are correctly understanding wakeable IDs, i.e. that
  a unique resource/promise is a unique wakeable.
* Check if `unstable_createResource` caches promises.

Test Plan
---

* `yarn lint`
* `yarn flow`: no errors in changed code
  • Loading branch information
taneliang authored Aug 4, 2020
1 parent 2f74a5c commit cb50ff8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/canvas/views/ReactEventsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import {
REACT_WORK_BORDER_SIZE,
} from '../constants';

function isSuspenseEvent(event: ReactEvent): boolean %checks {
return (
event.type === 'suspense-suspend' ||
event.type === 'suspense-resolved' ||
event.type === 'suspense-rejected'
);
}

export class ReactEventsView extends View {
_profilerData: ReactProfilerData;
_intrinsicSize: Size;
Expand Down Expand Up @@ -142,8 +150,17 @@ export class ReactEventsView extends View {
frame,
);

const highlightedEvents: ReactEvent[] = [];

events.forEach(event => {
if (event === _hoveredEvent) {
if (
event === _hoveredEvent ||
(_hoveredEvent &&
isSuspenseEvent(event) &&
isSuspenseEvent(_hoveredEvent) &&
event.id === _hoveredEvent.id)
) {
highlightedEvents.push(event);
return;
}
this._drawSingleReactEvent(
Expand All @@ -156,18 +173,18 @@ export class ReactEventsView extends View {
);
});

// Draw the hovered and/or selected items on top so they stand out.
// Draw the highlighted items on top so they stand out.
// This is helpful if there are multiple (overlapping) items close to each other.
if (_hoveredEvent !== null) {
highlightedEvents.forEach(event => {
this._drawSingleReactEvent(
context,
visibleArea,
_hoveredEvent,
event,
baseY,
scaleFactor,
true,
);
}
});

// Render bottom border.
// Propose border rect, check if intersects with `rect`, draw intersection.
Expand Down

0 comments on commit cb50ff8

Please sign in to comment.