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

Bug: JSX string interpolation throws erroneous error on hydrateRoot #25959

Closed
dickie81 opened this issue Jan 3, 2023 · 2 comments
Closed

Bug: JSX string interpolation throws erroneous error on hydrateRoot #25959

dickie81 opened this issue Jan 3, 2023 · 2 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@dickie81
Copy link

dickie81 commented Jan 3, 2023

hydrateRoot seems to have issues with jsx string interpolation. hydrateRoot seems to see the the inline string as separate on the client and can't match the unbroken string rendered by the server.

react-dom.development.js:73 Warning: Text content did not match. Server: "Jaguar shark!" Client: "Jaguar " at p at App1
react-dom.development.js:73 Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.

React version: 18.2.0

Steps To Reproduce

This is the simplest example I could muster, obviously I would not normally write JSX in this fashion but it illustrates the issue.

HTML:

<div id="root"><p>Jaguar shark!</p></div>

JS:

const App = () => (<p>Jaguar {'shark!'}</p>);

ReactDOM.hydrateRoot(document.getElementById("root"), <App />, {
  onRecoverableError: (err) => {
    alert('error found: ' + err);
  }
});

Link to code example:
https://codepen.io/Dickie81/pen/xxJVwmp

The current behavior

Throws error. Re-renders dom.

The expected behavior

hydrates without complaint

@dickie81 dickie81 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jan 3, 2023
@nmain
Copy link

nmain commented Jan 3, 2023

How did you get that HTML? It doesn't seem to match what React generates serverside:

const React = require("react");
const ReactDOMServer = require("react-dom/server");
const App = () => (<p>Jaguar {'shark!'}</p>)
ReactDOMServer.renderToString(<App />);
<p>Jaguar <!-- -->shark!</p>

@dickie81
Copy link
Author

dickie81 commented Jan 3, 2023

@nmain great point - it seems something is stripping comments on our implementation. Thanks for pointing out the obvious mistake!

@dickie81 dickie81 closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants