(cb: () => void | Promise<void>)
| 112 | } |
| 113 | |
| 114 | export async function getComponentCalls(cb: () => void | Promise<void>) { |
| 115 | const componentNames: Array<string> = [] |
| 116 | if (!internals) { |
| 117 | throw new Error('🚨 React DevTools is not available') |
| 118 | } |
| 119 | |
| 120 | const supportsInjectedProfilingHooks = |
| 121 | typeof internals.injectProfilingHooks === 'function' |
| 122 | |
| 123 | if (supportsInjectedProfilingHooks) { |
| 124 | internals.enableProfilerTimer = true |
| 125 | internals.enableProfilerCommitHooks = true |
| 126 | internals.injectProfilingHooks({ |
| 127 | markComponentRenderStarted: (fiber: any) => { |
| 128 | componentNames.push(fiber.type.name || 'Anonymous') |
| 129 | }, |
| 130 | }) |
| 131 | } else { |
| 132 | activeFallbackComponentNames = componentNames |
| 133 | } |
| 134 | |
| 135 | try { |
| 136 | await cb() |
| 137 | } finally { |
| 138 | if (supportsInjectedProfilingHooks) { |
| 139 | internals.enableProfilerTimer = false |
| 140 | internals.enableProfilerCommitHooks = false |
| 141 | internals.injectProfilingHooks(null) |
| 142 | } else { |
| 143 | activeFallbackComponentNames = null |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return componentNames |
| 148 | } |
| 149 | |
| 150 | if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) { |
| 151 | window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = enhanceExistingHook( |
no outgoing calls
no test coverage detected