-
Notifications
You must be signed in to change notification settings - Fork 51
API Discussion: Why isn't template just a render function? #47
Comments
There are a couple of reasons for this. React doesn't support conditional comments or In all of our sizable projects, we always end needing these things, and the template tag approach was the most ergonomic I came up with. I'd be open to a lower-level API that the template tag relied upon, but that you could also invoke directly. Definitely interested in your thoughts and ideas here. |
@divmain First off, thanks for the worderful library! I have been waiting for this in a long time! I was about to open the same issue. Because the first instinct when finding out about the library was to search for renderToStaticMarkup function. The analogous non streaming react-dom/server module exposes a single object with just two methods on it. It would be nice if we could follow the Principle_of_least_astonishment, and make the API's match
https://facebook.github.io/react/docs/react-dom-server.html I ended up doing the following on the server
Which makes me wonder. why not just alias the templete function so the API actually match. It seems to me that creating another templating language instead of using react itself does not actually follow the Unix_philosophy . But I am probably overlooking things. I have never tried to add analytics to react.
People seem to solve this with either this The below just works. Breaks the interface, but conveniently set html5 as default, which is probably true if one is doing ssr.
|
@cescoferraro Thanks for the contribution. I was thinking of a similar wrapper as well. The one thing I'm not clear about is if
but it's not totally clear from the docs if this will work or not:
The difference being that in the first case, the Rapscallion renderer is a passed directly to the I also agree with you that the doctype thing seems really easily fixable as a second argument to the render method, or just outside of the API, as it's trivial to stream out a doctype before streaming out content. I agree with @divmain that the current solutions for html conditional comments are not great. In my experience, conditional comments aren't particularly important to support, as IE9 is the only browser that supports both conditional comments and React, and IE9 is only about a quarter of a percent of global browser share and falling. If you really, really wanted to support conditional comments in server rendering, you could make a As for script tags, it seems to me pretty trivial to make a |
@aickin, re this:
I doubt that'll work as things stand now. However, if you wanted something like that, you could always do:
I may be missing what you're going for here, though... If you want the equivalent of So there'd be nothing stopping you from doing
or
That should give you clean markup. I'll think on this a bit more, and probably solicit some opinions from others who set up the SSR boilerplate regularly. Thanks for all the input! |
First off, congratulations on your launch! Nice job. 🚀🌈🔥
Also: thanks for having good docs!
It's great that you included static templates, but I'm a little confused about your choice to use template strings rather than just making another render function with plain old React elements. It seems to me that using template strings requires the developer to learn a second API (in addition to
render
), but that's not really required. If instead you made it a plain old function (called, say, `renderTemplate``), I think Rapscallion might have a more compact, learnable API.To get a sense for what this would look like, the example in the template section would become:
This also gets rid of the need to support callbacks in the templated strings, I think. Thoughts?
The text was updated successfully, but these errors were encountered: