Skip to content

fix(themes): drop malformed installed-theme entries instead of crashing - #372

Merged
nedtwigg merged 1 commit into
mainfrom
fix/theme-store-malformed-elements
Aug 15, 2026
Merged

fix(themes): drop malformed installed-theme entries instead of crashing#372
nedtwigg merged 1 commit into
mainfrom
fix/theme-store-malformed-elements

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

Surfaced by the nightly code-quality sweep.

getInstalledThemes() guards against corrupted/tampered localStorage with Array.isArray(parsed), but that only rejects a non-array top level. An array whose elements are malformed — [null], or an object missing id — passes the guard and is returned cast as DormouseTheme[]. The .id dereferences downstream then throw an uncaught TypeError, breaking exactly the theme listing and installation the guard comment says it protects:

  • getTheme(id)getAllThemes().find((t) => t.id === id)null.id
  • addInstalledTheme(theme) / removeInstalledTheme(id).filter((t) => t.id !== …)null.id

This is the same "corrupted or externally tampered storage" case the existing not-an-array test covers, just one level down.

Fix

Filter to well-formed elements (object with a string id) instead of only checking the top-level array. Malformed entries are dropped; well-formed themes still load, matching the graceful-recovery intent.

Test

Adds a regression test feeding [null, { label: 'no id' }, <valid theme>]: it asserts only the valid theme survives and that getAllThemes()/addInstalledTheme() no longer throw. The test fails before this change (the first .map((t) => t.id) throws on null.id).

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8f78c36
Status: ✅  Deploy successful!
Preview URL: https://8257dbd2.mouseterm.pages.dev
Branch Preview URL: https://fix-theme-store-malformed-el.mouseterm.pages.dev

View logs

@nedtwigg
nedtwigg merged commit e02a59a into main Aug 15, 2026
7 checks passed
@nedtwigg
nedtwigg deleted the fix/theme-store-malformed-elements branch August 15, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants