Use replaceChildren in StreamActions.update#534
Merged
dhh merged 3 commits intohotwired:mainfrom Jun 19, 2022
Merged
Conversation
replaceChildren in StreamActions.updatereplaceChildren in StreamActions.update
79b7527 to
f645bd8
Compare
While processing `<turbo-stream action="update">` 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
f645bd8 to
d763ead
Compare
dhh
pushed a commit
to feliperaul/turbo
that referenced
this pull request
Jul 16, 2022
* main: Allow frames to scroll smoothly into view (hotwired#607) Export Type declarations for `turbo:` events (hotwired#452) Add .php as a valid isHTML extension (hotwired#629) Add original click event to 'turbo:click' details (hotwired#611) Drive Browser tests with `playwright` (hotwired#609) Allow Turbo Streams w/ GET via `data-turbo-stream` (hotwired#612) Only update history when Turbo visit is renderable (hotwired#601) Support development ChromeDriver version overrides (hotwired#606) Turbo stream source (hotwired#415) Expose Frame load state via `[complete]` attribute (hotwired#487) fix(ie/edge): form.method='delete', raises Invalid argument. (hotwired#586) Do not declare global types/constants (hotwired#524) Defensively create custom turbo elements (hotwired#483) Use `replaceChildren` in StreamActions.update (hotwired#534)
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While processing
<turbo-stream action="update">elements, Turbocombines two steps:
innerHTML = ""append(this.templateContent)Modern
Elementimplementations provide a replaceChildren methodthat effectively combines these two steps into a single, atomic
operation.
The
Element.replaceChildren()method isn't supported by InternetExplorer, but the
Element.append()method that it replaces has the same incompatibility issues.