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.

infinite loop with dynamically nested components

See original GitHub issue

Hi, I’ve got a browser-crashing scenario with some nested components where translate is called on an inner and outer component. I guess it’s some weird edge-case with context handling.

I’ve tried to dumb it down quite a bit:

OuterComponent renders MiddleComponent and passes an anonymous Component that renders InnerComponent with some extra parameter. OuterComponent and InnerComponent are translated.

I’m sorry that this is still so complex, but I couldn’t get this any more simple.

Is this a bug in react-i18next? Is it something in react itself?

import * as React from 'react';
import {translate, Trans} from 'react-i18next';

const InnerComponent = translate()(
    ({name}: { name: string }) => <Trans>some-test</Trans>
);

const MiddleComponent =  ({Component}: { Component: React.ComponentType }) => <div><Component /></div> ;

const OuterComponent = translate()(
    class extends React.Component<any> {
        render() {
            console.log('this loops like crazy...');
            return (
                <div>
                    <MiddleComponent Component={() => <InnerComponent name="qwe"/>}/>
                </div>
            );
        }
    }
);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
jamuhlcommented, Aug 22, 2017

hm…must be some weird timing issue…but honestly no exact idea why

the cache does add resource bundles and cause of that triggers a few times added - as we listen to added and trigger a rerender upon that this might be to much…?!?

could you try setting bindStore to false?

translate('yourNS', { bindStore: false })(OuterComponent)

1reaction
phryneascommented, Aug 28, 2017

Oh, nice. I was still at 4.7.0 which didn’t have that option. Had not noticed that this was getting so many updates 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having to dynamically change the state : how to avoid an ...
It is obvious that right now my code generates an infinite-loop: The component is created and rendered for the first time. During this...
Read more >
C++ - Infinite Loops| Nested Loops - YouTube
00:00 Infinite Loops02:56 Nested LoopsTHANKS FOR WATCHING AND DON'T FORGET TO LIKE, COMMENT, SUBSCRIBE, AND HIT THE BELL ICON TO WATCH THE ...
Read more >
Loops in Ruby - performing repeated operations on a data ...
Loops and iterators in Ruby are a great way to perform repeated operations on a data set. Step by step tutorial for the...
Read more >
For Each...Next Statement - Visual Basic
Syntax; Parts; Simple Example; Nested Loops; Exit For and ... Next statement iterates through all the elements of a List collection.
Read more >
Why is it so difficult to modify a deeply nested state in React?
It's not uncommon to see a code like that in React world. All this effort just to update a single to-do item inside...
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