-
Notifications
You must be signed in to change notification settings - Fork 180
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 #50
Comments
I think this would be a nice feature! It is not high on our priority list since we want to use this with closure templates which has existing string based backends. |
I've uploaded a quick proof of concept doing string rendering here: https://github.com/paolocaminiti/incremental-dom-to-string calling .patch can render a string of the whole description function output or write directly to a stream. |
Definitely seems like an external library is the way to go for this, especially since you might want to tie it in with out you flush down changes. Simply rendering to a string could have some uses, but ultimately there are a lot of different trade-offs to be made. |
Server side rendering can be achieved trivially by using Soy with incremental dom, although the growth of popularity of other JavaScript-only-templates alerts the need of this feature, as suggested previously by @jridgewell. Being able to render incremental dom as string without external dependencies like Is there any library that already provides it? If not, this issue should be reopened for discussion. Thank you. |
I agree that idom should just stay focused on patching DOM, but maybe it would help to have a list of what DOM APIs idom depends on. Then a minimal in-memory DOM API can be created which is compatible with IDOM. Instead of passing a full HTMLElement to IDOM to patch, we could pass this minimal in-memory version. That could be used either for rendering on the server, or rendering from a web worker, or what have you. |
@ewinslow that would be ideal, as reference, this library does html to incdom. The opposite direction, incdom to html, may be even smaller. |
@sparhami's point is that DOM API is completely unnecessary for this. Instead, you'd use a library that implements iDOM's API ( |
@jridgewell yep, using a DOM API is unnecessary, patching iDOM's api is simpler. Just found this prototype, seems like it's not being maintained though. Did you happen to have something that solved your initial proposal? If not this could be an interesting library to exist. Just want to make sure if we do that we don't spent time in something someone else already have. |
Nothing that I know about. |
Easier said than done :)
|
I suppose if you want to inject HTML or something, having access to the const el = elementOpen(...)
el.innerHTML = 'foo'; // of course you would want to be a bit smarter here
elementClose(...); You might want to do something like: elementOpen(...);
setInnerHTML('foo');
elementClose(...); And then Not sure about other uses of grabbing the element, but it seems like you might want to avoid doing too much with it if you want to render on the client side. |
We've put together an initial implementation of incremental-dom-string. import {
elementOpen,
elementClose,
text,
renderToString
} from 'incremental-dom-string';
const output = renderToString(() => {
elementOpen('div');
text('Hello world');
elementClose('div');
}); where <div>
Hello world
</div> Implementation details feedback would be appreciated, specially at:
We are testing in production, it's working well for the cases we've identified. |
@jridgewell when you have a chance let us know if the implementation posted earlier is aligned with what you've proposed in this issue, thx |
We are using the referenced implementation in production for different products, would be ideal to have feedback from the community. @sparhami, since we didn't hear anything from mr. busy man @jridgewell :) would you mind giving your feedback on the implementation referenced? |
One thing I would caution about is sanitizing attribute values. For example, if you do something like:
If the user.name is something like
|
One of the perks of React is the ability to render its virtual dom into strings on the server. It'd be nice to have the same capabilities.
Do you think it'd be worth while to maintain string
element*
that could be required on the server?The text was updated successfully, but these errors were encountered: