Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
feat: add template-shadowroot polyfill (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominique Wirz <[email protected]>
  • Loading branch information
dwirz and Dominique Wirz authored Oct 17, 2023
1 parent 3214f44 commit 9ac5ad7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 73 deletions.
89 changes: 17 additions & 72 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lint": "next lint"
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.2.1",
"abc-web-components-react-wrapper": "^0.0.0",
"next": "13.5.5",
"react": "18.2.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/app/public/scripts/polyfills/template-shadowroot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// eslint-disable-next-line no-prototype-builtins
if (!HTMLTemplateElement.prototype.hasOwnProperty('shadowRoot')) {
import('@webcomponents/template-shadowroot/template-shadowroot.js').then(({ hydrateShadowRoots }) => {
hydrateShadowRoots(document.body);
});
}
4 changes: 4 additions & 0 deletions packages/app/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @next/next/no-before-interactive-script-outside-document */
import type { Metadata } from 'next';
import Script from 'next/script';

export const metadata: Metadata = {
title: 'Next.js ABC Web Components App',
Expand All @@ -18,7 +20,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
boxSizing: 'border-box',
}}
>
<noscript>Please enable JavaScript to view this website. Especially if you use Firefox.</noscript>
{children}
<Script src="./scripts/polyfills/template-shadowroot.js" strategy="beforeInteractive" />
</body>
</html>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "public/scripts/polyfills/template-shadowroot.js"],
"exclude": ["node_modules"]
}

0 comments on commit 9ac5ad7

Please sign in to comment.