aralroca / next-translate-plugin

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

getInitialProps inside _app.js not being called #8

Closed aureliopita-au closed 1 year ago

aureliopita-au commented 1 year ago

What version of this package are you using? "next": "^13.2.3", "next-translate": "^2.0.2", "next-translate-plugin": "^2.0.2", "react": "^18.2.0", "react-dom": "^18.2.0"

What operating system, Node.js, and npm version? MacOS, Node v16.18.0, npm 8.19.2.

What happened? When using nextTranslate() inside next.config.js, getInitialProps from _app stops working.

What did you expect to happen? getInitialProps from _app keeps working.

Are you willing to submit a pull request to fix this bug? Not at the moment.

Reproducible repo Based on the basic example from your repo. Just added a getInitialProps to _app. https://github.com/aureliopita-au/next-translate-getInitialProps-bug

mrtnzlml commented 1 year ago

👍 I just encountered the same issue. I originally thought I implemented getInitialProps incorrectly, but it turns out it was not called at all. After some debugging, I noticed that config.skipInitialProps is internally set to "true" (incorrectly, probably because of this plugin). 🤔

micahjonas commented 1 year ago

I have encountered the same issue in our nextjs setup.

amosbastian commented 1 year ago

Did you guys find a solution to this? @aralroca any ideas?

aralroca commented 1 year ago

I think the error is related in this line of code:

https://github.com/aralroca/next-translate-plugin/blob/83c658603af659715bf7479b665e25180fad4f8f/src/index.ts#L75-L79

We replaced all regex by the TypeScript parser, but it probably has using a bad way to detect the getInitialProps. Feel free to PR to fix this.

danielpid commented 1 year ago

Hi @aralroca, I implemented a fix for this, could you add me as a collaborator so I can open a PR and continue the discussion there? Thanks!

aralroca commented 1 year ago

Thanks so much @danielpid !!

aralroca commented 1 year ago

@danielpid is already available in 2.5.3-canary.1, please confirm that is working fine in your projects before close this issue! Thanks

danielpid commented 1 year ago

@aralroca I confirm it works on my projects. Thanks!

aralroca commented 1 year ago

Cool!!!