Skip to content

Commit

Permalink
enhance(noscript): also detect when a key JS asset cannot be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Aug 6, 2024
1 parent 2696433 commit 1aafe96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions site/SiteFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ export const SiteFooter = (props: SiteFooterProps) => (
</div>
<div className="site-tools" />
{viteAssetsForSite().forFooter}
<script
dangerouslySetInnerHTML={{
__html: `
document.querySelectorAll("script[data-attach-owid-error-handler]").forEach(script => {
script.onerror = () => {
console.log(new Error("Failed to load script: ", script.src));
document.documentElement.classList.add("js-disabled");
document.documentElement.classList.remove("js-enabled");
}
})`,
}}
/>
<script
type="module"
dangerouslySetInnerHTML={{
Expand Down
7 changes: 6 additions & 1 deletion site/viteUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export const createTagsForManifestEntry = (
if (manifestEntry?.isEntry) {
assets = [
...assets,
<script key={entry} type="module" src={assetUrl} />,
<script
key={entry}
type="module"
src={assetUrl}
data-attach-owid-error-handler
/>,
]
}

Expand Down

0 comments on commit 1aafe96

Please sign in to comment.