-
Notifications
You must be signed in to change notification settings - Fork 50.2k
[DevTools] Use Popover API for TraceUpdates highlighting #32614
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
Changes from 5 commits
ecb403f
a83589c
9215664
f7eb1c6
938ad0e
9c21b1e
6893d25
862826b
c950b0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,28 @@ function drawNative(nodeToData: Map<HostInstance, Data>, agent: Agent) { | |
| } | ||
|
|
||
| function drawWeb(nodeToData: Map<HostInstance, Data>) { | ||
| // if there are no nodes to draw, detach from top layer | ||
| if (nodeToData.size === 0) { | ||
| if (canvas !== null) { | ||
| if (canvas.matches(':popover-open')) { | ||
| // $FlowFixMe[prop-missing]: Flow doesn't recognize Popover API | ||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API | ||
| canvas.hidePopover(); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (canvas === null) { | ||
| initialize(); | ||
| } else { | ||
| try { | ||
|
||
| if (!canvas.matches(':popover-open')) { | ||
| // $FlowFixMe[prop-missing]: Flow doesn't recognize Popover API | ||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API | ||
| canvas.showPopover(); | ||
| } | ||
| } catch (e) {} | ||
| } | ||
|
|
||
| const dpr = window.devicePixelRatio || 1; | ||
|
|
@@ -191,7 +211,15 @@ function destroyNative(agent: Agent) { | |
|
|
||
| function destroyWeb() { | ||
| if (canvas !== null) { | ||
| try { | ||
| // $FlowFixMe[prop-missing]: Flow doesn't recognize Popover API | ||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API | ||
| canvas.hidePopover(); | ||
| } catch (e) {} | ||
|
|
||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API and loses canvas nullability tracking | ||
| if (canvas.parentNode != null) { | ||
| // $FlowFixMe[incompatible-call]: Flow doesn't track that canvas is non-null here | ||
| canvas.parentNode.removeChild(canvas); | ||
| } | ||
| canvas = null; | ||
|
|
@@ -204,6 +232,9 @@ export function destroy(agent: Agent): void { | |
|
|
||
| function initialize(): void { | ||
| canvas = window.document.createElement('canvas'); | ||
| canvas.setAttribute('popover', 'manual'); | ||
|
|
||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API | ||
| canvas.style.cssText = ` | ||
| xx-background-color: red; | ||
| xx-opacity: 0.5; | ||
|
|
@@ -213,9 +244,18 @@ function initialize(): void { | |
| position: fixed; | ||
| right: 0; | ||
| top: 0; | ||
| z-index: 1000000000; | ||
| background-color: transparent; | ||
| outline: none; | ||
| box-shadow: none; | ||
| border: none; | ||
| `; | ||
|
|
||
| const root = window.document.documentElement; | ||
| root.insertBefore(canvas, root.firstChild); | ||
|
|
||
| try { | ||
| // $FlowFixMe[prop-missing]: Flow doesn't recognize Popover API | ||
| // $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API | ||
| canvas.showPopover(); | ||
| } catch (e) {} | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this new code changes the behaviour of the
drawWebfunction.Before this change, we would clear out canvas and draw nothing. Also, even if canvas was not initialized yet and
drawWebwas called, we would initialize it as empty.I think we should preserve the previous approach:
canvas.showPopover()frominitialize.drawWebfunction call, addcanvas.showPopoverorcanvas.hidePopovercalls, based onnodeToData.sizeand popover state.Something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Totally agree that we should first finish all
drawWeblogic and then decide at the end whether or not to promote it to the top-layer.I think that approach better fits the responsibilities of each method. Thanks for clarifying this!
Considering your comments, I've tested two different approaches:
1. Hiding the canvas only when there's nothing to draw (the current method):
Result: This method avoids frequent updates to the top-layer.
However, as you mentioned in your comment, if another top-layer element appears while highlights still remain, the highlight canvas might fall behind the new element.
2. Re-promoting canvas to top-layer on every update call:
Result: Frequent changes to the top-layer occur, but the highlights consistently remain on top, ensuring they never get hidden by other elements.
I think method
#2seems preferable in terms of clearly maintaining highlight visibility too.However, I couldn't find any mentions of performance issues in either the W3C review or blink-dev discussions regarding frequent
top-layerchanges. Unless highlights are triggered continuously at extremely high frequency over a prolonged period, there shouldn't be any noticeable performance impact.