Description
#21641 added support to DevTools for showing hook names for the inspected component. For performance reasons, this feature caches source maps and ASTs by file name to avoid re-parsing any time a new component is inspected.
As #21790 (comment) mentions:
A new compiled script can be loaded into the VM that has the same URL (
hookSource.fileName
), same source map URL and even the same original source URL(s) as a previously loaded script, but contains completely different code.
So our cache may be incorrect in the case of Fast Refresh (or other hot-reloading system).
The comment goes on to say:
We may want to just invalidate the world during Fast Refresh.
The trouble with this idea is that DevTools is not explicitly notified when Fast Refresh reloads a component.
The React core team has talked about the idea of adding a new, DEV-only Remount
bit/flag to Fibers to notify DevTools of this case. That would be a helpful signal here too that any cached source/AST should be cleared when hooks are next inspected. (The flag would need to be passed from backend to frontend as part of the "inspected element" payload.)