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

Support document rendering #24523

Merged
merged 2 commits into from May 10, 2022
Merged

Commits on May 9, 2022

  1. Support Document as a container for hydration and rendering

    Previously Document was not handled effectively as a container. in particual when hydrating if there was a fallback to client rendering React would attempt to append a new <html> element into the document before clearing out the existing one which errored leaving the application in brokent state.
    
    The initial approach I took was to recycle the documentElement and never remove or append it, always just moving it to the right fiber and appending the right children (heady/body) as needed. However in testing a simple approach in modern browsers it seems like treating the documentElement like any other element works fine. This change modifies the clearContainer method to remove the documentElement if the container is a DOCUMENT_NODE. Once the container is cleared React can append a new documentElement via normal means.
    gnoff committed May 9, 2022
    Copy the full SHA
    fd06131 View commit details
    Browse the repository at this point in the history
  2. Allow Document as container for createRoot

    previously rendering into Document was broken and only hydration worked because React did not properly deal with the documentElement and would error in a broken state if used that way. With the previous commit addressing this limitation this change re-adds Document as a valid container for createRoot.
    
    It should be noted that if you use document with createRoot it will drop anything a 3rd party scripts adds the page before rendering for the first time.
    gnoff committed May 9, 2022
    Copy the full SHA
    0215c83 View commit details
    Browse the repository at this point in the history