0

When I upgraded my webiste from M2.3.5 to M2.4.2, I get this notice "The store will not work correctly in the case when cookies are disabled." on top of head frontend for 3 seconds. But I installed a new M2.4.2 have not get that notice(Cookie Restriction Mode = No) . I found div id named "cookie status" The store will not work correctly in the case when cookies are disabled. but I can't find which file can control this. I don't need the notice display, so how to do that? Thanks

enter image description here

enter image description here

enter image description here

1
  • Do you have an example of how to hide this notice with CSS as it is causing CLS in some situations? May 27 at 18:33
2

It's taking time to hide because there is using js for hide. you can use css for hide instaed of $script = 'document.querySelector("#cookie-status").style.display = "none";';

Content comes from vendor/magento/module-theme/view/frontend/templates/js/cookie_status.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<div id="cookie-status">
    <?= $block->escapeHtml(__('The store will not work correctly in the case when cookies are disabled.')); ?>
</div>
<?php
$script = 'document.querySelector("#cookie-status").style.display = "none";';
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['type' => 'text/javascript'], $script, false); ?>

<script type="text/x-magento-init">
    {
        "*": {
            "cookieStatus": {}
        }
    }
</script>
1
0

The cause is the missing code in Magento_Theme::js/cookie_status.phtml

<?php
   $script = 'document.querySelector("#cookie-status").style.display = "none";';
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['type' => 'text/javascript'], $script, false); ?>

We chose not to add this code as it causes delay and potentially Cumulative Layout Shift (CLS). Our solution is to use CSS to hide the element:

#cookie-status {
    display: none;
}

You can also remove the block entirely from the head by adding the following to

app/code//Theme/layout/default_head_blocks.xml

<body>
    <referenceContainer name="after.body.start">
        <referenceBlock name="cookie-status-check" remove="true"/>
    </referenceContainer>
</body>

This solution may present a problem when the element's data is required if the user has not enabled cookies.

0

Magento2.4.3

Solution:- Use this CSS to hide the element in your theme frontend folder Magento_Theme/web/css/source/_module.less

.cookie-status-message { display: none; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.