react icon indicating copy to clipboard operation
react copied to clipboard

[React 19] react-test-renderer deprecation

Open iammerrick opened this issue 9 months ago • 2 comments

Summary

Today our team relies on react-test-renderer to render a JSON tree which is subsequently used for search indexing. By rendering to JSON we have a structure we can use to extract semantic data like title, meta, description, etc. To do something similar without react-test-renderer we'd have to render to HTML, and then use an HTML parser to parse and extract semantic data.

I realize that this is an "off label" use of React Test Renderer but I was hoping there would be an alternative to with react-test-renderer's deprecation.

ReactTestRenderer.create(reactElement).toJSON();

iammerrick avatar Apr 26 '24 16:04 iammerrick

You probably get more reliable results by rendering to HTML with the method you want (server-side rendering, client-side rendering, streaming etc). That HTML can be passed to jsdom and then you also get a more robust query syntax and validation that your meta, title etc tags are valid.

eps1lon avatar Apr 26 '24 16:04 eps1lon

Consider rendering React components to HTML using react-dom/server, making react-test-renderer obsolete. Then, parse the HTML with libraries like cheerio. Remove semantic data such as titles, metas, descriptions, etc. This change retains your ability to index semantic data while accepting depreciation.

yuvarajrece avatar Apr 27 '24 12:04 yuvarajrece

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Jul 26 '24 13:07 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Aug 02 '24 13:08 github-actions[bot]