Specify namespacesRequired without getInitialProps
See original GitHub issueSpecifying 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:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
I didn’t realize
appWithTranslation
adds agetInitialProps
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 withoutgetInitialProps
, but maybe with theuserRouter
hook or thewithRouter
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.