Skip to content

fix: skip dangerouslySetInnerHtml hydration warning if it's undefined #18676

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

Merged
merged 6 commits into from
Apr 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: Add smaller test for innerHTML=string to innerHTML=undefined
  • Loading branch information
eps1lon committed Apr 20, 2020
commit 5c058570309bb8e595a3713b5f6314173d9eed32
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ describe('ReactDOMServerHydration', () => {
expect(domElement.innerHTML).toEqual(markup);
});

it('should warns if innerHTML mismatches with dangerouslySetInnerHTML=undefined on the client', () => {
it('should warn if innerHTML mismatches with dangerouslySetInnerHTML=undefined and children on the client', () => {
const domElement = document.createElement('div');
const markup = ReactDOMServer.renderToStaticMarkup(
<div dangerouslySetInnerHTML={{__html: '<p>server</p>'}} />,
Expand All @@ -585,4 +585,20 @@ describe('ReactDOMServerHydration', () => {
'Warning: Text content did not match. Server: "server" Client: "client"',
);
});

it('should warn if innerHTML mismatches with dangerouslySetInnerHTML=undefined on the client', () => {
const domElement = document.createElement('div');
const markup = ReactDOMServer.renderToStaticMarkup(
<div dangerouslySetInnerHTML={{__html: '<p>server</p>'}} />,
);
domElement.innerHTML = markup;

expect(() => {
ReactDOM.hydrate(<div dangerouslySetInnerHTML={undefined} />, domElement);

expect(domElement.innerHTML).not.toEqual(markup);
}).toErrorDev(
'Warning: Did not expect server HTML to contain a <p> in <div>',
);
});
});