Active
Project:
Drupal core
Version:
main
Component:
block.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Sep 2026 at 15:30 UTC
Updated:
21 Sep 2026 at 19:23 UTC
Jump to comment: Most recent
We have a custom block that just returns a '#type' => 'link'.
The render array also contains a #cache key and we noticed the cache context is ignored and does not bubble.
It seems the Link render element does not handle #cache correctly and loses it during render.
Here the cache context is lost:
public function build(): array {
return [
'#title' => 'foo',
'#type' => 'link',
'#url' => Url::fromUri('http://example.com'),
'#cache' => ['contexts' => ['timezone']]
];
}
But this works:
public function build(): array {
return [
'#markup' => 'foo',
'#cache' => ['contexts' => ['timezone']]
];
}
This also works:
public function build(): array {
return [
[
'#title' => 'foo',
'#type' => 'link',
'#url' => Url::fromUri('http://example.com'),
],
'#cache' => ['contexts' => ['timezone']],
];
}
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 #2
prudloff commentedIt seems I can't reproduce this on a clean install so it might be caused by a specific module.