Skip to content

Commit

Permalink
fix: only add shadow root if there is none attached
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Sep 29, 2023
1 parent e84e083 commit 3c62a79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Fixes

- Fixed shadow dom issue in nextjs dev mode by checking if a shadow root is already attached to the div before creating one.

### Example changes

- Updated dev/start script in netlify example
Expand Down
6 changes: 5 additions & 1 deletion lib/build/index2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/ts/components/featureWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ function WithShadowDom({ children }: PropsWithChildren<unknown>) {
useEffect(() => {
if (rootDiv.current) {
// defaults from react-shadow
setShadowRoot((os) => os || rootDiv.current!.attachShadow({ mode: "open", delegatesFocus: false }));
setShadowRoot(
(os) =>
os ||
rootDiv.current!.shadowRoot ||
rootDiv.current!.attachShadow({ mode: "open", delegatesFocus: false })
);
}
}, [rootDiv]);

Expand Down

0 comments on commit 3c62a79

Please sign in to comment.