Problem/Motivation
Blocked on #2450993: Rendered Cache Metadata created during the main controller request gets lost.
#2450993: Rendered Cache Metadata created during the main controller request gets lost reduces/removes all risks/implications of losing bubbleable metadata.
Proposed resolution
As a next step, we should remove the $is_root_call parameter and move the root call-specific logic out of ::render() and into ::renderRoot().
This in turn allows us to start reducing the Renderers reliance on the static $contextCollection variable, which currently prevents at least some async rendering implementations in core.
Remaining tasks
To fully enable fibers to suspend during rendering we also need #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers.
User interface changes
None.
API changes
TBD
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2511330-1.patch | 7.7 KB | wim leers |
Issue fork drupal-2511330
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
wim leersThis is a rough initial patch, built on top of #2450993-92: Rendered Cache Metadata created during the main controller request gets lost. This issue is postponed until that one lands.
Comment #2
wim leersThis was actually unblocked a long time ago. But will need work.
Comment #4
fabianx commentedhttps://gist.github.com/LionsAd/cbf84e5e70b05c1ca11e is a different approach to do the same, but keeps BC.
( Need to ignore the change for #cache though as that was needed for something else.)
Comment #5
wim leersI think this will need to wait until D9 now?
Comment #6
fabianx commentedNot really, my patch keeps BC so can go in whenever.
Comment #7
wim leersOk. Can you post your patch here?
Comment #8
fabianx commentedComment #9
wim leersPer #6 + #7.
Comment #23
catchJust ran into this exception and found the @todo via #3496369: Multiple load path aliases without the preload cache and #3437499: Use placeholdering for more blocks - if you combine the two MRs from those issues and don't have bigpipe installed, you get the exception on various pages.
Comment #24
catchConverted Fabianx's patch to an MR and dealt with conflicts/cs issues.
Comment #26
catchLots of failures. Might be worth moving Wim's patch to a second MR and see where we land with that - looks like bc could be added quite straightforwardly to Wim's approach.
Comment #28
catchOK after fixing the unit tests in Wim's approach I realised the bug in Fabian's approach, so we've now got green MRs for both.
However, this is an important improvement from Fabian's:
e.g. when rendering children, we no longer rely on the global render context state but or even a class property, but pass the context into the method.
I think that this will either solve, or approach solving, the issues I'm running into on #3496369: Multiple load path aliases without the preload cache (where we enter and leave different rendering contexts).
Comment #30
catchOK #28 was premature but now it's green.
Comment #31
catchI think the next step here is #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers but that will require interface changes to add the parameter to a couple of methods and maybe more things, so one step at a time.
#3516034: Add cacheable metadata to SelectInterface and entity QueryInterface objects is closely related too.
Comment #32
catchComment #33
catchMoving this to a bug report, it wasn't a bug as such when it was originally added to core, more of a 'limitation', but now we're using fibers for placeholder rendering, if code actually fiber suspends a decent amount, which is done in #3496369: Multiple load path aliases without the preload cache, everything explodes on cache misses.
The problem was (completely) missed in #3377570: Add PHP Fibers support to BigPipe, but this pre-existing issue solves it, alongside #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers which I just opened this week as a follow-up to this issue. The combination of the two allows that path alias issue to pass nearly all tests, but anything that uses fiber suspend in multiple placeholders will trigger the same exception at the moment.
There's very good existing test coverage of this, as shown by the several commits on both MRs here tracking down and fixing various test failures. I don't think we need explicit test coverage of the fiber suspend issue yet, it could possibly be added in #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers but not here because as soon as you fix this issue you run into that one, keeping separate for ease of review since neither are simple and they don't conflict.
Comment #34
catchComment #35
catchComment #36
andypostAs I get it just need deprecation test
Comment #37
catchI don't think this needs a deprecation test - the deprecation path is only the trigger_error() and one line method call, no actual bc layer to test. Moving back to needs review.
Comment #38
godotislateSome comments on MR 10795.
Comment #39
catchThanks for looking, think I resolved all of those.
Comment #40
godotislateMy mistake about the
use Drupal\Core\Render\RenderContext;suggestion. It's in the same namespace, so it was unnecessary and flagged by PHPCS.Also looks like phpstan baseline needs regenerating.
Added a couple comments on the typehints too.
Comment #41
catchArgh I spotted the RenderContext thing after commit and before push, but failed to commit the change.
Pushed a commit for that and the other couple of comments. I think the phpstan complaint was real. Should be back to green.
Comment #42
godotislatelgtm
Comment #43
larowlanLeft some questions on the MR
Comment #44
larowlanPutting back to RTBC because all the changes from my last review where I changed the status were either trivial or reverted.
I manually confirmed we still have the bubbling check from the other point.
Given the changes here would have been fine for catch to self RTBC I think it is OK for me to commit this still.
Comment #46
larowlanCommitted to 11.x - thanks!
Published the change notice.
Comment #48
catchThanks!
Next up for anyone following along is #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers.
Comment #49
kristiaanvandeneyndeI noticed the docs in doRender() were not adjusted:
They still mention that doRender() can be the root call, and from the MR it seems that doRender() should no longer be concerned with any of that. Tackle this in a tiny follow-up?
Comment #50
larowlanYes please to tiny follow up 🙏
Comment #51
kristiaanvandeneyndeWorking on it here: #3524626: Renderer::doRender() and ::doRenderRoot() contain some outdated information
Comment #52
larowlanThanks
Comment #53
berdirThe array type added here cases a fatal error for us, caused by template_preprocess_node():
created is null, and while it shouldn't call it then, this seems like a BC break that shouldn't be done like this or then the render () method should guard against that?
Follow-up to remove that?
Comment #54
berdirCreated #3524738: Fatal error when passing NULL to Renderer::render()
Comment #55
catchNext step here for unblocking async rendering is #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers.