laravel/framework

Stack push not always working

Open

#60221 opened on May 21, 2026

View on GitHub
 (2 comments) (0 reactions) (0 assignees)PHP (34,705 stars) (11,882 forks)batch import
help wanted

Description

Laravel Version

13.11.1

PHP Version

8.4

Database Driver & Version

N/A

Description

Based on the documentation for @stack I would expect to be able to define a @push basically anywhere and have it rendered into the stack. I have come across 2 scenarios where this does not appear to work.

The first is very contrived, and not a realistic way the feature would be used, but could be indicative of the underlying problem.

//welcome.blade.php

@push('scripts')
    before stack
@endpush

@stack('scripts')

@push('scripts')
    after stack
@endpush

In this example, the stack and push are defined in the same view file. Only "before stack" is rendered.

There's really no need to make this scenario work because if you're in the same file you don't need to bother pushing to a stack, but including it to showcase the full failure scenario.


The 2nd example is the specific issue I have run into, and what I hope we can make work. To replicate this issue we need 2 components and 1 view. I've used class based components, but I would assume anonymous one would behave the same.

  • "layout" component
  • "chat" component
  • "welcome" view
//layout.blade.php

<!doctype html>
<html lang="en">
<head>
<title>Title</title>

@stack('scripts')

</head>
<body>

<div>{{ $slot }}</div>

<x-chat input="layout"></x-chat>

</body>
</html>
//welcome.blade.php
<x-layout>

    <x-chat input="view"></x-chat>

    @push('scripts')
        pushed from view
    @endpush

</x-layout>
//chat.blade.php

@push('scripts')
    pushed from chat [{{ $input }}]
@endpush

<div>The Chat</div>

When visiting the "welcome" view, I would expect to see

<!doctype html>
<html lang="en">
<head>
<title>Title</title>
 
pushed from chat [view]
pushed from chat [layout]
pushed from view
 
</head>
<body>
 
<div>The Chat</div>
 
<div>The Chat</div>
 
</body>
</html>

but instead I only get

<!doctype html>
<html lang="en">
<head>
<title>Title</title>
 
pushed from chat [view]
pushed from view
 
</head>
<body>
 
<div>The Chat</div>
 
<div>The Chat</div>
 
</body>
</html>

So the view is able to push to the stack, the component included in the view is able to push to the stack, but the component included in the layout cannot. We can see the component contents are correctly being rendered twice, and it is only the stack push that is not working in the 1 scenario.

As far as I can tell, the compiled views look correct. They are calling startPush(), yieldPushContents(), etc correctly.

I'm going to try and dig into the Blade a little more to try and debug this, but putting this out there because maybe this is a known limitation, or someone has some insight on how to fix this.

Steps To Reproduce

See description.

Contributor guide