Skip to content
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

Self-closing components in translation strings should not attempt to replace the component's children #1695

Closed
bgmort opened this issue Nov 15, 2023 · 2 comments

Comments

@bgmort
Copy link

bgmort commented Nov 15, 2023

🐛 Bug Report

This could be viewed as a bug or an improvement, but either way – I found an unexpected behavior that feels buggy to me. When interpolating a component with children, the children are replaced by the children from the translation, even when the component in the translation string is self-closing.

To Reproduce

Full example: https://codesandbox.io/p/sandbox/react-i18next-trans-component-interpolation-rf646l?file=%2Fsrc%2FApp.js%3A35%2C1-36%2C1

The gist:

<Trans i18nKey="key"
  defaults="interpolated <component/>"
  components={{
    component: <div style={style}>This component will be replaced</div>,
  }}
/>

Expected behavior

interpolated component's children should be preserved in the final translation

Your Environment

  • runtime version: Chrome 119
  • react-i18next version: 13.4.1
  • i18next version: 23.7.6
  • react version: 18.2.0
  • os: Mac
adrai added a commit that referenced this issue Nov 15, 2023
@adrai
Copy link
Member

adrai commented Nov 15, 2023

Can you try with v13.5.0?

@bgmort
Copy link
Author

bgmort commented Nov 15, 2023

Thanks for the quick response! 13.5.0 works in the codesandbox. I'll update my codebase.

@adrai adrai closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants