Fix duplicate block rendering with getSortedChildren() #4337
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.
Description (*)
If you try to add a block to a
core/text_list
, you'll get unexpected behavior if another block has been defined with the same name or alias. I consider this a bug because it's not that both blocks are rendered, but the second block is rendered twice.For example, this renders "ÄÄ":
While the first block will be overwritten by
$this->_children[$alias] = $block;
, a duplicate array element will be added to$this->_sortedChildren
.Then when we loop through the sorted children in
Mage_Core_Block_Text_List
, we will encounter the block nametest_a
twice, callgetBlock('test_a')
twice, and runtoHtml()
twice.magento-lts/app/code/core/Mage/Core/Block/Text/List.php
Lines 27 to 38 in ca4f321
You could just not add duplicate block names, but it's actually useful if you want to override a block in a more specific handle without having to add
<action method="unsetChild">
.I also replaced
unset()
witharray_splice()
in theunsetChild
method. This seems like a better solution than the solution merged from PR #1108 which I reverted.Related Pull Requests
#1108
Manual testing scenarios (*)
Add the following into your local.xml:
Results:
Questions or comments
I think I correctly replicated the issue in #1108, but if there's another test case please let me know. Ping @lemundo-team and @sreichel.
Contribution checklist (*)