Skip to content

Commit

Permalink
fix: dom not appended should not be treated as ShadowRoot (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadCcc authored Aug 4, 2023
1 parent 2ced0b2 commit cc74b27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Dom/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function getRoot(ele: Node) {
* Check if is in shadowRoot
*/
export function inShadow(ele: Node) {
return getRoot(ele) !== ele?.ownerDocument;
return getRoot(ele) instanceof ShadowRoot;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/shadow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ describe('shadow', () => {

expect(getShadowRoot(button)).toBeNull();
});

it('should return null if dom is not appended', () => {
const button = document.createElement('button');
expect(getShadowRoot(button)).toBeNull();
});
});
});

2 comments on commit cc74b27

@vercel
Copy link

@vercel vercel bot commented on cc74b27 Aug 4, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

util – ./

util-react-component.vercel.app
util.vercel.app
util-git-master-react-component.vercel.app

@mazengh
Copy link

@mazengh mazengh commented on cc74b27 Oct 24, 2023

Choose a reason for hiding this comment

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

@MadCcc can you please check the below issue related to this change? I am facing an issue where this change breaks antd. I wish I am able to provide a repo for reproduction but I am loading my code as a static resource in salesforce and it's not possible to create a repo. Some context... Salesforce LWC uses a synthetic shadow dom @lwc/synthetic-shadow. This worked perfectly for antd before the update in this PR.
#462

Please sign in to comment.