Skip to content

Use replaceChildren in StreamActions.update#534

Merged
dhh merged 3 commits intohotwired:mainfrom
seanpdoyle:turbo-stream-update-replace-children
Jun 19, 2022
Merged

Use replaceChildren in StreamActions.update#534
dhh merged 3 commits intohotwired:mainfrom
seanpdoyle:turbo-stream-update-replace-children

Conversation

@seanpdoyle
Copy link
Copy Markdown
Contributor

@seanpdoyle seanpdoyle commented Feb 13, 2022

While processing <turbo-stream action="update"> elements, Turbo
combines two steps:

  1. sets innerHTML = ""
  2. call append(this.templateContent)

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
, but the Element.append()
method that it replaces has the same incompatibility issues.

@seanpdoyle seanpdoyle changed the title Using replaceChildren in StreamActions.update Use replaceChildren in StreamActions.update Feb 13, 2022
@seanpdoyle seanpdoyle force-pushed the turbo-stream-update-replace-children branch from 79b7527 to f645bd8 Compare April 1, 2022 13:47
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
@seanpdoyle seanpdoyle force-pushed the turbo-stream-update-replace-children branch from f645bd8 to d763ead Compare April 1, 2022 14:02
@dhh dhh merged commit 5109c56 into hotwired:main Jun 19, 2022
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)
@marcoroth marcoroth mentioned this pull request Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants