Problem/Motivation
#2478483: Introduce placeholders (#lazy_builder) to replace #post_render_cache introduced the concept of "placeholders". It allowed us to remove #post_render_cache, and all the special handling for that, and just have placeholders be another type of attachment. So, we now have #attached[placeholders].
Because placeholders are an attachment, they should be handled in a HtmlResponseAttachmentsProcessor, which specifically is the place that takes attachments and ensures the HtmlResponse is updated accordingly.
(This issue & code originate from #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!). This blocks that issue, as well as #2349011: Support placeholder render strategies so contrib can support BigPipe, ESI….)
Proposed resolution
Make it so.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
But, notable change:
HtmlResponseAttachmentsProcessor now renders the attached placeholders (#attached[placeholders]). Which means finally all attachments are truly processed in the AttachmentsResponseProcessorInterface implementation for HTML responses.
This means HtmlRenderer no longer needs to render attached placeholders. Which means HtmlResponse objects are now perfectly cacheable, because they don't contain anything user-specific.
(This is not an API change, just an implementation detail change.)
Data model changes
None.
Beta phase evaluation
| Issue category | Task because not broken, but an important improvement. |
|---|---|
| Issue priority | Major because it blocks significant other issues. |
| Prioritized changes | The main goal of this issue is performance/cacheability. |
| Disruption | Zero disruption. |
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | html_response_placeholders-2551989-5.patch | 12.27 KB | wim leers |
Comments
Comment #2
wim leersComment #3
wim leersAdded beta evaluation.
Comment #4
Crell commentedNit: This would be easier to read if split to multiple lines.
Let me make sure I am following the logic of this method, as it's rather inside out...
Given an HtmlResponse object, whose body contains placeholders and has placeholder replacement attachments...
Convert the HtmlResponse to an equivalent render array.
renderRoot() the render array, which will swap in the placeholders.
Reset the body of the rendered array back on the Response, which MAY include new dependencies and other attachments based on the now-executed placeholders.
Right? If so, let's add some version of the above to the docblock because it took me 10 minutes to write this summary. :-)
Also, this method should return the modified $response rather than just letting it be an input/output parameter. Both work, but explicit returns make the code easier to follow.
Shouldn't this be checking against an interface, not a class?
First sentence is a runon. I think you mean "renderRoot() renders the $build render array and updates it in place."
Same language correction as above.
So why don't we use renderRoot()?
Comment #5
wim leersYour understanding is 100% correct.
Docblock updated.
+1 on this returning a response object. I wonder why I didn't do that before :/
Comment #6
Crell commentedExtra period. Can fix on commit.
I think that's well-documented enough now. :-) Thanks, Wim.
Comment #7
alexpottI've spent some time on IRC discussing this change on IRC with @Wim Leers I'm that happy that we're injecting and using
renderer.configinto the HtmlRenderer and using it. We discussed several work around including:HtmlResponseAttachmentsProcessorto add them, This does not work because HtmlRenderer needs to return a properly cacheable response with all cache contextsrenderRoot(),renderPlain()and just plain ol'render().renderer.configto something that does not seem so specific.I think only the last one is actually worth pursuing and we can do that as a followup. Fixed the double fullstop on commit. Committed 0549d59 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.
Comment #9
wim leersMany thanks! This unblocks #2349011: Support placeholder render strategies so contrib can support BigPipe, ESI… and helps make #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!) more focused, so yay! :)
Follow-up created: #2553373: Consider renaming renderer.config. Expect it to become more meaty tomorrow. In meetings all day today.