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 REACT components in translation strings should not attempt to replace the component's children #1815

Open
simkentys opened this issue Nov 28, 2024 · 1 comment

Comments

@simkentys
Copy link

simkentys commented Nov 28, 2024

🐛 Bug Report

When using React components with children to replace self closing tags in translations, the children of react component is replaced.
Probably continuation of this issue: #1695

To Reproduce

https://stackblitz.com/edit/vitejs-vite-f6qrql?file=package.json,src%2Fmain.tsx%3AL41&terminal=dev

i18n.use(initReactI18next).init({
  interpolation: {
    escapeValue: false,
  },
});

function Link({ href, children }) {
  return <a href={href}>{children}</a>;
}

createRoot(document.getElementById('root')!).render(
  <>
      <Link href="#">linkTo</Link>
      <Trans
        i18nKey="<Component />"
        components={{ Component: <Link href="#">linkTo</Link> }}
      />
      <Trans
        i18nKey="<Component />"
        components={{ Component: <a href="#">linkTo</a> }}
      />
  </>
);

expected result:

<a href="#">linkTo</a>
<a href="#">linkTo</a>
<a href="#">linkTo</a>

actual result:

<a href="#">linkTo</a>
<a href="#"></a>
<a href="#">linkTo</a>

Expected behavior

React component children would be preserved

Your Environment

"i18next": "^24.0.2",
"react-i18next": "^15.1.2"

@adrai
Copy link
Member

adrai commented Nov 28, 2024

Feel free to provide a PR to address this.

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