Skip to content

[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

Merged
merged 9 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Adds React debugging tools to the Chrome Developer Tools.",
"version": "6.1.1",
"version_name": "6.1.1",
"minimum_chrome_version": "102",
"minimum_chrome_version": "114",
"icons": {
"16": "icons/16-production.png",
"32": "icons/32-production.png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,30 @@ 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) {
try {
if (canvas.matches(':popover-open')) {
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-use]
canvas.hidePopover();
}
} catch (e) {}
}
return;
}

if (canvas === null) {
initialize();
} else {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, you don't need it to wrap it in try / catch, since we bumped minimum versions for the extension

Please also check other calls below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out! I've removed all try/catch blocks around Popover API calls.

if (!canvas.matches(':popover-open')) {
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-use]
canvas.showPopover();
}
} catch (e) {}
}

const dpr = window.devicePixelRatio || 1;
Expand Down Expand Up @@ -191,7 +213,15 @@ function destroyNative(agent: Agent) {

function destroyWeb() {
if (canvas !== null) {
try {
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-use]
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;
Expand All @@ -204,6 +234,9 @@ export function destroy(agent: Agent): void {

function initialize(): void {
canvas = window.document.createElement('canvas');
// canvas.setAttribute('popover', 'manual');

// $FlowFixMe[incompatible-use]
canvas.style.cssText = `
xx-background-color: red;
xx-opacity: 0.5;
Expand All @@ -213,9 +246,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]
// $FlowFixMe[incompatible-use]
canvas.showPopover();
} catch (e) {}
}
Loading