question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

localStorage issues

See original GitHub issue

I am working on a desktop webapp that relies on Chakra for the UI rendering. I am having issues using ColorModeProvider. Specifically using <DarkMode>. It appears that on macOS (Safari WKWebView) the page is not able to access localStorage and it just crashes.

It would be nice to have a switch option to use/not use the localStorage feature provided by the use-dark-mode library and just let my application handle the user preference.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dedo1911commented, May 28, 2020

I just got around the issue with a solution like this:

import React from 'react'
import { CSSReset, ColorModeContext } from '@chakra-ui/core'

const ColorModeProvider = props => {
  const colorMode = {
    colorMode: props.value || 'light',
    toggleColorMode: _ => {}
  }

  return <ColorModeContext.Provider value={colorMode}>
    <CSSReset />
    {props.children}
  </ColorModeContext.Provider>
}

export default ColorModeProvider

What I did is basically defining my own ColorModeProvider that doesn’t use anything but a colorMode property. You should implement your custom toggleColorMode or set colorMode with your rules.

0reactions
with-heartcommented, Jun 30, 2020

Color mode now works correctly with localStorage in 1.0! https://next.chakra-ui.com/docs/color-mode

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is LocalStorage safe to use? - Snyk
When used thoughtfully, local storage can be a powerful lightweight data storage solution that isn't without problems.
Read more >
Please Stop Using Local Storage - DEV Community ‍ ‍
... issues by doing so. Let's have a heart-to-heart and talk about local storage and why you should stop using it to store...
Read more >
Your browser's local storage can be misused. Here's how.
Local storage remains persistent even after closing and reopening the browser. The information stored on the local storage will remain available ...
Read more >
Please Stop Using Local Storage - Randall Degges
This means anything sensitive you've got in local storage (like a user's session data) can be compromised. Now, you might be thinking “So...
Read more >
Can local storage ever be considered secure? - Stack Overflow
Well, the basic premise here is: no, it is not secure yet. Basically, you can't run crypto in JavaScript: JavaScript Crypto Considered Harmful....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found