Open
Description
Now that we have an await
template primitive, it makes sense to have a streaming renderer:
require('svelte/ssr/register');
const app = express();
const SomeRoute = require('./components/SomeRoute.html');
app.get('/some-route', (req, res) => {
SomeRoute.renderToStream({
foo: getPromiseSomehow(req.params.foo)
}).pipe(res);
});
It would write all the markup to the stream until it encountered an await
block (at which point it would await the promise, and render the then
or catch
block as appropriate) or a component (at which point it would pipe the result of childComponent.renderToStream(...)
into the main stream).
We'd get renderAsync
for free, just by buffering the stream:
const markup = await MyComponent.renderAsync({...});
Doubtless this is slightly more complicated than I'm making it sound.