Skip to content

API suggestion: deprecate rewind() and use a closure to prevent leaks and race conditions #23

@ide

Description

@ide

This is a proposal to deprecate the current API for server-side rendering:

let markup = ReactDOM.renderToString(<App />);
let title = DocumentTitle.rewind();

and replace it with this, inspired by Aphrodite's SSR API:

let { title, markup } = DocumentTitle.renderStatic(
  () => ReactDOM.renderToString(<App />)
);

This API has two advantages. It is impossible to forget to call rewind. It is also easy to throw an error if DocumentTitle.renderStatic is called in a reentrant way.

You could use this with Aphrodite easily too. The markup field in the result is whatever you return from the closure (can figure out a better name later -- I just didn't want to call it "html" since it might include CSS):

let { title, markup: { html, css } } = DocumentTitle.renderStatic(
  // Aphrodite.renderStatic() returns { html, css }
  () => Aphrodite.renderStatic(() => ReactDOM.renderToString(<App />))
);

This is easy to build in user-space but I think it might be a strictly better API than rewind() so wanted to start a discussion here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions