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.

Blocking cookies breaks withDarkMode component

See original GitHub issue

Description

The withDarkMode component uses the localStorage API directly, which causes errors when the browser blocks access to those APIs. This causes most of the site to not display correctly. Screen Shot 2021-06-01 at 11 33 44 AM

withDarkMode provides information about the current mode of the theme to various components around the site. It does this through checking localStorage for the darkMode key and using the use-dark-mode hook. When cookies are blocked by the browser, it blocks our access to certain browser APIs such as localStorage and causes this component to throw an uncaught error. This error comes from our attempt to access localStorage https://github.com/newrelic/opensource-website/blob/develop/src/components/withDarkMode.js#L10 and the use-dark-mode hook.

Solution

  1. Wrap the call to localStorage in a try/catch.
  2. Tell use-dark-mode to use an in-memory store when localStorage isn’t available, similar to how the theme does it.

Steps to Reproduce

Run the opensource site and block all cookies on your browser.

Expected Behavior

The core content loads without needing access to the localStorage.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
elaguertacommented, Jul 26, 2021

@rudouglas I’m taking myself off this one. I put a closes keyword on your PR, but if you get a chance you may want to relink it. No worries at all - you didn’t step on my toes, and I was glad to see your solution. Thanks for coordinating!

0reactions
rudouglascommented, Jul 26, 2021

Sorry @elaguerta didn’t see your comment, ignore my PR 😬

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to block third-party cookies in Chrome, Firefox, Edge, and ...
Then, on the right, click or tap on Custom, and select the option labeled “All third-party cookies (may cause websites to break)” from...
Read more >
FAQ How Blocked Third Party Cookies Can Potentially Impact ...
Third party cookie blocking can impact the following Okta use cases: ... functionality can be broken by the browser's blocking of third-party cookies....
Read more >
How to avoid third-party cookies in every browser
1. Google provides an in-built feature that automatically blocks all third-party cookies. To enable it, click the Three dots drop-down menu next to...
Read more >
Dark Mode Email: Your Ultimate How-to Guide - Litmus
In this post, we break down: What Dark Mode is and why people use it; 3 ways Dark Mode settings impact email design;...
Read more >
How Different Browsers Handle First-Party and Third-Party ...
The setting can be changed to block cookies from all unvisited websites, all third-party cookies or all cookies (including first-party cookies).
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