Issue #2940Opened August 6, 2020by jcamejo0 reactions

RemoveChildren in Components.js being executed with an undefined component

Question

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!

Answers (1)

artfAugust 26, 20200 reactions

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

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.