From d763ead692553890643ad59f5a0fe90c5f534459 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 13 Feb 2022 15:48:53 -0500 Subject: [PATCH] Use `replaceChildren` in StreamActions.update While processing `` elements, Turbo combines two steps: 1. sets [`innerHTML = ""`][innerHTML] 2. call [`append(this.templateContent)`][append] Modern `Element` implementations provide a [replaceChildren][] method that effectively combines these two steps into a single, atomic operation. The `Element.replaceChildren()` method [isn't supported by Internet Explorer][replaceChildren compatibility], but the `Element.append()` method that it replaces [has the same incompatibility issues][append compatibility]. [innerHTML]: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML [append]: https://developer.mozilla.org/en-US/docs/Web/API/Element/append [append compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/Element/append#browser_compatibility [replaceChildren]: https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren [replaceChildren compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren#browser_compatibility --- src/core/streams/stream_actions.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/streams/stream_actions.ts b/src/core/streams/stream_actions.ts index b7ab78e9e..0db0d3ba4 100644 --- a/src/core/streams/stream_actions.ts +++ b/src/core/streams/stream_actions.ts @@ -28,9 +28,6 @@ export const StreamActions: { [action: string]: (this: StreamElement) => void } }, update() { - this.targetElements.forEach(e => { - e.innerHTML = "" - e.append(this.templateContent) - }) + this.targetElements.forEach(e => e.replaceChildren(this.templateContent)) } }