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 all 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
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/edge/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 Microsoft Edge 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 @@ -65,6 +65,24 @@ function drawWeb(nodeToData: Map<HostInstance, Data>) {
drawGroupBorders(context, group);
drawGroupLabel(context, group);
});

if (canvas !== null) {
if (nodeToData.size === 0 && 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;
}
// $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API
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();
}
// $FlowFixMe[prop-missing]: Flow doesn't recognize Popover API
// $FlowFixMe[incompatible-use]: Flow doesn't recognize Popover API
canvas.showPopover();
}
}

type GroupItem = {
Expand Down Expand Up @@ -191,7 +209,15 @@ function destroyNative(agent: Agent) {

function destroyWeb() {
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();
}

// $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 +230,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;
Expand All @@ -213,7 +242,10 @@ 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;
Expand Down
87 changes: 87 additions & 0 deletions packages/react-devtools-shell/src/app/TraceUpdatesTest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import * as React from 'react';
import {useRef, useState} from 'react';

const Counter = () => {
const [count, setCount] = useState(0);

return (
<div>
<h3>Count: {count}</h3>
<button onClick={() => setCount(c => c + 1)}>Increment</button>
</div>
);
};

function DialogComponent() {
const dialogRef = useRef(null);

const openDialog = () => {
if (dialogRef.current) {
dialogRef.current.showModal();
}
};

const closeDialog = () => {
if (dialogRef.current) {
dialogRef.current.close();
}
};

return (
<div style={{margin: '10px 0'}}>
<button onClick={openDialog}>Open Dialog</button>
<dialog ref={dialogRef} style={{padding: '20px'}}>
<h3>Dialog Content</h3>
<Counter />
<button onClick={closeDialog}>Close</button>
</dialog>
</div>
);
}

function RegularComponent() {
return (
<div style={{margin: '10px 0'}}>
<h3>Regular Component</h3>
<Counter />
</div>
);
}

export default function TraceUpdatesTest(): React.Node {
return (
<div>
<h2>TraceUpdates Test</h2>

<div style={{marginBottom: '20px'}}>
<h3>Standard Component</h3>
<RegularComponent />
</div>

<div style={{marginBottom: '20px'}}>
<h3>Dialog Component (top-layer element)</h3>
<DialogComponent />
</div>

<div
style={{marginTop: '20px', padding: '10px', border: '1px solid #ddd'}}>
<h3>How to Test:</h3>
<ol>
<li>Open DevTools Components panel</li>
<li>Enable "Highlight updates when components render" in settings</li>
<li>Click increment buttons and observe highlights</li>
<li>Open the dialog and test increments there as well</li>
</ol>
</div>
</div>
);
}
2 changes: 2 additions & 0 deletions packages/react-devtools-shell/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Toggle from './Toggle';
import ErrorBoundaries from './ErrorBoundaries';
import PartiallyStrictApp from './PartiallyStrictApp';
import SuspenseTree from './SuspenseTree';
import TraceUpdatesTest from './TraceUpdatesTest';
import {ignoreErrors, ignoreLogs, ignoreWarnings} from './console';

import './styles.css';
Expand Down Expand Up @@ -112,6 +113,7 @@ function mountTestApp() {
mountApp(SuspenseTree);
mountApp(DeeplyNestedComponents);
mountApp(Iframe);
mountApp(TraceUpdatesTest);

if (shouldRenderLegacy) {
mountLegacyApp(PartiallyStrictApp);
Expand Down