Incompatibility with React
-
Hey TranslatePress-Team!
More and more plugins are using modern development approaches and frameworks / libraries like React to develop components to their frontend. So, we do also for our plugin “Real Cookie Banner”. Unfortunately, the translation editor of TranslatePress is not fully compatible with React (or the
MutationObserver
).How to reproduce?
1. Create a new Gutenberg page
2. Create a “Custom HTML” block
3. Insert the following code into the custom HTML block: https://gist.github.com/matzeeable/5ee88ffbb052720b3f35ea6ac3befc49#file-gutenberg-custom-html-block-html
4. If needed and a console error likeReact is undefined
comes up,wp_enqueue_script('react')
React within yourfunctions.php
so React and React DOM gets loaded on your frontendAfterwards, open the translation editor, and you will see, that you cannot change the text of the React component: https://i.imgur.com/Kb6FLZo.png
Potential solutions
1. Make the
MutationObserver
work for React components
2. Provide aReact
component, so we can wrap our texts in translatable strings:<TranslatePressText>{text}</TranslatePressText>
What do you think?
- The topic ‘Incompatibility with React’ is closed to new replies.