cookieconsent icon indicating copy to clipboard operation
cookieconsent copied to clipboard

[Bug]: Clicking Save Preferences button rejects all services regardless of toggle state

Open peaemaye opened this issue 1 year ago • 1 comments

Expected Behavior

Should save the current service selection.

Current Behavior

All services are rejected and fire their onReject event.

Steps to reproduce

See this StackBlitz for a minimal repro: https://stackblitz.com/edit/stackblitz-starters-xtbkbf?file=index.js

  1. Click Open Preview in new tab icon to open in new window that will retain cookies on reload.
  2. Open F12 developer tools to see console.log entries.
  3. Click Accept all to accept all categories/services.
  4. Press F5 to reload the page.
  5. Click the Show preferences modal button to open the preferences window.
  6. Expand the Analytics cookies section to see that Service1 and Service2 are active.
  7. Click Save preferences to save the current selection without making any changes.

Proposed fix or additional info.

See PR: https://github.com/orestbida/cookieconsent/pull/701

Version

3.0.1

On which browser do you see the issue?

Firefox, Chrome

peaemaye avatar Jun 25 '24 10:06 peaemaye

I think I've found the cause of this issue. The retrieveState method of api.js currently sets the _enabledServices before _acceptedServices so the enabled services don't include services read from the cc-cookie. I think reversing this order is sufficient to fix it.

See pull request #701

peaemaye avatar Jun 27 '24 09:06 peaemaye