react-scan icon indicating copy to clipboard operation
react-scan copied to clipboard

Incorrect production enviroment detection

Open ha1fstack opened this issue 6 months ago • 2 comments

React Scan would not run in many conditions where multiple react root exists, such as Next.js dev environment.

https://github.com/aidenybai/react-scan/blob/0fae9f3ab1ff25e98a4307bf826a4dd2c50a168a/packages/scan/src/core/index.ts#L537

export const getIsProduction = () => {
  if (isProduction !== null) {
    return isProduction;
  }
  rdtHook ??= getRDTHook();
  for (const renderer of rdtHook.renderers.values()) {
    const buildType = detectReactBuildType(renderer);
    if (buildType === 'production') {
      isProduction = true;
    }
  }
  return isProduction;
};
Image Image

For example, in Next.js dev environment, the next-devtools overlay uses production build of react and has separate root.

getIsProduction helper wrongly sets isProduction to true, so react-scan is not enabled.

For temporary workaround, you can set dangerouslyForceRunInProduction option to true and use other methods to decide whether to run scan.

ha1fstack avatar Aug 05 '25 05:08 ha1fstack

Thanks for the issue, will get this fixed!

RobPruzan avatar Aug 05 '25 18:08 RobPruzan

Same issue

brunocapdevila avatar Sep 10 '25 16:09 brunocapdevila

you may use a trick be like

    if (IS_DEV) {
      scan({
        enabled: true,
        dangerouslyForceRunInProduction: true,
      })
    }

zhsama avatar Dec 03 '25 10:12 zhsama