aralroca / next-translate-plugin

Next-translate plugin for i18n in Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
32 stars 20 forks source link

Custom HOC breaks auto-static-optimization in build #71

Closed poeyer closed 1 year ago

poeyer commented 1 year ago

What version of this package are you using?

What operating system, Node.js, and npm version?

What happened? Using pages

The plugin checks if the app has a HOC. If you add a custom HOC without getInitialProps, the plugin assumes it's a HOC with getInitialProps. This makes you opt out of the https://nextjs.org/docs/messages/opt-out-auto-static-optimization because the logic of the Next.js build checks if there is a getInitialProps or not. The hasHoc util must check if the app actually has getInitialProps and only return the HOC template if that's the case.

I have this issue with TRPC, you need to have: export default trpcHoc.withTRPC(App)

When SSR: false, it doesn't do getInitialProps

What did you expect to happen?

Are you willing to submit a pull request to fix this bug? No

aralroca commented 1 year ago

This behavior is because there are some HOC that internally are overwritting the getInitialProps. This behavior is documented in the README.md that this is in this way just to avoid issues with HOC. If you know that the HOC is fine, you always can do this workaround to force what loader do you want in your page:

export let getStaticProps = undefined

https://github.com/aralroca/next-translate/issues/801#issuecomment-1059800473