Skip to content

Commit

Permalink
Clear body instead of document; use textContent instead of innerHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Apr 28, 2020
1 parent 39b2042 commit f45a8a1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
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 = '';
}
}
}
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

0 comments on commit f45a8a1

Please sign in to comment.