Skip to content

fix(theming): persist primary color changes/resets and invalidate stylesheet cache - #66772

Open
saiyyedfardeen wants to merge 1 commit into
nextcloud:masterfrom
saiyyedfardeen:fix-66706
Open

saiyyedfardeen wants to merge 1 commit into
nextcloud:masterfrom
saiyyedfardeen:fix-66706

Conversation

@saiyyedfardeen

@saiyyedfardeen saiyyedfardeen commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

Users were unable to permanently change or reset their primary color under User > Appearance and accessibility.

Root Causes

  1. Frontend reset race condition & missing @submit handler (UserSectionPrimaryColor.vue): <NcColorPicker> lacked a @submit event listener, relying solely on a 1000ms debounced watcher. Navigating away or refreshing before 1000ms lost the update, and clicking Reset primary color triggered onUpdate(null) (DELETE) followed 1000ms later by the watcher re-posting defaultPrimaryColor, preventing the preference from ever resetting.
  2. Stale stylesheet browser cache (BeforePreferenceListener.php): Theme stylesheets are served with Cache-Control: max-age=86400, keyed by Util::getCacheBuster() (userCacheBuster). Updating or deleting primary_color did not increment userCacheBuster, causing browsers to serve the cached stylesheet with the old color on reload.

Changes

  • apps/theming/src/components/UserSectionPrimaryColor.vue: Added @submit="onUpdate" to <NcColorPicker> for immediate saving when clicking "Choose", retained the debounced primaryColor watcher so closing the picker without clicking the button still autosaves, and guarded onReset() with isResetting + debouncedUpdate.clear?.() so resetting cleanly sends only the DELETE request without being overwritten.
  • apps/theming/lib/Listener/BeforePreferenceListener.php: Incremented userCacheBuster when primary_color is set (valid) or deleted so the stylesheet URL cache buster updates immediately.
  • Unit Tests: Added apps/theming/tests/Listener/BeforePreferenceListenerTest.php covering primary_color validation and userCacheBuster incrementation.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@susnux susnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like multiple unrelated things mashed up in on PR.
Also the frontend change does not really solve the problem but just moves it from wait 1s to being forced pressing the button.
So I would say its even worse now because 1s waiting is more likely than remember to press the button

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is you can close the picker and the colors stays - thats by design but in this usage its now confusing because the color is changed but not saved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @susnux! I've updated the PR to address all your feedback:

  1. Focused scope: Reverted the unrelated ThemingController and UserThemeController changes and kept BeforePreferenceListener strictly scoped to primary_color cache invalidation.
  2. Frontend picker behavior (UserSectionPrimaryColor.vue): Restored the debounced watch(primaryColor, ...) alongside @submit="onUpdate" so closing the picker without pressing "Choose" still auto-saves after 1s, while pressing "Choose" saves immediately.
  3. Reset race condition: Guarded onReset() with an isResetting flag and debouncedUpdate.clear?.() so resetting primaryColor back to defaultPrimaryColor doesn't trigger a follow-up POST that overwrites the DELETE request.

Comment on lines -140 to 142
$this->appConfig->setAppValueBool('disable-user-theming', $value === 'yes' || $value === 'true');
$this->themingDefaults->set(ConfigLexicon::USER_THEMING_DISABLED, $value);
$saved = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this related?

…lesheet cache

Signed-off-by: Fardeen Saiyyed <fardinsaiyyed@hotmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot change or reset primary color in theming

2 participants