navapbc / template-application-nextjs

Next.js, TypeScript, USWDS, and Storybook template, including CI/CD, for teams at Nava building web applications
Apache License 2.0
10 stars 3 forks source link

server-only package ? #312

Closed rylew1 closed 5 months ago

rylew1 commented 6 months ago

Nextjs recommends using the server-only package (simply imported into server components). This will cause a build-time error if it's inadvertently imported from a client component, making sure we're not accidentally accessing secrets from the browser/client components. Would it make sense to include this in the template?

https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#keeping-server-only-code-out-of-the-client-environment

To prevent this sort of unintended client usage of server code, we can use the server-only package to give other developers a build-time error if they ever accidentally import one of these modules into a Client Component.