Issue open pre-filled composer

AI-generated summary

duranmla is seeking a way to open the Discourse composer with pre-filled data instantly, without redirecting to /latest first. They’re using DiscourseURL.routeTo() with query parameters, but this causes a page load before the composer opens — which they want to avoid. They’ve referenced prior discussions on pre-filling composers and working with actions, and clarify they’re not asking for help lazily but to document solutions for others. They note this isn’t marked as a bug, suspecting it’s a usage issue. Osama offers a direct solution: bypass routing and use the composer controller’s open() method directly, passing CREATE_TOPIC, draftKey, title, and topicBody — along with optional fields like tags or category ID. They point to the composer controller source for more options. This approach avoids page navigation and opens the composer immediately, solving the delay issue.

I have already made a topic that gives me information about how to open the composer with pre-filled information, besides, I got some useful answer about working with actions too, those Topics can be found at:

However, I face the problem that the composer gets open but it doesn’t open instantly, instead, the app moves to: /latest URL and once the loading there finishes THEN the composer opens. In that sense, I am posting this in order to know if there is a better way to ensure the composer opens without load a new page so it can be open instantly (as soon the user click the button) The code I use looks like:

_openComposerWithParams($form) {
    var serializedData = $form.serialize();
    var pathToOpenComposer = `/new-topic?${serializedData}`

    // open composer using query params
    DiscourseURL.routeTo(`${pathToOpenComposer}`);
}

and of course, I have a preventDefault on the form submission to avoid redirections.

$form.on('submit', (e) => {
      e.preventDefault();
      this._openComposerWithParams($form);
});

PD: I am publishing all these topics around quite the same context not because I stop to make my research and wants someone does my homework but to actually helps someone else with the same problems.

Lastly, I didn’t mark this as a “BUG” cause sounds more like I am doing something wrong cause I do not think this is the expected behavior.

You could do something like this in your button’s action:

const { CREATE_TOPIC, DRAFT } = require('discourse/models/composer').default;

composer = Discourse.__container__.lookup('controller:composer');
composer.open({
  action: CREATE_TOPIC,
  draftKey: DRAFT,
  title: "Pre-filled topic title!",
  topicBody: "Pre-filled topic body goes here"
});

You can pass additional data to the composer’s open() method such as tags, category ID, target usernames if you’re sending a message and so on. There are a lot of clues in this file:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/controllers/composer.js.es6#L587