Closed wimski closed 11 months ago
Hey there,
While this may be a legitimate issue, can you first try posting your problem or question on one of the support channels below? If this issue can be definitively identified as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.
Thanks!
@crynobone I managed to fix 'my' issue like this:
use Illuminate\View\View as BaseView;
class View extends BaseView
{
public function render(callable $callback = null): string
{
$contents = parent::render();
$this->factory->flushSections();
return $contents;
}
}
Apparently all the section contents are cached during the entire request cycle, which results in incorrect data usage in rendering when you have multiple views extending the same parent in one page (request cycle). I resolved this by flushing the section cache after the rendering of each individual view (within the page/request cycle).
So either it's not a bug because extending views was always only intended to be used for a single view (a page), or it is. If the former is the case, a big disclaimer in the documentation would be nice so the limitations of extending are clear.
The fact that sections are cached by name during the rendering of an entire page, can have some weird effects if you use the same section names in different (unrelated) views. This consequence is also not mentioned in the documentation. And I'm wondering if that was ever an intended consequence.
Okay, this results in errors for certain more complex setups :thinking:
Laravel Version
10.10.33
PHP Version
8.2.4
Database Driver & Version
No response
Description
When using template inheritance with
@yield
and@section
by multiple children at the same time, only the data of the first child will be rendered. The other children will therefore show the data of the first child (in the inherited template). I would expect that every child template would be rendered with its own data.I've created a repository to demonstrate the issue (also see 'Steps To Reproduce'). The last commit gives a clear picture of the setup. I've included three examples which all use the same template inheritance setup:
https://github.com/wimski/laravel-view-inheritance-issue/commit/d2e6257bc8add924e4a59f5fb71504201a4139b2
Steps To Reproduce
.env.example
to.env
.concreteValue: bar
(from the first item) instead ofconcreteValue: ipsum
.