Add safe first_node fn#2094
Merged
Merged
Conversation
`first_node` function can fail and in some situations, when the VNode has not been mounted yet, so this adds a safe version that returns an `Option<Node>` and refactors the previous version to use the "unchecked" prefix as it can and should panic if the first node cannot be found.
bytesnail
reviewed
Dec 4, 2021
| .map(JsCast::unchecked_into), | ||
| VNode::VComp(vcomp) => vcomp.node_ref.get(), | ||
| VNode::VList(vlist) => vlist.get(0).and_then(VNode::first_node), | ||
| VNode::VRef(node) => Some(node.clone()), |
There was a problem hiding this comment.
VNode::VList(vlist) => vlist.get(0).and_then(VNode::first_node)
would vlist be empty and cause out of index range error?
Member
There was a problem hiding this comment.
VList::get is the same as Vec::get, so it returns Option::None when the index is out of bounds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
first_nodefunction can fail, like when the VNodeis not mounted, so this adds a safe version that returns an
Option<Node>and refactors the previous version to use the "unchecked"prefix as it can and should panic if the first node cannot be found.
This change resolves @intendednull's particular issue and there seems to be
a few different versions of panics that occur that all have this function in common
so it might fix them all. I think the issue comes about when trying to insert a
node before a component that is no longer mounted - trying to find that component's
first node fails and causes the panic when we could just ignore it and then render the
node on its own.
Description
Fixes #1946
If this is accepted before it is merged a caveat I have is - I can't accept the reward so
I don't know whether @intendednull can cancel the funded issue or whether
we have to? (not quite sure how it works 🙃)
Checklist
cargo make pr-flow