threepointone / glamor

inline css for react et al
MIT License
3.66k stars 199 forks source link

Generalize type for html in ServerResults typescript definition #385

Open cdebotton opened 6 years ago

cdebotton commented 6 years ago

Since ReactDOM can now render to a readable stream, this will let us properly return that as the type for the HTML value.

ie)

    const { html, css } = renderStatic(() => renderToNodeStream(app));

    ctx.respond = false;
    ctx.status = 200;
    ctx.res.write(
      '<!doctype html>' +
        '<html lang="en">' +
        '<head>' +
        `<style>${css}</style>` +
        '</head>' +
        '<body>' +
        '<main id="app">',
    );

    html
      .on('end', () => {
        ctx.res.end(
          '</main>' +
            '</body>' +
            '</html>',
        );
      })
      .pipe(ctx.res);
  };