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.

Browser bundle includes namespaces that are unrelated to a given page

See original GitHub issue

Not sure if it’s an upstream bug or not, but I’ve noticed that the size of initialI18nStore grows as the website is warming up. Opening any page for the first time adds dependent namespaces to the source of all other pages viewed later. If a website consists of quite a few pages, the overall size of initialI18nStore can grow rather big and thus diminish the benefits of splitting translations into files. I’m quite sure that my projects did not suffer from this problem before I tried next-i18next, but switching to it also meant for me the upgrading of i18next.

Steps to reproduce

Worked both for 0.8.0 and the latest master)

  1. cd example; yarn; yarn dev;
  2. Open http://localhost:3000/
  3. View page source, observe that initialI18nStore includes
    {"en": {"common": ..., "footer": ...}}
  4. Go to http://localhost:3000/second-page and refresh the page (so that it got server-rendered)
  5. Return to http://localhost:3000/, refresh the page again
  6. View page source, observe that initialI18nStore includes
    {"en": {"common": ..., "footer": ..., "second-page": ...}}
    Expected content:
    {"en": {"common": ..., "footer": ...}}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:34 (34 by maintainers)

github_iconTop GitHub Comments

1reaction
isaachinmancommented, Dec 14, 2018

Let’s continue discussion in #54.

1reaction
isaachinmancommented, Dec 12, 2018

Happy to report that I think I’ve found a much more sane, workable solution.

Fix comes with 2386bf2.

I finally stumbled across react-tree-walker, which seems to be well-written, well-maintained, and an absolute godsend for our use case here.

Instead of creating a modified withNamespaces HOC and trying to keep track of a component tree’s namespace deps there (which is an inherently fraught idea), we will walk the component tree inside getInitialProps, as this will be request-specific, and we’re provided with the page-level Component inside the first argument object, thanks to NextJs.

Now that we have the initialLanguage and can walk a component tree based on a specific request, we can reliably produce exactly the initialI18nStore required to render that specific request - nothing more and nothing less.

Performance is obviously the biggest concern here. During prod SSR of the example, I’m seeing walk times of 3ms, which isn’t great considering how simple a tree it is.

Hopefully in the future, a method will solving this problem will come to my attention that completely avoids the issue of re-walking/re-rendering the tree. Until now, I am quite happy with this solution.

Another added benefit is that we no longer need to maintain a custom withNamespaces HOC, and can simply re-export directly from react-i18next.

Read more comments on GitHub >

github_iconTop Results From Across the Web

i18next-express-middleware should not be included ... - GitHub
I noticed that the size of my app's client bundle soared after switching to next-i18next from a custom react-i18next integration.
Read more >
Introduction to Kubernetes Namespaces | SUSE Communities
Kubernetes clusters can manage large numbers of unrelated workloads concurrently ... Different namespaces can be given different policies.
Read more >
Getting "type or namespace name could not be found" but ...
The problem I faced was that I created a new solution, that I added a different version of a Nuget package, than others...
Read more >
ASP.NET Core breaking changes | Microsoft Learn
Lists the breaking changes in ASP.NET Core 3.0 and 3.1.
Read more >
Configure Namespaces - API Gateway - TechDocs
are unrelated to those found in the namespace map of XPath-based assertions, even if they may happen to be identical.
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