[meta] Add a replacement for renderRoot() that returns a cacheable render array instead of a string

Created on 26 May 2015, over 9 years ago
Updated 23 January 2025, 6 days ago

Follow-up to / Helper for #2407195: Move attachment processing to services and per-type response subclasses

Problem/Motivation

renderRoot() returns a 'string', but that is wrong, because this is the root of the tree and hence we must take cacheable meta data into account.

Proposed resolution

Before:

$this->renderer->renderRoot($html);
$content = $this->renderCache->getCacheableRenderArray($html);

After:

$content = $this->renderer->renderRootReplacementNeedsAName($html);

If someone still needs to use the markup directly, they can do:

print $content['#markup']

on their own risk.

Remaining tasks

  1. Decide the new method name (it should not actually be renderRootReplacementNeedsAName()) and add it. Add documentation to renderRoot() about the new method as well as about the workaround above that is required for it to be cacheable.
  2. Convert those core uses that should be renderPlain() already to renderPlain() (i.e. simple renderables with no assets or caching requirements).
  3. Convert remaining core usages to the new method.
  4. Deprecate renderRoot().

User interface changes

- None

API changes

- New method returns a cacheable render array.

BETA EVAL:

It is a major bug, because if you get back a string, you expect to use that => cacheability metadata lost => security issues.

🌱 Plan
Status

Needs work

Version

11.0 🔥

Component

render system

Created by

🇩🇪Germany Fabianx

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Triaged core major

    There is consensus among core maintainers that this is a major issue. Only core committers should add this tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany donquixote

    Quick idea,
    would it make sense to return a markup object with cacheable metadata, instead of a render element?

    $markup = $renderer->renderRoot($element);
    assert($markup instanceof MarkupInterface);
    assert($markup instanceof CacheableDependencyInterface);
    
Production build 0.71.5 2024