meglio seeks to create a custom page at a specific Discourse URL (e.g., /my-page) that displays the native Discourse header and footer but renders custom content using React.js instead of the default Ember.js framework. The primary goal is to avoid writing a full custom plugin while retaining access to the Discourse JavaScript environment and the streaming API.
meglio initially asks if this can be achieved solely via custom JS scripts in the admin panel. However, Falco clarifies that this is not possible without a custom plugin because both the Rails and Ember routers must be explicitly aware of the new route to handle direct URL access correctly. meglio explores workarounds, such as overriding templates for specific topics or intercepting 404 errors, but acknowledges the complexity of server-side rendering versus client-side interception.
gdpelican outlines the difficult “circus” required to make a non-plugin approach work: relying on 404 interception, injecting React components into the DOM, and accessing internal containers (like messageBus) via fragile hacks. gdpelican questions why a plugin or Ember is not an option, noting the approach is inefficient. meglio explains that while they are not opposed to learning, they strongly dislike the Ember paradigm and prefer leveraging their existing React expertise. The discussion concludes with meglio reiterating the desire for a simpler method to embed React components into Discourse pages without deep framework integration.
Under the header, I’d like a React container with my own custom JS code.
Question:
How can I do it without making a custom plugin for Discourse, but by only providing custom JS scripts in admin panel?
I’ll need to still keep the Discourse header live
Will I be able to subscribe to Discourse streaming API without using Ember?
As you can understand, the whole goal for me here is to make a custom page with the native Discourse header, but with using React.js and not touching Ember.js at all.
The ember router is JS, so I thought what if there is a way to add a route to it AND provide a template as well - such a template which would not make Ember request anything from the server, but just load react JS library and some custom JS files with React components?
Will it be possible to load the Discourse’s header section into that page and still have access to all the Discourse environment and streaming API from withing JS?
What you’re proposing would have to go through some circus like
Call to domain/my-page.html
Discourse 404’s
Your custom JS catches that 404, recognizes that it came from your custom route somehow, and.. renders the whole template into the 404 div?
Meanwhile, it also loads a react component, which.. I guess gets slid into a particular DOM element using react-dom-inject or something?
Then it subscribes to messageBus, err maybe by loading something like let messageBus = Discourse.__container__.lookup('messageBus:main').subscribe? (<-- this code I think still works today, but likely won’t forever, or even for much longer)
I don’t quite get it; why is creating a custom plugin, or using Ember, not an option here?
I get that the plugin architecture and perhaps Ember has a steep learning curve, but this is really using a to churn the butter.
Because I’m not a R programmer, nor am I an Ember programmer. In the same time, I have lots of React.js experience and I love building stuff with using it.
It’s not that learning Ember is difficult. It’s that I hate its paradigm, so would like to keep its usage to the minimum.
Okay, well, thanks for commenting - anyway, this one is not the critical point. What I wanted is to allow easy React embedding in particular Discourse pages.