Cookie Notice: "Cannot read properties of null (reading 'style')" on the login page and in the block editor
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start with obfx_modules/policy-notice/init.php, especially hooks() around lines 160–162 and the script around lines 238–240; compare when the markup and script are printed. Reproduce on the login page or in the block editor with Cookie Notice enabled, where the bar element is absent. Done when those contexts load without the reported JavaScript error and the bar still works where its markup is present.
Written by the indexing model from the issue text.
Description
Cookie Notice: "Cannot read properties of null (reading 'style')" on the login page and in the block editor
With the Cookie Notice bar enabled, its script also runs on pages where the bar isn't printed, and throws: Uncaught TypeError: Cannot read properties of null (reading 'style'). This happens on the login page (wp-login.php), inside the block editor's canvas, and in the Customizer's login preview. Visitors don't see anything. It shows in the browser console and in any monitoring that records JavaScript errors, and an uncaught error can stop scripts that run after it in the same block.
Seen on Orbit Fox 3.0.12 with WordPress 7.1.3 and 7.1.4.
Try it in Playground: WordPress latest (7.1.4), Neve, Orbit Fox with the Cookie Notice bar on. It opens the login form.
Checked through that link: the login page carries the Cookie Notice script but no #obfx-cookie-bar element. That is exactly the state in which the script throws. (Our local runs on 7.1.3 and 7.1.4 recorded the TypeError on wp-login.php and in the editor canvas on every page load.)
Steps to reproduce
- Orbit Fox → General Settings: turn on Cookie Notice, open its Settings, enable the bar, Save.
- Open
/wp-login.phpand open the browser console. - Open any post in the block editor and check the console again.
Expected: no errors.
Actual: Uncaught TypeError: Cannot read properties of null (reading 'style') on both screens.
Cause
obfx_modules/policy-notice/init.php, hooks() (lines 160–162): the bar's markup is printed on wp_footer, but its script and style on wp_print_footer_scripts. That second hook also runs on the login page, in the editor canvas and in other contexts without wp_footer. The script reads document.getElementById('obfx-cookie-bar').style (line 238) and document.getElementById('obfx-accept-cookie-policy') (line 240) without checking they exist.
Possible fix
Print the script from wp_footer together with the markup, or return early in the script when #obfx-cookie-bar is missing. Not tried; a suggestion from the code.
Found while building Orbit Fox's compatibility checks (Codeinwp/qa-compatibility#100), where it is recorded as a known difference: the same on every WordPress version tested.
- Dominant language
- PHP
- Stars
- 13
- Forks
- 18
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Codeinwp/themeisle-companion
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Codeinwp/themeisle-companion#1013 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Codeinwp/themeisle-companion#1009 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Codeinwp/themeisle-companion#1008 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 77/100
Codeinwp/themeisle-companion#1015 · 1 comment ·
Maintainers usually reply within 1 day
-
Disable Comments: blocks registered only in JavaScript can't be inserted while the module is onOpen
Difficulty 3/5 1-2 days Newbie friendliness 70/100
Codeinwp/themeisle-companion#1012 ·
Maintainers usually reply within 1 day
All issues in Codeinwp/themeisle-companion
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Icinga/icinga-notifications-web#645 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
OpenMage/magento-lts#5865 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
neos/flow-development-collection#3655 ·
Maintainers usually reply within 2 days
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
Maintainers usually reply within 1 day