turbo_stream
tag builder: support :partial
with block
#701
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.
The Background
Consider an application with a shared
application/flash
partial that accepts its message as a partial-local assignment:Also consider an
application/layout.turbo_stream.erb
template for appending theFlash
messages to a element with[id="flashes"]
:This works as you'd expect, since the
:partial
and:locals
keyword arguments are forwarded along to the underlyingrender
call.The Scenario
Now consider that the
application/flash
message changed its interface to expect themessage
as block content yielded to the partial instead of an assignment to the:locals
options:The
layouts/application.turbo_stream.erb
template would need to change as well:The Problem
This style of invocation of
turbo_stream.append
does not work the same as if it were passed a block of content generated by callingrender
with the same keywords.The presence of a
&block
argument triggers an entirely separate code path than the presence of the**rendering
keywords.To work around this issue, you'd have to capture the rendering separately:
The Proposal
This commit alters the tag builder's decision making process to incorporate a check for a combination of both a
&block
and:partial
or:layout
keyword arguments.