Skip to content

regression: createGlobalStyle does not remove styles on unmount #4100

Closed

Description

@mdeschamps

Environment

System:

  • OS: macOS 13.4.1
  • CPU: (10) arm64 Apple M1 Max
  • Memory: 5.18 GB / 64.00 GB
  • Shell: 3.2.57 - /bin/bash

Binaries:

  • Node: 18.1.0 - ~/.nvm/versions/node/v18.1.0/bin/node
  • npm: 9.7.2 - ~/.nvm/versions/node/v18.1.0/bin/npm
  • pnpm: 8.6.0 - ~/.nvm/versions/node/v18.1.0/bin/pnpm

npmPackages:

  • babel-plugin-styled-components: ^2.1.4 => 2.1.4
  • styled-components: ^6.0.4 => 6.0.4

Reproduction

In this change https://github.com/styled-components/styled-components/pull/3726/files#diff-b8702cbcaf39eaa95deb156bf4132fef9fd7096c4f87679cf656105070c38bc8R64 @probablyup changed it to conditionally use useInsertionEffect if it exists; but useInsertionEffect does not have a return type: https://react.dev/reference/react/useInsertionEffect#returns

After updating to v6 I started noticing that none of the global styles created by createGlobalStyle are removed after the component is unmounted.

I couldn't come up with a small reproducible case; in a codepen the global styles are removed; but in our app with hundreds of lines in the <style/> those global styles are clearly sticky.

Expected Behavior

Global style is removed when component is unmounted

Actual Behavior

Global styles remain in the stylesheet after component is unmounted

Activity

  1. quantizor commented on Jul 21, 2023

    @quantizor
    Contributor

    That's annoying! Would you be open to shooting over a quick PR to remove use of useInsertionEffect?

  2. mdeschamps commented on Jul 21, 2023

    @mdeschamps
    ContributorAuthor

    That's annoying! Would you be open to shooting over a quick PR to remove use of useInsertionEffect?

    sure thing... PR ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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