| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | import {useRef, useState} from 'react'; |
| 12 | |
| 13 | const Counter = () => { |
| 14 | const [count, setCount] = useState(0); |
| 15 | |
| 16 | return ( |
| 17 | <div> |
| 18 | <h3>Count: {count}</h3> |
| 19 | <button onClick={() => setCount(c => c + 1)}>Increment</button> |
| 20 | </div> |
| 21 | ); |
| 22 | }; |
| 23 | |
| 24 | function DialogComponent() { |
| 25 | const dialogRef = useRef(null); |
| 26 | |
| 27 | const openDialog = () => { |
| 28 | if (dialogRef.current) { |
| 29 | dialogRef.current.showModal(); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | const closeDialog = () => { |
| 34 | if (dialogRef.current) { |
| 35 | dialogRef.current.close(); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | return ( |
| 40 | <div style={{margin: '10px 0'}}> |
| 41 | <button onClick={openDialog}>Open Dialog</button> |
| 42 | <dialog ref={dialogRef} style={{padding: '20px'}}> |
| 43 | <h3>Dialog Content</h3> |
| 44 | <Counter /> |
| 45 | <button onClick={closeDialog}>Close</button> |
| 46 | </dialog> |
| 47 | </div> |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | function RegularComponent() { |
| 52 | return ( |
| 53 | <div style={{margin: '10px 0'}}> |
| 54 | <h3>Regular Component</h3> |
| 55 | <Counter /> |
| 56 | </div> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | export default function TraceUpdatesTest(): React.Node { |
| 61 | return ( |
| 62 | <div> |
| 63 | <h2>TraceUpdates Test</h2> |
| 64 | |
| 65 | <div style={{marginBottom: '20px'}}> |
| 66 | <h3>Standard Component</h3> |
| 67 | <RegularComponent /> |
| 68 | </div> |
| 69 | |
| 70 | <div style={{marginBottom: '20px'}}> |
| 71 | <h3>Dialog Component (top-layer element)</h3> |
| 72 | <DialogComponent /> |
| 73 | </div> |
| 74 | |
| 75 | <div |
| 76 | style={{marginTop: '20px', padding: '10px', border: '1px solid #ddd'}}> |
| 77 | <h3>How to Test:</h3> |
| 78 | <ol> |
| 79 | <li>Open DevTools Components panel</li> |
| 80 | <li>Enable "Highlight updates when components render" in settings</li> |
| 81 | <li>Click increment buttons and observe highlights</li> |
| 82 | <li>Open the dialog and test increments there as well</li> |
| 83 | </ol> |
| 84 | </div> |
| 85 | </div> |
| 86 | ); |
| 87 | } |