a-h / templ

A language for writing HTML user interfaces in Go.
https://templ.guide/
MIT License
7.14k stars 236 forks source link

feat: use buffered IO to enable streaming responses, and implement flush component #802

Closed a-h closed 1 week ago

a-h commented 1 week ago

Fixes #207 Resolves https://github.com/a-h/templ/discussions/458

See https://github.com/a-h/templ/discussions/781#discussioncomment-9680731 for discussion

a-h commented 1 week ago

The ComponentHandler that's used for HTTP currently renders everything to an internal buffer, so that if there's an error during template rendering, the correct HTTP status code can be used.

So, there is likely a need for a streaming version of the Handler function, e.g. StreamingHandler which doesn't do that, or a streaming mode of operation for the existing version.

joerdav commented 1 week ago

This makes sense to me, it took a minute for me to understand what the point was, but I get it now.

I think this needs thorough docs, not just around how to use it, but when and why you would use it with examples.

joerdav commented 1 week ago

You read my mind on the non-flushable streams error, I was going to ask about that.