mui / mui/material-ui

No SSR stylesheets when using @mui/styled-engine-sc and yarn 2/3 workspaces

Open
#29,516 9 comments 4 reactions 1 assignee View on GitHub

@mnajdova is already working on this.

Since Nov 5, 2021.

external dependency package: styled-engine-sc scope: system
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

The problem is that server side generated styles do not get attached to the html for the production build.

My stack:

  • Yarn 3 with workspaces
  • Nextjs
  • Material-ui v5 with styled components
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

This is what a page looks like with an icon:
image

The same problem occurs for regular components. Check http://localhost:3000/component in the repro project for this.

Expected Behavior 🤔

This is what it looks like in dev, and should look like in prod:
image

Steps to Reproduce 🕹

Since there are several technologies involved, here is a full reproduction repository:
https://github.com/tobilen/mui5-sc-workspaces-issue

The steps necessary to reproduce are mentioned in the readme.

Context 🔦

I believe i have narrowed the problem down to the lack of dependency hoisting in yarn berry. This can be observed when removing the styled-components dependency from the root package.json, as doing this will mean that there is only one version of it in the project. I've detailed this in the repro project readme.

This would howver not work as a solution, since sibling workspaces with a styled-components dependency cause the same issue.

Your Environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 11.6
  Binaries:
    Node: 15.13.0 - ~/.asdf/installs/nodejs/15.13.0/bin/node
    Yarn: 3.1.0 - ~/.asdf/shims/yarn
    npm: 7.7.6 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 95.0.4638.69
    Edge: Not Found
    Firefox: 93.0
    Safari: 15.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.