Resolve block chains against the render context - #4925
Merged
Conversation
stof
reviewed
Sep 11, 2026
| } | ||
|
|
||
| public function hasBlock(string $name): bool | ||
| public function hasBlock(string $name, array $context = []): bool |
Member
There was a problem hiding this comment.
I suggest adding @param array<string, mixed> $context on this method to give more precise type (phpstan level 6+ does not like arrays that don't specify their types)
fabpot
force-pushed
the
block-chain-render-context
branch
from
September 11, 2026 22:35
1fdff94 to
897717d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While working on the Symfony PR for #4917, I realize that the performance was worse with the Twig's way. #4924 fixes part of the performance "regression". This one closes the gap.
BlockChaincurrently freezes each template's lineage by cloning it, so the block map andparent()both resolve{% extends %}against the constructor context.This PR changes that to resolve the chain against the render context instead.
hasBlock()andgetBlockNames()take a context, likeTemplateWrapperalready does, and the third constructor argument becomes a default the render context can override. A lineage whose templates all have a fixed parent (none, or constant) is resolved once and cached, so the common case costs nothing; a dynamic{% extends %}re-resolves per call (not use by Symfony anyway).This fixes also an inconsistency: a chained template with a dynamic parent now behaves exactly as it does when rendered directly. It also removes all changes in the "core" logic of Template.