Skip to content

manually call sheet.seal() during SSR to avoid memory leaks #329

@brunorzn

Description

@brunorzn

This is linked to styled-components/styled-components#1624 (comment)

To avoid memory leaks, we need to manually call sheep.seal during SSR, if any error has been thrown during rendering.

Here is an example :

const sheet = new ServerStyleSheet();
    try {
      const page = await renderPage((App) => (props) => sheet.collectStyles(<App {...props} />));
      const styleTags = sheet.getStyleElement();
      return {
        assets, data, ...page, styleTags,
      };
    } finally {
      sheet.seal();
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions