Skip to content

fix(theming): Don't reset the cachebuster value when we reset theming - #46428

Merged
SystemKeeper merged 1 commit into
masterfrom
fix/noid/fix-cypress-test-cachebuster
Jul 11, 2024
Merged

fix(theming): Don't reset the cachebuster value when we reset theming#46428
SystemKeeper merged 1 commit into
masterfrom
fix/noid/fix-cypress-test-cachebuster

Conversation

@SystemKeeper

@SystemKeeperSystemKeeper commented Jul 10, 2024

Copy link
Copy Markdown
Contributor

Summary

From the other PR:

By default there is a Pragma: no-cache header set due to the default
value no-cache of session.cache-limiter, which will cause Chrome and
iOS to not cache even with a different Cache-Control header set on the
response.

After the PR was merged the cypress-tests theming/AdminSettings kept failing. Since we now don't have a pragma: no-cache header anymore, we now rely on cache-control header and our cachebuster implementation to make sure that we get the correct files. For some files, we rely on a cachebuster based on appVersion and cachebuster value:

protectedfunctiongetVersionHashSuffix($path = false, $file = false) {
if ($this->config->getSystemValueBool('debug', false)) {
// allows chrome workspace mapping in debug mode
return"";
}
$themingSuffix = '';
$v = [];
if ($this->config->getSystemValueBool('installed', false)) {
if (\OC::$server->getAppManager()->isInstalled('theming')) {
$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
}
$v = \OC_App::getAppVersions();
}
// Try the webroot path for a match
if ($path !== false && $path !== '') {
$appName = $this->getAppNamefromPath($path);
if (array_key_exists($appName, $v)) {
$appVersion = $v[$appName];
return'?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
}
}
// fallback to the file path instead
if ($file !== false && $file !== '') {
$appName = $this->getAppNamefromPath($file);
if (array_key_exists($appName, $v)) {
$appVersion = $v[$appName];
return'?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
}
}
return'?v=' . self::$versionHash . $themingSuffix;
}

To make sure individual tests are reliable, we reset the theming settings completely before each test:

publicfunctionundoAll(): void {
$this->config->deleteAppValues('theming');
$this->increaseCacheBuster();
}

This also results in a removed cachebuster value and therefore we get the same urls in different tests which (with the changes of the other PR) results in electron to use a cached version of the file, instead of requesting the latest one.
To fix this, we keep the cachebuster value when resetting theming and increase it afterwards.

TODO

  • Don't increase twice

Checklist

Comment threadapps/theming/lib/ThemingDefaults.php Fixed
Comment threadapps/theming/lib/ThemingDefaults.php Fixed
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
@SystemKeeperSystemKeeper changed the title fix(theming): Don't reset the cachebuster value when we reset themeingfix(theming): Don't reset the cachebuster value when we reset themingJul 10, 2024
@SystemKeeper
SystemKeeperforce-pushed the fix/noid/fix-cypress-test-cachebuster branch from 9b54602 to 4f12584CompareJuly 10, 2024 21:57
@SystemKeeper

Copy link
Copy Markdown
ContributorAuthor

/backport to stable29

@SystemKeeper

Copy link
Copy Markdown
ContributorAuthor

/backport to stable28

public function undoAll(): void {
// Remember the current cachebuster value, as we do not want to reset this value
// Otherwise this can lead to caching issues as the value might be known to a browser already
$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCP\IConfig::getAppValue has been marked as deprecated
// Otherwise this can lead to caching issues as the value might be known to a browser already
$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
$this->config->deleteAppValues('theming');
$this->config->setAppValue('theming', 'cachebuster', $cacheBusterKey);

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCP\IConfig::setAppValue has been marked as deprecated
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewstestsRelated to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@SystemKeeper@nickvergessen@susnux@github-advanced-security