-
-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser bundle includes namespaces that are unrelated to a given page #40
Comments
Yes, I noticed this bug awhile back but haven't gotten around to it. Simply put, Worth noting that you store you were receiving on |
Thanks for a very quick fix @isaachinman 🎉 Would you be happy to release some new version so that I could give it a try? This can be I wish I could just run your lib from |
@kachkaev It would be fantastic if you could write some test cases to help this project develop and release quicker. I am nervous to release some of the recent changes without a proper second opinion. |
See #18. |
It's the end of the weekend and I'm running out of time to go for anything new, unfortunately 😪 I can help a bit with the tests next weekend if things go as planned. I would not worry too much about breaking things at such an early stage of the library lifecycle, especially when it comes to releasing alpha versions. Iteration over perfection 😉 |
It's not about perfection, but rather critical breaks. I'd rather not scare off new users. That would be very helpful if you do have time next weekend! |
This approach is not going to work. In fact, the approach is fatally flawed to begin with - |
We need a way of to store each used namespace in a request-specific manner, and then load each namespace into the Need to think on this, not sure yet how it will be possible. |
using the req.i18n instance in that case https://github.com/isaachinman/next-i18next/blob/master/src/hocs/with-namespaces.js#L4 would solve it - as that instance is created per request |
Hi @jamuhl - yes of course The hard part is: how do we append an array onto I cannot think of a way to do this, yet. It might be the case that the only reliable way to get the used namespaces for a React tree is to force a |
Not sure but if remember it right the past sample had that built-in... |
Anyway i'm sure you come up with an elegant solution |
The past sample was broken in exactly the same way described here, because it took the same approach. I appreciate your confidence! This one will be tricky. |
Not sure but you got req.i18n there https://github.com/isaachinman/next-i18next/blob/master/src/hocs/app-with-translation.js#L57 And only issue is: not passing that here: https://github.com/isaachinman/next-i18next/blob/master/src/hocs/app-with-translation.js#L94 my guess would be initialProps handled so props.i18n would be req.i18n if set here: https://github.com/isaachinman/next-i18next/blob/master/src/hocs/app-with-translation.js#L78 but might be i understand it wrong and initialProps runs only on clientside.... |
Spent over an hour looking into this and didn't really get anywhere. Finally caved in and asked for help. Hopefully @timneutkens is aware of something I haven't found - this might not even be specific to NextJs... |
So far I've gotten as far as this: const reactTree = (
<I18nextProvider
i18n={i18n}
initialLanguage={initialLanguage}
initialI18nStore={initialI18nStore}
>
<NextStaticProvider>
<Component {...this.props} />
</NextStaticProvider>
</I18nextProvider>
)
const nsFromTree = []
const recurseTree = (component) => {
if (component.type && component.type.namespaces) {
nsFromTree.push(component.type.namespaces)
}
if (component.props && component.props.children) {
recurseTree(component.props.children)
}
}
recurseTree(reactTree) This works, but only seems to go one level deep (in the example stopping at @jamuhl @timneutkens Any ideas? |
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 Now that we have the 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 |
@kachkaev Would you mind doing some quick testing to ensure that this solution does indeed solve the original problem. We're coming ever closer to a production-ready release. |
Released in v0.10.0. |
Many thanks for looking into this @isaachinman! I'll try testing your changes but unfortunately can't promise to do this before the weekend. One closed-project in which I'm trying BTW is |
Just printing a timestamp before and after executing. Do you have any large Please open a bug issue for the |
I don't have an opportunity to check If you are registered on GitLab, I can temporary invite you into a private project – just drop me an email with your login. My open-sourced mini-website also uses |
I could not kick off my mini-website after upgrading from 0.8 to 0.10, unfortunately. Here's the terminal output during SSR:
Changes I've made: https://gitlab.com/kachkaev/website-frontend/merge_requests/6/diffs All is fine on master 🤔 |
You should be importing the default export, not |
That's what I was successfully doing in 0.8.0. In 0.10.0,
|
If I understand things correctly, CodeSandbox is client-side only. In my case, the exception is raised on the server. This may be to do with babel-plugin-add-module-exports introduced in da40a3e#diff-e56633f72ecc521128b3db6586074d2cR16 – I can't think of anything else that could contribute to this new error I witness 🤔 |
Without exports.default = NextI18Next; With exports.default = NextI18Next;
module.exports = exports.default; It's additive, not a replacement. If you believe this is the issue, please test by simply removing |
Again: please open a new issue for each new topic, instead of adding unrelated discussion to other issues. |
The thing is that before we got into discussing When I was trying I really appreciate what you're doing @isaachinman I'm happy to help as I see the potential value |
If your problem is with v0.9.0, it is not related to this issue. This is an open source project. If you find a bug or problem, you should:
I don't see what that error stack has to do with 2386bf2, you're going to need to explain that if you want to be understood. |
Usage of If you think there's a problem with usage of If you think there's a problem with the export syntax, open an issue. If you think there's a problem with the tree-walking implementation that attempts to fix the namespace dep problem, this is the appropriate place to discuss it. Any other topics are not appropriate for discussion. @kachkaev I also appreciate your enthusiastic interest in the project, but value is generated via concise bug reports or feature requests, and above all else, PRs. |
I don't remember reporting an issue with Trans in 0.8.0, the comment you point to does not state that. Here are the latest tests for After upgrading 0.8.0 to 0.9.0 (next-i18next diff): no exception, even for After 0.9.0 → 0.10.0 (next-i18next diff):
After 0.10.0 → 0.10.2 (next-i18next diff): no exception, but no data in Was there some bug in 0.10.0 that is related to your fix of this issue, rather than
|
Let's continue discussion in #54. |
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 ofinitialI18nStore
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 triednext-i18next
, but switching to it also meant for me the upgrading ofi18next
.Steps to reproduce
Worked both for 0.8.0 and the latest master)
cd example; yarn; yarn dev;
initialI18nStore
includes{"en": {"common": ..., "footer": ...}}
initialI18nStore
includes{"en": {"common": ..., "footer": ..., "second-page": ...}}
Expected content:
{"en": {"common": ..., "footer": ...}}
The text was updated successfully, but these errors were encountered: