fix: element z-index sorting rendering abnormality #1921
Merged
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.
🤔 This is a ...
🔗 Related issue link
fixed #1910
💡 Background and solution
In the rendering process, in order to ensure the correct rendering order of child elements, we need to check whether there are child elements with
z-index != 0
. If so, we first sort them and save them to thesorted
list for rendering. If not, we will directly render them in thechildNodes
list (that is, the order in which the elements are mounted).There are 3 problems here:
z-index
of the element, if a parent element no longer has a child element withz-index != 0
, the rendering list will be abnormalTo solve this problem, it is necessary to determine whether there is a child element with
z-index != 0
after the child elements are sorted. If not, we will clear thesorted
list to obtain the correct rendering list and orderz-index == 0
andz-index != 0
child elements, since thesorted
list has not been truly refreshed during the element mounting (needs to be triggered by callingrender()
), some elements do not appear in thesorted
list in the end and cannot be rendered normallyTo solve this problem, you only need to determine whether the sorted list is marked as
dirty = true
during the element mounting to ensure that the logic of the data processing process does not depend on the rendering resultrender()
, the finalsorted
There will be multiple references to the same element in the list, which means that the same element will be rendered multiple times (for example, text elements will appear jagged)When sorting sub-elements in each frame, we need to remove the sub-elements from the
sorted
list first, and then perform subsequent logical processing based on whether the element is mounted or unmounted. If it is a mounted sub-element, we will calculate the element's sorting index and insert it into the appropriate position in thesorted
list again.📝 Changelog
☑️ Self Check before Merge