question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify namespacesRequired without getInitialProps

See original GitHub issue

Specifying namespacesRequired is optional, but recommended for performance reasons. Currently, the only way to set namespacesRequired is from getInitialProps.

There are several pages in my projects that only have a getInitialProps to specify namespacesRequired, and using getInitialProps prevents next.js from performing automatic static optimization and pre-rendering HTML.

This makes it unclear which has better performance:

  • setting namespacesRequired, only sending the fewest translations required to the page, but sacrificing static optimization
  • Not setting namespacesRequired, sending all the translations to the page but letting next.js perform static optimization and prerender the HTML.

I think it’s worth considering exposing namespacesRequired with static properties on the page. hoist-non-react-statics may be helpful in this instance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
isaachinmancommented, Dec 18, 2019

This package will eventually be converted into a NextJs plugin once that functionality lands.

In the meantime, we could migrate this to a static, or something similar.

1reaction
ckeeneycommented, Nov 6, 2019

I didn’t realize appWithTranslation adds a getInitialProps to _app.js anyways.

next-i18next needs to do a lot of processing on the request object here so I don’t know if it is possible to do all this without getInitialProps, but maybe with the userRouter hook or the withRouter hoc.

Eliminating getInitialProps is a much bigger undertaking than I thought when I opened this issue and I am probably not going to contribute a PR for this feature in the near future.

Feel free to close this issue if you like, it really isn’t critical but there are performance compromises made when getInitialProps is used and it may be worth leaving the issue open for discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify namespacesRequired without getInitialProps #544
Specifying namespacesRequired is optional, but recommended for performance reasons. Currently, the only way to set namespacesRequired is ...
Read more >
reactjs - Keep having namespacesRequired even if declared
ico but I have one (it appears in the tab). No idea where to look at now... Here is the code of my...
Read more >
getInitialProps - Data Fetching - Next.js
This new directory has support for colocated data fetching at the component level, using the new React use hook and an extended fetch...
Read more >
@kichiyaki/next-i18next - npm package | Snyk
To do that, you need to return a namespacesRequired array via getInitialProps on your page-level component. You can see this approach in ...
Read more >
next-i18next setup in next.js for multi-languages implementation
Must create namespacesRequired (Array) in each Component. ... or defines a getInitialProps if it's a function component (explanation here).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found