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

Prevent crash when use lib inside webcomponent #445

Merged
merged 2 commits into from
Dec 12, 2021

Conversation

hreyeslo
Copy link
Contributor

I'm using this lib inside Stencil webcomponent with shadow dom activated. The problem is when the closest funtion is trying to find a document element because inside shadowDorm we have not a document element, we have a document-fragment element without matches function so for that i added an if to return false in that case because we able to asume that is the last parent or cant continue finding more nodes.

@vercel
Copy link

vercel bot commented Oct 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/t1m0n/air-datepicker/AdVT99cddhgN4nLbwsVP4Hnb1SPk
✅ Preview: https://air-datepicker-git-fork-hreyeslo-feature-webcompon-36a66f-t1m0n.vercel.app

src/utils.js Outdated
@@ -293,6 +293,8 @@ export function addEventListener(el, type, listener) {
export function closest(target, selector) {
if (!target || target === document) return false;

if (typeof target.matches !== 'function') return false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your PR, maybe it is better to add check against DocumentFragment for better understanding what is happening?

if (!target || target === document ||  target instanceof DocumentFragment) return false;

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Yes, i believe that it looks better

@t1m0n t1m0n merged commit 27a070a into t1m0n:v3 Dec 12, 2021
pleomax13 pushed a commit to pleomax13/air-datepicker that referenced this pull request Jun 6, 2023
Prevent crash when use lib inside webcomponent
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.

None yet

2 participants