Changing Theme Style (sub-theme) does not work for AJAX pages

Hello.

I am using SuiteCRM 7.11.15 and have noticed a problem when I go to “Profile” -> “Layout Options” and change the “Style” (e.g. from “Day” to “Night”). For pages that don’t use AJAX (e.g. /index.php?module=Home&action=index), the new style is used, but for AJAX pages (e.g. /index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DAccounts%26action%3Dindex%26parentTab%3DMarketing) it isn’t.

When I look at the network activity, the request for “/index.php?action=ajaxui” returns “304 Not Modified”, meaning that the browser will display the cached version of the page, which links to the previous “style.css” file.

Looking at the code, in include/MVC/View/views/view.ajaxui.php, it runs

     $etag = $user->id . $user->getETagSeed("mainMenuETag");
    generateEtagHeader($etag);

which is in include/utils.php:

function generateETagHeader($etag)
{
    header('cache-control:');
    header('Expires: ');
    header('ETag: ' . $etag);
    header('Pragma:');
    if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
        if ($etag == $_SERVER['HTTP_IF_NONE_MATCH']) {
            ob_clean();
            header('Status: 304 Not Modified');
            header('HTTP/1.0 304 Not Modified');
            die();
        }
    }
}

However, because changing the sub-theme does not change the “mainMenuETag”, this always sends back the “304 Not Modified”.

Note that this only happens if the website has a valid SSL certificate, otherwise the browser discards the Etags.

Is anyone else having this problem, and if so, this there a work-around (apart from clearing the browser cache whenever you change the sub-theme)?

Thanks,

Carl

Maybe one of the options from Admin / Repair? Not sure which, though.

Hello.

Thanks for the response. Even assuming that one of the repair options does fix it (and I haven’t seen anything in the code that suggests that it would), it isn’t really a solution, as most users would not have the option to run it.

Regards,

Carl

Yes, you’re right, I just meant my suggestion as a work-around.

Can you make a fix for this? You seem to understand what’s going on.

Hello.

I made the following change to modules/Users/User.php, function saveFormPreferences(), from

if (isset($_POST['subtheme'])) {
    $this->setPreference('subtheme', $_POST['subtheme'], 0, 'global');              
}

to

if (isset($_POST['subtheme'])) {
    if ($this->getPreference('subtheme')!==$_POST['subtheme']) {
        $this->setPreference('subtheme', $_POST['subtheme'], 0, 'global');
        $this->incrementEtag('mainMenuETag');
    }
}

Seemed to work for me.

Regards,

Carl

Cool. Do you want to propose a PR on Github for that change?