Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Don't reverse the pushed data #16325

Merged
merged 1 commit into from
Nov 15, 2016
Merged

[5.4] Don't reverse the pushed data #16325

merged 1 commit into from
Nov 15, 2016

Conversation

jbrooksuk
Copy link
Member

Closes #14876

@jbrooksuk jbrooksuk changed the title Don't reverse the pushed data [5.4]Don't reverse the pushed data Nov 8, 2016
@jbrooksuk jbrooksuk changed the title [5.4]Don't reverse the pushed data [5.4] Don't reverse the pushed data Nov 8, 2016
@taylorotwell
Copy link
Member

I feel like we must have been doing this for a reason? 😄

@jbrooksuk
Copy link
Member Author

@taylorotwell I originally thought that, but the change that introduced the reversal didn't explicitly state why.

@taylorotwell
Copy link
Member

Would like to get to the bottom of that if possible.

@taylorotwell
Copy link
Member

@mark86092 can you let us know why you introduced an array_reverse on the push?

@jbrooksuk
Copy link
Member Author

Pinging @mark86092?

@jbrooksuk
Copy link
Member Author

Oh, you beat me.

@mark86092
Copy link
Contributor

Wait me a moment, I'll reply soon

@mark86092
Copy link
Contributor

The reason goes to several statements:

  1. Rendering Ordering:

The first is child --> then parent --> then the grand parent blade template

with renderCount increases to identify

So, the PR #12808 's tests use the $factory->incrementRender(); in L285, to mimic the @push in parent.

  1. The Push Content Ordering:

I would expect the @push content in parent should appear before child, and the @push content in grand parent should appear before parent blade template

Reason from 1) and 2)

So, I think when render the $this->pushContentsStack[$section], it is better to array_reverse it.

Making the parent's push content (i.e. $this->pushContentsStack[$section][1]) appears before the child's push content (i.e. $this->pushContentsStack[$section][0])

@mark86092
Copy link
Contributor

During the investigation of the reason, I found that in BladeCompiler.php, compileExtends and compileInclude share almost the same render behaviors. Could it be the reason why array_reverse or not array_reverse ?

@taylorotwell
Copy link
Member

@jbrooksuk any thoughts on that? 😄

@taylorotwell
Copy link
Member

I tend to agree with removing this. It becomes more apparent the behavior is wrong when you use something like the new 5.4 components and slots... your pushes are in reverse order when you dump them in that situation.

@taylorotwell taylorotwell merged commit 85309df into laravel:master Nov 15, 2016
@taylorotwell
Copy link
Member

I think there are situations where the array_reverse behavior makes sense but perhaps it needs to be thought out more. To me push should render its contents in the order they were pushed. Otherwise its not a push its just a prepend.

@jbrooksuk
Copy link
Member Author

Sorry, @taylorotwell I missed your message. But yeah, slots would make the reverse weirder.

@rico-ocepek
Copy link

rico-ocepek commented Jan 29, 2017

From my point of view the 5.3 order was better (maybe not correct but better).
Just updated to 5.4 and all my javascript inclusions broke due to the child's javascript being rendered before the parent's.
It's probably the correct behavior for something called 'stack' but I really wish for something queue-like now.

For the moment i fixed my error using prioritized yields for the scripts that need to be loaded first but this doesn't feel nice at all.

Any ideas how to work arround this?

@GrahamCampbell GrahamCampbell changed the title [5.4] Don't reverse the pushed data [5.5] Don't reverse the pushed data Jan 30, 2017
@GrahamCampbell GrahamCampbell changed the title [5.5] Don't reverse the pushed data [5.4] Don't reverse the pushed data Jan 30, 2017
@jbrooksuk jbrooksuk deleted the dont-reverse-yield-push branch January 30, 2017 08:55
@jbrooksuk jbrooksuk restored the dont-reverse-yield-push branch February 21, 2017 16:28
@jbrooksuk jbrooksuk deleted the dont-reverse-yield-push branch February 12, 2021 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants