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

An element with non-undefined children should clear the node’s actual children. #167

Closed
brainkim opened this issue Oct 29, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@brainkim
Copy link
Member

brainkim commented Oct 29, 2020

Rendering something like <div>{[]}</div> will fail to clear the div of user-created DOM nodes (my current use-case is a content-editable). This was done so that the user could manually insert children into crank-created DOM nodes without having Crank interfere. Currently, we check the length of the normalized array of child nodes passed into the arrange() method, but I sorta want DOM nodes to be cleared in the case of an empty array, or a component element with no children, for instance. Maybe we could refine the heuristic to check that the actual children prop is nullish or maybe even undefined. Think more about this heuristic.

Related to #158, except that issue concerns the root DOM node which we render into, while this issue seems more about any rendered DOM node, and in this issue we want the opposite effect (clear out the DOM node as opposed to preserve the DOM node’s previous children).

@brainkim brainkim added bug Something isn't working good first issue Good for newcomers enhancement New feature or request labels Oct 29, 2020
@brainkim brainkim self-assigned this Oct 30, 2020
@brainkim brainkim changed the title An element with non-nullish empty children should clear the node’s actual children. An element with non-undefined children should clear the node’s actual children. Nov 5, 2020
@brainkim
Copy link
Member Author

brainkim commented Nov 5, 2020

My current thinking is that this behavior should be based on a "children" in el.props test, which would align with how we handle other props. In other words, if no children are defined on props, we avoid arranging the element’s children.

This would technically be a breaking change.

@brainkim brainkim removed the enhancement New feature or request label Nov 5, 2020
@brainkim
Copy link
Member Author

brainkim commented Nov 5, 2020

On second thought, I think I’m gonna make this a non-breaking change because whenever I encounter this behavior it feels more like a bug than anything.

@brainkim brainkim removed the good first issue Good for newcomers label Nov 6, 2020
@brainkim
Copy link
Member Author

brainkim commented Nov 10, 2020

On third thought, while doing an in check against the props object would technically make the children prop more like other props, that would be a more disruptive change as people might be surprised that rendering a node without children (<div />) doesn’t clear previously rendered children. I think such a change would have to be deferred to a major version change, if we actually wanted this behavior.

@brainkim
Copy link
Member Author

“Fixed” or “Changed” in 0.3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant