@@ -26,10 +26,11 @@ import {
26
26
inspectElement ,
27
27
} from 'react-devtools-shared/src/inspectedElementCache' ;
28
28
import {
29
+ clearHookNamesCache ,
29
30
hasAlreadyLoadedHookNames ,
30
31
loadHookNames ,
31
32
} from 'react-devtools-shared/src/hookNamesCache' ;
32
- import LoadHookNamesFunctionContext from 'react-devtools-shared/src/devtools/views/Components/LoadHookNamesFunctionContext ' ;
33
+ import HookNamesContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesContext ' ;
33
34
import { SettingsContext } from '../Settings/SettingsContext' ;
34
35
35
36
import type { HookNames } from 'react-devtools-shared/src/types' ;
@@ -63,7 +64,10 @@ export type Props = {|
63
64
64
65
export function InspectedElementContextController ( { children} : Props ) {
65
66
const { selectedElementID} = useContext ( TreeStateContext ) ;
66
- const loadHookNamesFunction = useContext ( LoadHookNamesFunctionContext ) ;
67
+ const {
68
+ loadHookNames : loadHookNamesFunction ,
69
+ purgeCachedMetadata,
70
+ } = useContext ( HookNamesContext ) ;
67
71
const bridge = useContext ( BridgeContext ) ;
68
72
const store = useContext ( StoreContext ) ;
69
73
const { parseHookNames : parseHookNamesByDefault } = useContext ( SettingsContext ) ;
@@ -150,6 +154,24 @@ export function InspectedElementContextController({children}: Props) {
150
154
[ setState , state ] ,
151
155
) ;
152
156
157
+ useEffect ( ( ) => {
158
+ if ( enableHookNameParsing ) {
159
+ if ( typeof purgeCachedMetadata === 'function' ) {
160
+ // When Fast Refresh updates a component, any cached AST metadata may be invalid.
161
+ const fastRefreshScheduled = ( ) => {
162
+ startTransition ( ( ) => {
163
+ clearHookNamesCache ( ) ;
164
+ purgeCachedMetadata ( ) ;
165
+ refresh ( ) ;
166
+ } ) ;
167
+ } ;
168
+ bridge . addListener ( 'fastRefreshScheduled' , fastRefreshScheduled ) ;
169
+ return ( ) =>
170
+ bridge . removeListener ( 'fastRefreshScheduled' , fastRefreshScheduled ) ;
171
+ }
172
+ }
173
+ } , [ bridge ] ) ;
174
+
153
175
// Reset path now that we've asked the backend to hydrate it.
154
176
// The backend is stateful, so we don't need to remember this path the next time we inspect.
155
177
useEffect ( ( ) => {
0 commit comments