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

MenuItem Component should wrap text content in span #7140

Open
donghee214 opened this issue Jan 6, 2025 · 0 comments
Open

MenuItem Component should wrap text content in span #7140

donghee214 opened this issue Jan 6, 2025 · 0 comments

Comments

@donghee214
Copy link
Contributor

donghee214 commented Jan 6, 2025

Realistically this will be very difficult to fix, mostly for tracking purposes.

Currently React and Google translate does not play nice where google translate will mutate the DOM to a state where it will be inconsistent to Reacts view of the world.

original
<div>無選択</div>

translated:
<div>
  <font style="vertical-align: inherit;">
    <font style="vertical-align: inherit;">No choice</font>
  </font>
</div>

React will reference the text node in its virtual DOM (not the div) which no longer exists after browser translation is ran. For conditionally rendered components this is an issue because when React goes to call parent.removeChild(textNode) in the event the component is to be unrendered, textNode no longer exists in the real DOM which throws Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

The workaround provided on the ticket suggested wrapping all textNodes in a span such that React will still reference the span even when the contents inside the span are replaced with font, allowing it to still maintain the same reference between virtual and real DOM.

So far just identified MenuItem rendering textNodes but basically any component using TextNode will have this issue

TextNode defaults to div: https://github.com/palantir/blueprint/blob/develop/packages/core/src/components/menu/menuItem.tsx#L270

React Issue: facebook/react#11538

@donghee214 donghee214 changed the title MenuItem Component should wrap text content in <span></span> MenuItem Component should wrap text content in span Jan 6, 2025
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

1 participant