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

Root API should clear non-empty roots before mounting #18730

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/react-art/src/ReactARTHostConfig.js
Expand Up @@ -427,12 +427,8 @@ export function unhideTextInstance(textInstance, text): void {
// Noop
}

export function clearContainer(container: Container): void {
// TODO This doesn't work for anything other than SVG.
// Is that okay?
while (container.lastChild != null) {
container.lastChild.eject();
}
export function clearContainer(container) {
// TODO Implement this
}

export function DEPRECATED_mountResponderInstance(
Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Expand Up @@ -636,11 +636,11 @@ export function unhideTextInstance(

export function clearContainer(container: Container): void {
if (container.nodeType === ELEMENT_NODE) {
((container: any): Element).innerHTML = '';
((container: any): Element).textContent = '';
} else if (container.nodeType === DOCUMENT_NODE) {
const documentElement = ((container: any): Document).documentElement;
if (documentElement != null) {
documentElement.innerHTML = '';
const body = ((container: any): Document).body;
if (body != null) {
body.textContent = '';
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Expand Up @@ -74,8 +74,7 @@ describe('when Trusted Types are available in global object', () => {
container,
);
expect(container.innerHTML).toBe('<div><b>Hi</b></div>');
// Second call to innerHTML is the clearContainer check.
expect(innerHTMLCalls.length).toBe(2);
expect(innerHTMLCalls.length).toBe(1);
// Ensure it didn't get stringified when passed to a DOM sink:
expect(innerHTMLCalls[0]).toBe(ttObject1);

Expand Down