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

[do not merge]Retain documentElement when appending/removing from Document #24524

Closed
wants to merge 1 commit into from

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented May 9, 2022

creating a root or hydrating into a root with a Document container could error in surprising ways because the document root element was not removed when clearing the container and then a new html element was attempting to be appended to the document. Browsers do not allow more than one root element and this errored leading to a cascading failure where all content was unmounted from the tree breaking the application.

This change changes the behavior of clearContainer, appendChildToContainer, and removeChildFromContainer

clearContainer on a Document container will now remove all children of the documentElement (usually )

appendChildToContainer on a Document container will now 'adopt' the existing documentElement, transferring all stateNode properties and children over to it rather than dirctly appending the child

removeChildFromContainer on a Document container will now remove all children of the documentElement but leave the documentElement in place

Summary

How did you test this change?

creating a root or hydrating into a root with a Document container could error in surprising ways because the document root element was not removed when clearing the container and then a new html element was attempting to be appended to the document. Browsers do not allow more than one root element and this errored leading to a cascading failure where all content was unmounted from the tree breaking the application.

This change changes the behavior of clearContainer, appendChildToContainer, and removeChildFromContainer

clearContainer on a Document container will now remove all children of the documentElement (usually <html>)

appendChildToContainer on a Document container will now 'adopt' the existing documentElement, transferring all stateNode properties and children over to it rather than dirctly appending the child

removeChildFromContainer on a Document container will now remove all children of the documentElement but leave the documentElement in place
@sizebot
Copy link

sizebot commented May 9, 2022

