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.

I18nProvider remounts all the children, but not rerender

See original GitHub issue

Describe the bug I18nProvider implementation has a very unpleasant effect of changing own key when locale changes. It declares, that forceRenderOnLocaleChange force rerender of all children. Sorry, but its not a rerender, it’s full remount of it’s children. As a result React.memo is killed and state of all the components is reset. I have google map inside and its remount is slow and flickering

To Reproduce

export default function App() {
   return <I18nProvider i18n={i18n}><PureComponentWithReactMemo></I18nProvider>
}

Expected behavior It would be great to have all the components just rerendered, not remounted. It is usually done with a trick like having state with counter and incrementing it by one every time we need children to be rerendered.

I cannot have a single global I18nProvider as it remounts everything inside, the heavy components like maps are remounted with unpleasant flicker.

Additional context

  • jsLingui version 3.11.1
  • Babel version - not related

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sakulstracommented, Feb 11, 2022

Was just running into this as well. I feel like having this behavior as a default is a weird choice.

probably just stupidity on my side: Didn’t realize the remount for quite some time and now have to refactor every use of t which is sad. Would have rather notices it earlier 😅

1reaction
JSteunoucommented, Dec 9, 2021

plzzz stale bot 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Parent component re-renders all children, even those ...
If a parent component is updated, does React always update all the direct children within that component? No. React will only re-render a ......
Read more >
Avoiding React component re-renders with React.memo
A component can re-render even if its props don't change. More often than not this is due to a parent component re-rendering causing...
Read more >
"mount" vs "render"? - React Training
A "re-render" is when React calls the function component again to get a new set of instructions on an already mounted component.
Read more >
How I eliminate ALL unnecessary Rerenders in React - Medium
As we all know, React recomputes and rerenders all components, every time their states change. That also applies if the component is dependent...
Read more >
Avoid unnecessary remounting of DOM elements in React
3 <Child id={2}/>. 4</Container>. I expected React to not unmount and then remount the two DOM nodes corresponding to the two buttons when ......
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