-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Context is broken with react-tree-walker #54
Comments
This might be stupid idea, but can we just traverse the tree until the first occurrence of |
No, that's not what we'll do. Older versions of this project, which existed only as "examples" in the There are many cases where a tree's deps could change:
Wherein two very different trees with different deps can be rendered, and the parent shouldn't have to declare all namespaces for both possible renders. |
Ideally I'd like to traverse the tree without rendering, but I'm not sure if such a thing is even possible. |
My intuition suggests that something similar to Apollo's Using an equivalent of |
This is my thoughts on this issue. |
In case of someone wonders: Redux wasn't working with Note: I'm posting it anyway. I saw the same suggestion from @isaachinman after I checked the changelog. |
@isaachinman I've just read what you commented. It's true that using 0.9.0 there's no problem. Take the time you need to fix it. Thank you for your rapid response and your patience. |
That's probably a very expensive compromise to make. When I was using react-intl, the main reason for me to switch to I understand that requiring to list all namespaces in the top-level |
This again misses the point... Having to declare namespaces explicitly is not something I want to force users to do. It will be a pain to maintain, and as shown in examples above, there are many cases where you'd end up loading namespaces you don't even need.
It's JSON, not JavaScript, and it does not need to be executed. It is not my intention to have this package send down all translations - I really want to support "code splitting" for namespaces. That being said, I have built small projects where all namespaces are sent down initially. It's a fine approach if you understand what you're doing.
It is my opinion that we need a robust solution in the core source code here, not bandaid tooling. I am still actively thinking about how we can fix this problem. I have a hunch it's possible without tree walking, but it's an extremely tricky problem and will take time. Thank you everyone for your patience. |
I've created a branch called namespace-dep-order-of-execution. If you clone it and do Basically - the data we need is "there" and ready to be consumed, I just have no idea how. It would be great if we could relate this namespace data from within the initial
Either way would allow us to save the namespaces as Assuming each unique URL always has the same namespace dependencies (I don't see how it couldn't, but please tell me if your use case is different), we could end up saving a cache-map of deps:
Otherwise, if there is such a thing as a NextJs request ID, we would simply create the deps on an object, and then clean up that request ID once it's been served. So, I need help making that link between |
From your own recent comment:
|
Yup. Given the choice between:
What does everyone want? If we're not going to proceed with tree walking, there's no point trying to fix these context issues. |
After having a think about it, I am going to end up asking users to define required namespaces on the page level after all. Unfortunately it seems like any other solution is going to make life unpredictable/buggy for end users, and extremely difficult for maintainers. Most likely I'll be expecting users to return a Changes incoming today. |
What if a modified version of Sending down all namespaces if some condition is not met does not solve the problem, it simply hides it. It may seem that this "default" mode can protect a newcomer from some extra cognitive load, but in fact it will make things more complex. Rather than learning a simple rule (i.e. include all namespaces in a top-level |
This is how the old example used to work, and is not something I want to do. A HOC should do one thing - they're already hard enough to reason about. The
No. It uncontroversially does solve the problem of SSR localisation. Sending down all namespaces with the initial request is not inherently bad. Doing full network roundtrips for a 5kb JSON file isn't inherently good. It will all depend on your use case. This approach gives users the option to "code split" their translations based on route if they feel it's appropriate, but prevents things from being broken out of the box. |
Having a SSoT for the different settings, on a per-app basis really should be a given and therefore it makes sense to have a file that dictates which combintations of namespaces are used. For context: I'm implementing i18n, material-ui, Apollo and GA at the same time, my plan is to eventually make it OSS as a full-stack 'starter kit', as it's coupled with a local Prisma backend and I've created a whole CLI around it all. My point is, that basically everything works, with configurability and I'd love to have to explicitly give my settings or have (documented) defaults be the default. Otherwise I'll have to go back to own implementation for full flexibility for everybody. The issue got closed as i was writing this, I'm glad I didn't have to argue but would still like to post an opinion. |
@MathiasKandelborg Thanks for adding your opinion here. Although, I didn't really understand it... You're saying you are in support of declaring User opinions are very much appreciated, and in fact influence the direction of this project as it's still quite young and there are some core issues to iron out. |
I'm sorry for being unclear, I deleted some of the text, as the issue got closed, as it would be empty arguments. I tried cutting it down to the relevant parts but I'm notorious for not being particularly explicit. Yes, I'm in favor of using Basically, my thoughts are: in order to accommodate as many as possible... one of the best approaches I've encountered has been to:
E.g. in dev-mode I'd like to always get notified if no |
|
@isaachinman that's a useful addition, thanks! Also WDYT of warning users of missing namespaces when they've defined too few? At the moment, when a required namespace is missed, the page will flash, but it won't be clear why. A warning can be added when i18next renders things on the client for the first time (or within ≈1-5 seconds) and notices a need to fetch more namespaces. Of course, this can be a dev-only feature too. |
@kachkaev That's a more complicated proposal, because we'd need to hook into |
Thanks @isaachinman for this direction. I love this very much, as it's very easy to integrate i18n to any existing Next.JS project without breaking anything. Because it's just |
Oh, I just thought of something! Opt-out of the message, "some people like to see the world burn and hate to get reminded to get a fire extinguisher all the time". It would be great to turn off the messages via a boolean setting. This would enable the exact dev experience one would like. Anyways, Opt-out seems like a good solution to this problem none has had yet. |
@MathiasKandelborg Feel free to open an issue with a feature request. If anything, I'd want to start a "strict mode" where we throw errors and warnings, and it's "all or nothing". I don't want to start putting flags for every single thing. |
Hmm, I'll see if I'm able to find some time to contribute (and can figure things out haha). This is a core feature of my own work and I'd love to help if possible. I'll be sure to add a feature request no matter what, I'm just on my way out atm so it's first due later/tomorrow. The strict mode seems like a great thing to have. I personally always go all-in on safeguarding everything I do (besides tests because I'm lazy and do crazy combinations with my code, Like apollo+mui+i18n+formik which seems daunting to test, also, most is tested anyways). I love to learn how tech works while using it and coding with a strict mode on, often helps with proper understanding and lots of times even requires reading up on how things should work together. Being able to do this with i18n would be great! |
If you open an issue, I can point you in the right direction. It'll just be a matter of adding a new bool to the config, and then protecting the |
Creating this issue so that we have one place to discuss potential solutions.
I recently added
react-tree-walker
to this package so that we can traverse React component trees to determine the exact namespaces required to render that tree correctly. This allows us to do SSR in the most efficient way possible.However, it seems that there are several context-related issues with
react-tree-walker
:app-with-translation
HOC.Instead of going down this road, I would really prefer if we can come up with a different way to do tree traversal that does not depend upon context. All we need to do is traverse a tree, checking for
props.ns
. Ifprops.ns
exists, we need to add it to an array. That's it.Does anyone have any good ideas?
Otherwise, we'll probably need to revert to sending down all namespaces to the client. This is not ideal, especially for (very) large apps.
The text was updated successfully, but these errors were encountered: