Hi, I find that even when I have set “default_composition_mode” to Markdown mode, users on my forum are getting served the Rich text editor on starting a new topic. The forum version is “Discourse v3.5.0.beta9-dev — Commits · discourse/discourse · GitHub — Ember v5.12.0”.
Each time I apply the change, I am prompted “Would you like to apply this change historically? This will change preferences for 15 existing users.” and I click Yes. Even then, users being served the rich editor. Is this a known bug?
Edit - note: I have this issue with users who never used the toggle option to swap their editor mode between rich/markdown. They just logged in today after I had already set the default composition mode on the weekend right after the upgrade. I had also hidden the toggle option via theme CSS.
Following up on this, we have a plugin that uses “wrap_open” BBCode tokens, which are not supported by the rich text editor yet. So we need to ensure we stay on the Markdown mode for now.
I used Claude Sonnet to generate the following code to ensure that. I would be happy to receive any feedback on how I could improve it (especially if it has any bugs ). Also sharing this in case it helps other forum admins. The code goes in Theme settings > JS (/admin/customize/themes/2/common/js/edit):
import {
apiInitializer
} from "discourse/lib/api";
export default apiInitializer((api) => {
// Force switch the user's editor to markdown mode
function switchToMarkdownMode() {
const currentUser = api.getCurrentUser();
// User should be signed in if composer was opened
if (!currentUser) {
console.error('No user found');
return;
}
// Got this option from here
// https://github.com/discourse/discourse/blob/f0fc5646dc9bd29b0e814faea490e34800e9b322/app/assets/javascripts/discourse/app/models/user.js#L262C1-L266C4
const currentMode = currentUser.get('user_option.composition_mode');
if (currentMode !== 0) {
// Only switch if not already in markdown mode
// Example usage: https://github.com/discourse/discourse/blob/87476ce2c18fb8f856dda7ff03804ed5fbb0ff38/app/assets/javascripts/discourse/app/services/user-tips.js#L127
currentUser.set('user_option.composition_mode', 0);
// Save the user preference to the server
currentUser.save(['composition_mode']).then(() => {
console.log('Successfully switched to markdown mode');
}).catch((error) => {
console.error('Failed to update composition mode:', error);
});
// Immediately toggle the current composer UI
setTimeout(() => {
const toggleButton = document.querySelector('.composer-toggle-switch[data-rich-editor]');
if (toggleButton) {
const isRichTextActive = toggleButton.getAttribute('aria-checked') === 'true';
if (isRichTextActive) {
toggleButton.click();
console.log('Toggled current composer to markdown mode');
}
}
}, 100); // Small delay to ensure composer is fully rendered
} else {
console.log('Already in markdown mode, no change needed');
}
}
api.onAppEvent('composer:opened', () => {
switchToMarkdownMode();
});
});
Ik zal proberen dit te reproduceren + morgen aan een oplossing te werken, maar ik weet niet zeker waarom dit zou gebeuren, aangezien de admin standaard alle gebruikersoptiewaarden instelt (als je de bestaande gebruikersoptie in de prompt gebruikt), en dit is alles wat we gebruiken om de schakelaar te bedienen.
Thanks for the quick responses! I’m not sure how I can create a minimal repro for this. I’m happy to share any additional info from my forum if you can share the steps for it.
I tried to reproduce this today with no luck. I do have one question though – are users refreshing the browser after you change this? Because if not, we still have their old user preference data in the browser in ember, so the new preference will not be used yet.
For this to work as expected I did this:
Checked on user A that editor was toggled to rich mode
As admin, I changed the default to markdown mode and applied for all users
As user A, reloaded the page and reopened the editor, and saw that it was in markdown mode
If I didn’t reload on step 3 there, I would still see rich mode.
Bedankt voor de follow-up, Martin. Ik had de modus zondag al ingesteld op Markdown. Vervolgens had ik me maandag met een testaccount ingelogd, in een apart browserprofiel, dat de Rich editor ontving in plaats daarvan.
Ook, als dat helpt, telkens als ik “default_composition_mode” instel op “Markdown”, krijg ik de waarschuwing: “Wilt u deze wijziging historisch toepassen? Dit verandert de voorkeuren voor 61 bestaande gebruikers.” Ik begrijp dat ik dit de eerste keer zou moeten krijgen, maar het lijkt een bug dat het me elke keer voor een aantal gebruikers vraagt.
Voor verder testen heb ik me ook net ingelogd op een ander testaccount dat 10 maanden niet was ingelogd. Deze was ook standaard ingesteld op Rich Text-modus.
This is very odd indeed…how many users are on your site in total? I wonder if it’s hanging on the step where it’s supposed to update all users from the site setting change, because I noticed there is nothing in the UI to indicate that work is still happening.
Depends on how many users have changed it with the toggle in the interim. It seems like it works properly for me in local testing.
Set default_composition_mode to Markdown mode. Even when it’s already in Markdown mode, you can open the dropdown and select the Markdown option.
Get the warning for XX number of users. Accept it.
Wait ten minutes, and then reload the page.
Set default_composition_mode to Markdown mode (same as step 2).
Again, get the warning for the same number of users.
As you mentioned, I also don’t know how long it takes (over 10 minutes?) to update the historical user preferences. Also, I don’t think all those users would have updated their preferences back in just that time. I could be missing something here.
Okay yeah definitely doesn’t sound like that many people would be toggling in that time Are you able to do a screen recording to show what’s happening?
I’d also advise you take a look at the Network tab in Chrome Developer tools. It should show 2 requests like this after you save it (first one is the one to show the prompt of XX users, second one is to actually save the setting and do the backfill):
The second one needs to have a 200 status, if it doesn’t and you navigate away then it will not have backfilled for existing users.
A video recording is at this Drive link. I set the setting, accepted the warning dialog, waited a little, reloaded the page, and then set it again. Then I got the warning dialog again.
Should not happen…there is a bug here where it’s considering the value for the list item (0) different from the setting value (’0’). So I think the Save here is doing nothing. I can fix that bug, but can you do this:
Change the setting to “Rich text”
Save it, but choose “No, only apply changes going forward”
Change back to “Markdown”
Save it, and choose “Yes” to apply it retroactively