]> git.ardis.lu - ardislu.dev/commitdiff
Catch when path is not in metadata
authorArdis Lu <ardisglu@gmail.com>
Mon, 29 May 2023 20:02:03 +0000 (13:02 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 29 May 2023 20:02:03 +0000 (13:02 -0700)
Happens when static assets are loaded on homepage

script.js

index c9bcb62ae265f579c0e2de8c79f67a3c7a1c7c72..e4a95f1758ce3e7b96b0b3f1a584d9b5d1b5a8f5 100644 (file)
--- a/script.js
+++ b/script.js
@@ -13,7 +13,7 @@ const cacheChannel = new BroadcastChannel('cache');
 cacheChannel.addEventListener('message', e => {
   const resourceUrl = new URL(e.data.resource);
   const isApiRequest = resourceUrl.pathname === '/api';
-  const isCurrentPage = resourceUrl.search.split('/').pop() === metadata.get(window.location.pathname).id;
+  const isCurrentPage = resourceUrl.search.split('/').pop() === metadata.get(window.location.pathname)?.id;
   // Only show toast if:
   // - Non-static asset (static assets logo.svg, style.css, script.js, etc. are not managed by service worker)
   // - The relevant page is open (if the user has multiple tabs open, do not show the toast on unrelated pages)
This page took 0.043135 seconds and 4 git commands to generate.