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

[React 19] react-test-renderer deprecation #28928

Open
iammerrick opened this issue Apr 26, 2024 · 2 comments
Open

[React 19] react-test-renderer deprecation #28928

iammerrick opened this issue Apr 26, 2024 · 2 comments
Labels

Comments

@iammerrick
Copy link
Contributor

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();
@eps1lon
Copy link
Collaborator

eps1lon commented Apr 26, 2024

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.

@yuvarajrece
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants