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

added check for self.parentElement before attempting to remove #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mfoitzik
Copy link

Hi Stefan. I came across this issue in my implementation. There is a step in the code that does: self.parentElement.removeChild(self), but sometimes self.parentElement does not exist and causes an error. I wrapped it in an if statement to first check for self.parentElement and it fixed the problem. Thank you.

@Flyer53
Copy link
Owner

Flyer53 commented Dec 2, 2024

@mfoitzik Hey Mike, thanks for your addition 😄
But I wonder how the line of code you referenced can cause this kind of error.
The code is used inside self.close() which starts with if (!self.parentElement) {return;} as the first line of code. So I don't understand the error.
And another question is: how can a panel which is always a part of the document be without a parent element?
Do I miss something?

@mfoitzik
Copy link
Author

mfoitzik commented Dec 2, 2024 via email

@Flyer53
Copy link
Owner

Flyer53 commented Dec 2, 2024

Hi Mike, thanks for the quick answer ... and thanks for the praise 😄

It's not that I have a problem with the if statement. I just don't understand ...

self.close = (cb, closedByUser) => {
    // if panel does not exist return
    if (!self.parentElement) {return;}
    /*
     more code ...
    */
    self.remove()
}

... my thinking is that self.remove() never gets called when there is no parent element because self.close() already returns in this case prior self.close() is called. Am I wrong here?

@mfoitzik
Copy link
Author

mfoitzik commented Dec 2, 2024 via email

@Flyer53
Copy link
Owner

Flyer53 commented Dec 3, 2024

Hi Mike, I did a few quick tests and could not reproduce the same error.

Is there any reason that you remove a panel without using the close method? Somehow you have to reference the panel anyhow, so why not use the close method?

@mfoitzik
Copy link
Author

mfoitzik commented Dec 3, 2024 via email

@Flyer53
Copy link
Owner

Flyer53 commented Dec 3, 2024

Hi Mike,
In order to remove all panels you could use ...

document.querySelectorAll('.jsPanel').forEach((item) => {
    item.close();
});

... since all panels have the CSS class jsPanel by default.

@mfoitzik
Copy link
Author

mfoitzik commented Dec 3, 2024 via email

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.

2 participants