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.

cookiesEnabled not present in cart.js

See original GitHub issue

Shopify starter and Slate have a function that looks like the below.

import {cookiesEnabled} from '@shopify/theme-cart';

// Apply a specific class to the html element for browser support of cookies.
if (cookiesEnabled()) {
  document.documentElement.className = document.documentElement.className.replace('supports-no-cookies', 'supports-cookies');
}

However the latest version of theme scripts / cart doesn’t have that function cookiesEnabled exporting. This may be related to issue #5

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
ogzcodercommented, Oct 4, 2018

I work around that error using navigator.cookiesEnabled so a simple utility function i put in my own util.js looks like:

export function cookiesEnabled() {
    return navigator.cookiesEnabled;
}

then in theme.js I remove the theme-cart import and import my own util.js

import { cookiesEnabled } from 'util';
if (cookiesEnabled()) {
  document.documentElement.className = document.documentElement.className.replace('supports-no-cookies', 'supports-cookies');
}

Haven’t taken the time to really look into it but I started getting this error within the last 24 hours. I did notice that cookiesEnabled is still being exported from @shopify/theme-cart/dist/theme-cart.cjs.js but nowhere else.

2reactions
Camcommented, Mar 4, 2019

This is probably a little less ideal, but I ended up going with the following in theme.js to keep everything in one place for now:

// Apply a specific class to the html element for browser support of cookies.
if (window.navigator.cookieEnabled) {
  document.documentElement.className = document.documentElement.className.replace(
    'supports-no-cookies',
    'supports-cookies',
  );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect server-side whether cookies are disabled
I dont think there are direct ways to check. The best way is to store a value in the cookie and try to...
Read more >
Navigator.cookieEnabled - Web APIs | MDN
navigator.cookieEnabled returns a Boolean value that indicates whether cookies are enabled or not. The property is read-only. Value.
Read more >
Reference — Cart.js
If you're not making use of the Data API and are super-concerned with performance, ... Core API methods are available on the global...
Read more >
JS examples - Shopify
Tables and video embeds do not natively scale well on smaller screens. ... This makes handling product prices and cart items in JS...
Read more >
Strip response cookies enabled - Performance
/cart* /basket* are exceptions which have been added to no avail. ... If every page is cached, it will show the same page...
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