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

Fix append() failing after mutating nodes through .parent #1740

Merged
merged 1 commit into from Apr 30, 2022

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Apr 29, 2022

Fixes #1738

I wasn't quite sure where to put the test but the gist of the issue is that

  1. node.append calls node.normalize
  2. node.normalize sets the parent to this.

The problem arises when node is a proxy. This means that this ends up being a proxy instead of the raw node. Assigning the proxy to the "raw" child node's parent has a side-effect of causing proxyOf.nodes to contain proxies rather than raw postcss nodes.

This causes indexOf lookups to fail since they're sadly not transparent to Proxies b/c of object identity.
Later on append tries to use this index assuming that the nodes passed in are definitely children and have been found and crashes.

I'm not 100% sure this is the right fix because the interactions just to get this to happen are fairly specific. Change any number of things and it all magically works. But, it seems reasonable.

I noticed that the .push method sets the parent as well but I don't have a test case where it's affected so I've not updated it. I might be able to come up with a test case if needed. Also, if you have any suggestions for reducing the test case I've got in this PR I would love some because it seems like it's a bit much for such a "simple" fix.

@ai
Copy link
Member

ai commented Apr 29, 2022

Thanks for the fix

Can I ask you to fix linter s your PR will be green? =^_^=

@thecrypticace
Copy link
Contributor Author

Whoops my bad! Fixed that up.

@ai ai merged commit 8a1f6c2 into postcss:main Apr 30, 2022
@ai
Copy link
Member

ai commented Apr 30, 2022

Released in 8.4.13

@thecrypticace
Copy link
Contributor Author

Awesome — thank you very much!

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.

Traversing though .parent and then mutating .nodes causes append to fail
2 participants