Automattic / Automattic/jetpack
Cookies & Consents Widget: JavaScript error in the customizer in some themes
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
When using the WordPress Customizer I am getting this error in the Chrome Inspector Tools:
Uncaught TypeError: Cannot read property 'classList' of null
at eu-cookie-law.min.js:2
at eu-cookie-law.min.js:2
It is the Jetpack eu-cookie-law because this is the full source:
https://c0.wp.com/p/jetpack/8.5/_inc/build/widgets/eu-cookie-law/eu-cookie-law.min.js
The offending object is “**n**” which is set to “**getElementById(‘eu-cookie-law’)**”.
I believe there should be a check for existence of the element:
if(n !== null && n.hasOwnProperty('classList'){ ... }
Contributor guide
Research direction
Reproduce the error in the WordPress Customizer with a theme where the eu-cookie-law element is absent, then inspect _inc/build/widgets/eu-cookie-law/eu-cookie-law.min.js from the reported Jetpack source. Confirm that the customizer no longer throws a classList error when getElementById('eu-cookie-law') returns null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wordpress
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100