Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools in production #212

Open
spacecat opened this issue Jul 26, 2024 · 3 comments
Open

DevTools in production #212

spacecat opened this issue Jul 26, 2024 · 3 comments

Comments

@spacecat
Copy link

spacecat commented Jul 26, 2024

Hi,

Stupid question maybe but what happens with the DevTools component that I have in my forms when I deploy to production?

I have "@hookform/devtools": "^4.3.1", in my devDependencies in package.json but won't my app break in production wherever I'm referencing @hookform/devtools?

@ViewableGravy
Copy link

What you might consider doing is a similar approach with most other libraries and their dev tools that should be lazy loaded;

ie. Tanstack Router

So in the case of this particular package, you can likely accomplish the same thing with the below code (untested)

export const HookFormDevtools =
  process.env.NODE_ENV === 'production'
    ? () => null // Render nothing in production
    : React.lazy(() =>
        // Lazy load in development
        import('@hookform/devtools').then((res) => ({
          default: res.DevTool
        })),
      )

Note: I am not a maintainer of this library, this just seems like a common approach that would work in the case of these dev tools, similar to others.

@ahkhanjani
Copy link

@spacecat I think it should be mentioned in the readme. As for what happens, if you take a look at rollup/writeCjsEntryFile.js file the bundler handles this case:

if (process.env.NODE_ENV !== 'development') {
  module.exports = {
    DevTool: () => null,
  };
} else {
  ${baseLine}.${formatName}.development.js')
}

So there's no devtools in prod. No need for manual checking.

@spacecat
Copy link
Author

spacecat commented Nov 20, 2024

@spacecat I think it should be mentioned in the readme. As for what happens, if you take a look at rollup/writeCjsEntryFile.js file the bundler handles this case:

if (process.env.NODE_ENV !== 'development') {
  module.exports = {
    DevTool: () => null,
  };
} else {
  ${baseLine}.${formatName}.development.js')
}

So there's no devtools in prod. No need for manual checking.

@ahkhanjani I agree that it should be mentioned in the docs. I don't think it is ATM, however? I haven't checked recently....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants