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
fix: preserve node order in swapWithParent #7639
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment. Other than that, looks great.
Thanks for your patience with my review.
Thanks. Happy with your suggestion. That was just my lack of understanding of the internals, your version is clearer. I haven't clicked 'commit suggestion' in the GitHub UI just because I don't want to mess up the house style for commit messages. Happy for you to commit them, or I can batch them into a commit. Would a commit message of |
We will squash the commits anyway so the individual commit messages are not as critical. |
* fix: preserve node order in swapwithparents * chore: update examples [CI] * style: auto-formatting [CI] * Update src/compile/data/dataflow.ts * docs: update src/compile/data/dataflow.ts Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com> Co-authored-by: Dominik Moritz <domoritz@gmail.com>
This PR closes #4680 and #5475. It helps with part of #5261.
The root cause of the problem is within the moveFacetDown map.
The problem occurs because the
swapWithParent
method does not preserve the order of branches in the tree, so the main map iterates incorrectly. It expects to be able to iterate over each branch in turn, but when the order changes, this fails.I have used the following spec to find the bug.
Example buggy spec
To be more specific, with this example spec, in
optimize.ts
immediately prior to themoveFacetDown
map,data.sources
is a symmetrical tree like:However, following the map, the data structure has become asymmetrical. This is because
swapWithParent
does not preserve the order of the children. But we're iterating recursively over these children, so the recursive map becomes asymetrical.The order fails to be preserved because when you remove a child and then re-add it here, its position in the array is not preserved.
I have tested this against the following specs which are reported as broken in #4680, with the following outputs, which look correct to me.
Grateful for any feedback on the fix. I've run tests locally, but I'm not sure I understand [this] about adding a
GH_PAT
. Is that saying that, in my fork, I need to add a secret containing a personal access token that has onlypublic_repo
permissions? I didn't want to do that without checking, because of potential security implications.Specs:
My example used to bugfix
cpennington example
sh4pe example
Isue 5475 example
Isue 5261 example