[Live] Always send HTML over the wire instead of JSON #245
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.
Hi!
Currently, the LiveComponent controller expects to get JSON back from the server, containing
{ data: ..., html: '...' }
. But, Stimulus is so cool, that this isn't necessary! The LiveComponent Ajax requests can simply return HTML in all cases. The rendered element will have an updateddata-live-data-value
attribute with the latest data. And so, the Stimulus component instantly reads that updated data and incorporates it: there is no need to send back the "component data" on a separate key in the JSON.This makes the live component system more boring in a good way: it's just a way to return HTML (and then we have fancy JavaScript that adds all the interactivity). It's also a bit faster now, as previously we were dehydrating the component data twice on re-render.
I can't think of any downsides to this approach - everything seems to work just fine.
Cheers!