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();
});
});
I will try reproduce this + work on a fix tomorrow, but I am not sure why this would happen since the admin default sets all user option values (if you use the existing user option in the prompt), and this is all we use to control the toggle switch.
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.
Thanks for the follow-up, Martin. I had already set the mode to Markdown on Sunday. I had then logged in with a test account on Monday, in a separate browser profile, which received the Rich editor instead.
Also, if that helps, each time I set “default_composition_mode” to “Markdown”, I get the warning: “Would you like to apply this change historically? This will change preferences for 61 existing users.” I understand I should get this the first time, but it seems like a bug that it prompts me each time for some number of users.
For further testing, I also just logged into another test account that hadn’t logged in for 10 months. It was also set to Rich Text mode by default.
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