| 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 {useContext, useSyncExternalStore} from 'react'; |
| 12 | import {ProfilerContext} from './ProfilerContext'; |
| 13 | import {StoreContext} from '../context'; |
| 14 | |
| 15 | import styles from './Profiler.css'; |
| 16 | |
| 17 | export default function NoProfilingData(): React.Node { |
| 18 | const {startProfiling} = useContext(ProfilerContext); |
| 19 | const store = useContext(StoreContext); |
| 20 | |
| 21 | // React only started emitting Performance tracks in 19.2. |
| 22 | const supportsPerformanceTracks = useSyncExternalStore<boolean>( |
| 23 | function subscribe(callback) { |
| 24 | store.addListener('rootSupportsPerformanceTracks', callback); |
| 25 | return function unsubscribe() { |
| 26 | store.removeListener('rootSupportsPerformanceTracks', callback); |
| 27 | }; |
| 28 | }, |
| 29 | function getState() { |
| 30 | return store.rootSupportsPerformanceTracks; |
| 31 | }, |
| 32 | ); |
| 33 | |
| 34 | const performanceTracksLink = ( |
| 35 | <a |
| 36 | className={styles.DescriptionLink} |
| 37 | href="https://react.dev/reference/dev-tools/react-performance-tracks" |
| 38 | rel="noopener noreferrer" |
| 39 | target="_blank"> |
| 40 | Performance tracks |
| 41 | </a> |
| 42 | ); |
| 43 | |
| 44 | return ( |
| 45 | <div className={styles.Column}> |
| 46 | <div className={styles.Header}>No profiling data has been recorded</div> |
| 47 | <div className={styles.Description}> |
| 48 | Record a session to see which components rendered, how long they took, |
| 49 | and why.{' '} |
| 50 | <a |
| 51 | className={styles.DescriptionLink} |
| 52 | href="https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html" |
| 53 | rel="noopener noreferrer" |
| 54 | target="_blank"> |
| 55 | Learn more |
| 56 | </a> |
| 57 | </div> |
| 58 | <button |
| 59 | className={styles.CTAButton} |
| 60 | onClick={startProfiling} |
| 61 | type="button"> |
| 62 | Start recording |
| 63 | </button> |
| 64 | <div className={styles.PerformanceTracksCard}> |
| 65 | To profile scheduling and rendering on a timeline,{' '} |
| 66 | {supportsPerformanceTracks ? ( |
| 67 | <> |
| 68 | record a profile in the Performance panel — React adds its own{' '} |
| 69 | {performanceTracksLink} there. |
| 70 | </> |
| 71 | ) : ( |
| 72 | <> |
| 73 | upgrade to React 19.2 or newer, which adds {performanceTracksLink}{' '} |
| 74 | to the Performance panel. |
| 75 | </> |
| 76 | )} |
| 77 | </div> |
| 78 | </div> |
| 79 | ); |
| 80 | } |