Skip to content

Commit f45a8a1

Browse files
author
Brian Vaughn
committed
Clear body instead of document; use textContent instead of innerHTML
1 parent 39b2042 commit f45a8a1

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,8 @@ export function unhideTextInstance(textInstance, text): void {
427427
// Noop
428428
}
429429

430-
export function clearContainer(container: Container): void {
431-
// TODO This doesn't work for anything other than SVG.
432-
// Is that okay?
433-
while (container.lastChild != null) {
434-
container.lastChild.eject();
435-
}
430+
export function clearContainer(container) {
431+
// TODO Implement this
436432
}
437433

438434
export function DEPRECATED_mountResponderInstance(

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,11 @@ export function unhideTextInstance(
636636

637637
export function clearContainer(container: Container): void {
638638
if (container.nodeType === ELEMENT_NODE) {
639-
((container: any): Element).innerHTML = '';
639+
((container: any): Element).textContent = '';
640640
} else if (container.nodeType === DOCUMENT_NODE) {
641-
const documentElement = ((container: any): Document).documentElement;
642-
if (documentElement != null) {
643-
documentElement.innerHTML = '';
641+
const body = ((container: any): Document).body;
642+
if (body != null) {
643+
body.textContent = '';
644644
}
645645
}
646646
}

packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ describe('when Trusted Types are available in global object', () => {
7474
container,
7575
);
7676
expect(container.innerHTML).toBe('<div><b>Hi</b></div>');
77-
// Second call to innerHTML is the clearContainer check.
78-
expect(innerHTMLCalls.length).toBe(2);
77+
expect(innerHTMLCalls.length).toBe(1);
7978
// Ensure it didn't get stringified when passed to a DOM sink:
8079
expect(innerHTMLCalls[0]).toBe(ttObject1);
8180

0 commit comments

Comments
 (0)