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

Transfer head/body over if appending an HTML document #22876

Closed
wants to merge 3 commits into from

Conversation

salazarm
Copy link
Contributor

@salazarm salazarm commented Dec 7, 2021

Summary

This fixes #22833 by making appending an HTML document instead copy over the attributes of HTML, Head, and Body (preserving the original HTML/Head/Body elements) and then setting the innerHTML of Body/Head.

This stops us from running into Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed while trying to client render a full page into document.

How did you test this change?

Added a jest test

Confirmed issue #22833 is fixed: https://codesandbox.io/s/react-18-hydration-mismatch-in-document-forked-spxnt?file=/src/App.js

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 7, 2021
@sizebot
Copy link

sizebot commented Dec 7, 2021

Comparing: c7917fe...eb9a4c6

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js +0.47% 129.89 kB 130.50 kB +0.50% 41.62 kB 41.83 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.46% 134.64 kB 135.26 kB +0.55% 43.00 kB 43.24 kB
facebook-www/ReactDOM-prod.classic.js +0.38% 428.08 kB 429.70 kB +0.47% 78.60 kB 78.97 kB
facebook-www/ReactDOM-prod.modern.js +0.39% 416.64 kB 418.26 kB +0.52% 76.91 kB 77.31 kB
facebook-www/ReactDOMForked-prod.classic.js +0.38% 428.08 kB 429.70 kB +0.47% 78.60 kB 78.97 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-dom/cjs/react-dom-testing.production.min.js +0.49% 124.73 kB 125.34 kB +0.49% 39.99 kB 40.19 kB
oss-stable/react-dom/cjs/react-dom-testing.production.min.js +0.49% 124.73 kB 125.34 kB +0.49% 39.99 kB 40.19 kB
oss-stable-semver/react-dom/umd/react-dom.production.min.js +0.47% 130.01 kB 130.63 kB +0.46% 42.34 kB 42.54 kB
oss-stable/react-dom/umd/react-dom.production.min.js +0.47% 130.01 kB 130.63 kB +0.46% 42.34 kB 42.54 kB
oss-stable-semver/react-dom/cjs/react-dom.production.min.js +0.47% 129.89 kB 130.50 kB +0.50% 41.62 kB 41.83 kB
oss-stable/react-dom/cjs/react-dom.production.min.js +0.47% 129.89 kB 130.50 kB +0.50% 41.62 kB 41.83 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.46% 134.64 kB 135.26 kB +0.55% 43.00 kB 43.24 kB
oss-experimental/react-dom/umd/react-dom.production.min.js +0.46% 134.69 kB 135.30 kB +0.42% 43.65 kB 43.84 kB
oss-experimental/react-dom/cjs/react-dom-testing.production.min.js +0.45% 135.51 kB 136.13 kB +0.55% 43.73 kB 43.97 kB
oss-stable-semver/react-dom/umd/react-dom.profiling.min.js +0.44% 138.96 kB 139.57 kB +0.46% 45.07 kB 45.27 kB
oss-stable/react-dom/umd/react-dom.profiling.min.js +0.44% 138.96 kB 139.57 kB +0.46% 45.07 kB 45.27 kB
oss-stable-semver/react-dom/cjs/react-dom.profiling.min.js +0.44% 139.46 kB 140.08 kB +0.56% 44.47 kB 44.72 kB
oss-stable/react-dom/cjs/react-dom.profiling.min.js +0.44% 139.46 kB 140.08 kB +0.56% 44.47 kB 44.72 kB
oss-experimental/react-dom/umd/react-dom.profiling.min.js +0.43% 143.63 kB 144.25 kB +0.51% 46.39 kB 46.62 kB
oss-experimental/react-dom/cjs/react-dom.profiling.min.js +0.43% 144.24 kB 144.85 kB +0.56% 45.86 kB 46.11 kB
facebook-www/ReactDOMTesting-prod.modern.js +0.40% 406.53 kB 408.15 kB +0.51% 76.75 kB 77.15 kB
facebook-www/ReactDOM-prod.modern.js +0.39% 416.64 kB 418.26 kB +0.52% 76.91 kB 77.31 kB
facebook-www/ReactDOMForked-prod.modern.js +0.39% 416.64 kB 418.26 kB +0.52% 76.91 kB 77.31 kB
facebook-www/ReactDOMTesting-prod.classic.js +0.38% 419.91 kB 421.53 kB +0.47% 78.87 kB 79.24 kB
facebook-www/ReactDOM-prod.classic.js +0.38% 428.08 kB 429.70 kB +0.47% 78.60 kB 78.97 kB
facebook-www/ReactDOMForked-prod.classic.js +0.38% 428.08 kB 429.70 kB +0.47% 78.60 kB 78.97 kB
facebook-www/ReactDOM-profiling.modern.js +0.36% 448.47 kB 450.09 kB +0.49% 82.35 kB 82.75 kB
facebook-www/ReactDOMForked-profiling.modern.js +0.36% 448.47 kB 450.09 kB +0.49% 82.35 kB 82.75 kB
facebook-www/ReactDOM-profiling.classic.js +0.35% 459.96 kB 461.58 kB +0.42% 84.06 kB 84.41 kB
facebook-www/ReactDOMForked-profiling.classic.js +0.35% 459.96 kB 461.58 kB +0.42% 84.06 kB 84.41 kB

Generated by 🚫 dangerJS against eb9a4c6

@@ -465,7 +465,49 @@ export function appendChild(
parentInstance: Instance,
child: Instance | TextInstance,
): void {
parentInstance.appendChild(child);
const isDocumentParentNode = parentInstance.nodeType === DOCUMENT_NODE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing an extremely hot path and might break a bunch of optimisations. We need to be very careful about this.

@@ -465,7 +465,49 @@ export function appendChild(
parentInstance: Instance,
child: Instance | TextInstance,
): void {
parentInstance.appendChild(child);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the hottest functions in React since it’s for every insertion for every node. It’s also typically inlined. It’s not the right trade off to put it here so we’ll need a different strategy.

@salazarm salazarm closed this Dec 7, 2021
@salazarm salazarm deleted the specialCaseHTMLBodyHead branch February 10, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React 18: Non-recoverable hydration mismatch if mismatch occurs in the same boundary as main script
5 participants