Comparing: 99eef9e...1818f29

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.64% 131.58 kB 132.42 kB +0.89% 42.17 kB 42.55 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.61% 136.82 kB 137.65 kB +0.87% 43.68 kB 44.06 kB
facebook-www/ReactDOM-prod.classic.js +0.46% 440.68 kB 442.71 kB +0.58% 80.33 kB 80.79 kB
facebook-www/ReactDOM-prod.modern.js +0.48% 425.89 kB 427.92 kB +0.61% 78.17 kB 78.64 kB
facebook-www/ReactDOMForked-prod.classic.js +0.46% 440.68 kB 442.71 kB +0.58% 80.33 kB 80.80 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.production.min.js +0.64% 131.56 kB 132.39 kB +0.89% 42.17 kB 42.55 kB
oss-stable/react-dom/cjs/react-dom.production.min.js +0.64% 131.58 kB 132.42 kB +0.89% 42.17 kB 42.55 kB
oss-stable-semver/react-dom/umd/react-dom.production.min.js +0.63% 131.68 kB 132.51 kB +0.87% 42.80 kB 43.17 kB
oss-stable/react-dom/umd/react-dom.production.min.js +0.63% 131.70 kB 132.54 kB +0.88% 42.79 kB 43.17 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.61% 136.82 kB 137.65 kB +0.87% 43.68 kB 44.06 kB
oss-experimental/react-dom/umd/react-dom.production.min.js +0.61% 136.86 kB 137.70 kB +0.91% 44.31 kB 44.72 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.production.min.js +0.60% 140.37 kB 141.21 kB +0.83% 45.25 kB 45.63 kB
oss-stable-semver/react-dom/umd/react-dom.profiling.min.js +0.60% 140.41 kB 141.25 kB +0.92% 45.08 kB 45.49 kB
oss-stable/react-dom/umd/react-dom.profiling.min.js +0.60% 140.44 kB 141.27 kB +0.92% 45.08 kB 45.49 kB
oss-stable-semver/react-dom/cjs/react-dom.profiling.min.js +0.59% 140.98 kB 141.82 kB +0.85% 44.64 kB 45.02 kB
oss-stable/react-dom/cjs/react-dom.profiling.min.js +0.59% 141.01 kB 141.85 kB +0.85% 44.64 kB 45.02 kB
oss-experimental/react-dom/umd/react-dom.profiling.min.js +0.58% 145.60 kB 146.44 kB +0.94% 46.62 kB 47.06 kB
oss-experimental/react-dom/cjs/react-dom.profiling.min.js +0.57% 146.25 kB 147.08 kB +0.87% 46.15 kB 46.55 kB
facebook-www/ReactDOMTesting-prod.modern.js +0.49% 416.84 kB 418.87 kB +0.58% 78.07 kB 78.52 kB
facebook-www/ReactDOM-prod.modern.js +0.48% 425.89 kB 427.92 kB +0.61% 78.17 kB 78.64 kB
facebook-www/ReactDOMForked-prod.modern.js +0.48% 425.89 kB 427.92 kB +0.61% 78.17 kB 78.64 kB
facebook-www/ReactDOMTesting-prod.classic.js +0.47% 432.95 kB 434.98 kB +0.57% 80.52 kB 80.98 kB
facebook-www/ReactDOM-prod.classic.js +0.46% 440.68 kB 442.71 kB +0.58% 80.33 kB 80.79 kB
facebook-www/ReactDOMForked-prod.classic.js +0.46% 440.68 kB 442.71 kB +0.58% 80.33 kB 80.80 kB
facebook-www/ReactDOM-profiling.modern.js +0.45% 456.44 kB 458.47 kB +0.57% 82.69 kB 83.16 kB
facebook-www/ReactDOMForked-profiling.modern.js +0.45% 456.44 kB 458.47 kB +0.57% 82.69 kB 83.16 kB
facebook-www/ReactDOM-profiling.classic.js +0.43% 471.29 kB 473.32 kB +0.55% 84.91 kB 85.38 kB
facebook-www/ReactDOMForked-profiling.classic.js +0.43% 471.29 kB 473.32 kB +0.55% 84.91 kB 85.38 kB
oss-stable-semver/react-dom/umd/react-dom.development.js +0.24% 1,074.16 kB 1,076.75 kB +0.21% 231.98 kB 232.47 kB
oss-stable/react-dom/umd/react-dom.development.js +0.24% 1,074.19 kB 1,076.77 kB +0.21% 232.00 kB 232.49 kB
oss-stable-semver/react-dom/cjs/react-dom.development.js +0.24% 1,023.81 kB 1,026.28 kB +0.22% 229.42 kB 229.92 kB
oss-stable/react-dom/cjs/react-dom.development.js +0.24% 1,023.84 kB 1,026.30 kB +0.22% 229.44 kB 229.95 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.development.js +0.24% 1,035.79 kB 1,038.25 kB +0.21% 233.24 kB 233.74 kB
oss-experimental/react-dom/umd/react-dom.development.js +0.23% 1,104.71 kB 1,107.30 kB +0.21% 238.28 kB 238.78 kB
oss-experimental/react-dom/cjs/react-dom.development.js +0.23% 1,052.95 kB 1,055.41 kB +0.22% 235.68 kB 236.19 kB
facebook-www/ReactDOMTesting-dev.modern.js +0.23% 1,035.12 kB 1,037.50 kB +0.21% 232.86 kB 233.34 kB
facebook-www/ReactDOMTesting-dev.classic.js +0.22% 1,063.75 kB 1,066.12 kB +0.20% 238.52 kB 238.99 kB
facebook-www/ReactDOMForked-dev.modern.js +0.21% 1,130.26 kB 1,132.64 kB +0.19% 249.76 kB 250.24 kB
facebook-www/ReactDOM-dev.modern.js +0.21% 1,130.26 kB 1,132.64 kB +0.19% 249.77 kB 250.25 kB
facebook-www/ReactDOMForked-dev.classic.js +0.21% 1,154.24 kB 1,156.62 kB +0.20% 254.11 kB 254.61 kB
facebook-www/ReactDOM-dev.classic.js +0.21% 1,154.24 kB 1,156.62 kB +0.20% 254.11 kB 254.62 kB

Generated by 🚫 dangerJS against 1818f29

@gnoff
Copy link
Collaborator Author

gnoff commented May 10, 2022

closing in favor of #24523 which is less code and more semantically correct

@gnoff gnoff closed this May 10, 2022
@gnoff gnoff deleted the retain-document-element branch May 10, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants