-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Node.before() inserts after if the new node is already a sibling #1778
Comments
Sorry, I need to ask a help with research and PR. I am spending all my free resources helping people affected by war. |
👋 willing to take a look in the next few days. |
Have done some digging and as far as I can tell the They are intended and written for adding new nodes. let root = parse('@alpha; @beta; @gamma')
let alpha = root.nodes[0];
root.push(alpha);
// Just adds one more "@alpha"
// @alpha; @beta; @gamma; @alpha This is also reflected in the documentation : https://postcss.org/api/#container-before
That said I think all the methods can be updated with something like this : function someContainerMethodForInsertion(..., add) {
if (this.index(add) > -1) {
this.removeChild(add);
}
// existing code Each method first checks if the node exists and removes it, if needed. I think this might be a breaking change for some plugins. Update : this comment was incorrect |
Yes, it could be dangerous. It is better to call |
Taking a more in depth look because there does seem to be some weirdness. This works and gives the correct final order : insertBefore(exist, add) {
this.removeChild(add); // call before "this.index()"
exist = this.index(exist) This is broken and gives an unexpected order : insertBefore(exist, add) {
exist = this.index(exist)
this.removeChild(add); // call after "this.index()" So it seems that calling |
If the expectation is that |
What I missed before is that the So @nex3 was absolutely right about :
Only for
Changing it would make the behaviour more predictable. |
@romainmenke fix was released in 8.4.17. Can we close an issue? |
@ai Did a few checks throughout the ecosystem and found that 8.4.17 affects whitespace. I don't think this is an issue as the whitespace change doesn't affect the actual CSS to the best of my knowledge. I've opened pull requests to update test results :
But these also give you an idea of the effect in case you do think this is something that requires further action. If no action is required we can close this :) |
@nex3 Have you had a chance to try out the latest version to verify that this is fixed? |
I think we can close this. |
Test case:
It looks like the index calculation gets stale once the new node is removed from its original location.
The text was updated successfully, but these errors were encountered: