Skip to content

RemoveChildren in Components.js being executed with an undefined component #2940

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

Closed
jcamejo opened this issue Aug 6, 2020 · 1 comment
Closed

Comments

@jcamejo
Copy link
Contributor

jcamejo commented Aug 6, 2020

Hi @artf long time, I hope everything is going good with you and your closed ones.

There's a small case that I wanted to ask what you think before i make a request.

I have a custom link component that is wrapped around a li tag, this link has an event to remove its parent li when is removed.

If i delete the link directly everything works fine, but if I remove an outer parent that contains both li and link components, removeChildren in Components.js gets executed with an undefined component, causing this error to happen

Uncaught TypeError: can't access property "getId", removed is undefined
    removeChildren Components.js:30

This is due to the object being deleted during another callback (the custom one i made) before the removeChildren gets the parameter.

This can be solved by just returning if the removed param is falsey but maybe it's too hackish and i should look for another solution and not make the component delete its parent.

  removeChildren(removed, coll, opts = {}) {
    if (!removed) {
      return;
    }

What do you think?

Thanks!

@jcamejo jcamejo changed the title RemoveChildren in Components.js being executed with an undefined component parameter RemoveChildren in Components.js being executed with an undefined component Aug 6, 2020
@artf
Copy link
Member

artf commented Aug 26, 2020

Thanks Juan, all good and I hope the same to you :)

This can be solved by just returning if the removed param is falsey but maybe it's too hackish and i should look for another solution and not make the component delete its parent.

Well, technically removeChildren shouldn't be called "without" removed, so if that condition solves your issue I think it's good.
I also think that your case might be used by someone else

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

No branches or pull requests

2 participants