-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render to string to support server-side rendering (SSR) #657
Comments
First thought is that not all views use |
That's what I ran into as well but why does It seems like they could be a Side-effects which assume DOM could be moved into helpers like
I can explore this route more, just feels like it's almost possible with the current code and PoC. |
For reference, I was able to get basic SSR working with Still would be interesting to do without that extra faff and render to string directly. I'm curious about the questions in my previous reply but I know you may not want to push forward here. |
I might be misunderstanding the question, but the goal is that all views share a common interface, so a TemplateView can be mounted inside a ListView and vice-versa, independent of how they are implemented. There's even StaticView that doesn't do data binding or event handlers fwiw. We also want to keep the possibility open to have an IView that wraps for example a React or Vue view if we want to integrate some third party library. The only common denominator is really the DOM.
Sorry, but I don't think we want to add this complication just so server-side rendering wouldn't need to use a DOM implementation.
It's up to you, but I don't think we want to accommodate too much within the Hydrogen view layer to render with anything else than a DOM implementation. If you can make it work, great, but it's a fragile setup IMO. We could change where we get the DOM implementation from (e.g. allow to inject it rather than hardcode the If you have problems with linkedom, I'd recommend to giving JSDOM a try. |
With the same Hydrogen ethos in mind (minimizing dependencies), it would be nice to do away with the DOM implementation for Node.js. At this point, we have a working enough example with
The case against render to string mostly boils down to this which is fine ⏩ It's not too unreasonable.
The common interface could be
Both Vue and React have the possibilities to render to a node or a string so it would be compatible with a |
Is your feature request related to a problem? Please describe.
For feature parity with Gitter, we're developing a new Matrix public archive so all of the Gitter content on Matrix is still indexable by search engines (and bring this benefit to all of the other Matrix rooms).
The plan is to server-side render some Hydrogen components to get a native(to Element) feeling experience (and the maintenance of keeping up with different message types). Currently, Hydrogen uses a lot of DOM
document
API's to construct the views which aren't available in Node.js and makes it harder to server-side render.Describe the solution you'd like
Add a way to render Hydrogen components to a string.
For reference, Vue.js
renderer.renderToString
Describe alternatives you've considered
In Node.js land, we could instead maybe use the
document
API's from https://github.com/jsdom/jsdom but this feels heavy compared to how close render to string might be.Other related libraries:
document
/Node
API'slinkedom
document
stuffAdditional context
Since Hydrogen has a lot of the DOM usage abstracted up to
src/platform/web/ui/general/html.ts
andsrc/platform/web/ui/general/TemplateView.ts
, it seems possible to shove a newTemplateBuilder
in place which renders to a string instead.I've made a very rough proof of concept in #656 which kinda works but there are some obstacles:
In terms of actually doing it, I'm curious about your thoughts and taste-making here! 🙂
The text was updated successfully, but these errors were encountered: