Overriding .gjs files - not possible?

AI-generated summary

The discussion revolves around overriding .gjs files in Discourse, specifically post-text-selection-toolbar.gjs, which cannot be overridden using traditional methods due to its GJS-based template. Sören_Geier expresses concern about limited control over UI components and functionality. Don suggests using api.renderInOutlet as a potential solution, while david confirms that plugin outlets are the recommended approach for extending such UI elements, emphasizing their reliability across updates. He also mentions a proposed feature in Discourse PR #23782 that would allow full replacement of core implementations via a ‘wrapper plugin outlet’, offering greater flexibility. The consensus is that plugin outlets are the preferred and more robust method for customization, with further enhancements under consideration.

Hello,

with a recent update one of our components broke. The component was previously extending the inline quote button which was quote-button.hbs. This file doesnt exist enymore - instead all the code was moved into a gjs file post-text-selection-toolbar.gjs and if I try to override it the “old way” the browser complains with the following message.

component-templates.js:62 [discourse/theme-48/discourse/templates/components/post-text-selection-toolbar] post-text-selection-toolbar was authored using gjs and its template cannot be overridden. Ignoring override.

Does that mean this piece of UI in Discourse can only be targeted by the defined PluginOutlets there?

  <PluginOutlet
                @name="quote-share-buttons-after"
                @connectorTagName="span"
              />

 <PluginOutlet @name="quote-button-after" @connectorTagName="div" />

What if I needed more control over the state of the buttons and the new ones added. I feel like this limits functionality.

Does anyone know how to handle that case?

Hello :waving_hand:

I think this can be possible now with api.renderInOutlet ?

https://github.com/discourse/discourse/commit/c00fd3e17d84e074a190da40744d02b944814eda

Hi @Sören_Geier - that’s correct, you’ll need to use plugin outlets to make changes in this part of the UI. Plugin outlets are a much more robust way to extend things, and will be more reliable across Discourse core updates.

If the existing Plugin Outlets don’t work for your use-case, then please let us know and we’ll be happy to look at introducing new ones.

In this case, you might be interested in the proposal in DEV: Add outlet and API for adding/controlling post selection buttons by keegangeorge · Pull Request #23782 · discourse/discourse · GitHub. This introduces a ‘wrapper plugin outlet’ which will allow themes/plugins to totally replace the core implementation if they need to.

This is an alternative way to render things into Plugin Outlets, yes. But it’s more of a code-style thing - it doesn’t actually introduce any new features when compared to /connectors/... files.