Menu

1 / 2

window.localStorage can be null, which is how our signup flow handed people an error screen

DEV Community: react·Daniel Pertu·3 days ago
#14Lxkt4K
#devtoreact#devto#dev#theme#null
Reading 0:00
15s threshold

Everyone knows two things about localStorage . It might be empty, and reading it might throw in a privacy mode. There is a third state that I had never written code for, and it cost new CogniPrep users their first logged-in page:

TypeError: Cannot read properties of null (reading 'getItem')

Enter fullscreen mode

Exit fullscreen mode

Not "storage is empty". Not "access denied". window.localStorage was null . An Android WebView with DOM storage disabled hands you a null property where the object should be, so the obvious line

const stored = localStorage . getItem ( ' theme ' );

Enter fullscreen mode

Exit fullscreen mode

throws a TypeError before any storage policy gets a say. Android WebViews are how in-app browsers render pages, which makes this ordinary traffic rather than an edge case. The error arrived tagged Chrome Mobile WebView.

Why it landed on the worst possible page

CogniPrep forces dark mode on its marketing and auth pages, and respects your preference everywhere else.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.