From 7c64767b520c240cbbcce2121428e2857647a2fc Mon Sep 17 00:00:00 2001 From: Pagwin Date: Wed, 3 Sep 2025 17:19:27 -0400 Subject: [PATCH] checking for db error also bringing in article tweaks due to lazy usage of -a in git commit --- posts/platonically-ideal-light-dark-toggle.md | 6 ++++-- static/demos/light-dark-demo-4/sw.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/posts/platonically-ideal-light-dark-toggle.md b/posts/platonically-ideal-light-dark-toggle.md index 94d021a..eb69017 100644 --- a/posts/platonically-ideal-light-dark-toggle.md +++ b/posts/platonically-ideal-light-dark-toggle.md @@ -21,13 +21,15 @@ So I thought it'd be interesting to explore these tradeoffs and throw my own hat ## The Obvious Way -[demo]() +[demo](/static/demos/light-dark-demo-1) + +The obvious way to attempt a toggle between light and dark mode is ## A Suboptimal Solution A trick from from [](https://www.joshwcomeau.com/react/dark-mode/) -[demo]() +[demo](/static/demos/light-dark-demo-2) ## An Ideal Stateless Toggle diff --git a/static/demos/light-dark-demo-4/sw.js b/static/demos/light-dark-demo-4/sw.js index 94532e0..addfb5f 100644 --- a/static/demos/light-dark-demo-4/sw.js +++ b/static/demos/light-dark-demo-4/sw.js @@ -22,6 +22,15 @@ self.addEventListener("fetch", event =>{ async function handle_redirect(req){ const go_back_to = req.headers.get('Referer') || '/';; const db_req = self.indexedDB.open("light-dark-store"); + + db_req.onerror = (event) => { + console.error("Database error:", event); + resolve(new Response("Database error", { + status: 302, + headers: { 'Location': go_back_to } + })); + }; + const up_promise = new Promise((res)=>{ db_req.onupgradeneeded = (event) => { const db = event.target.result;