Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Adding prepend: true to emotion cache breaks remix example #30359

Open
2 tasks done
Tracked by #39765
ShuPink opened this issue Dec 22, 2021 · 6 comments
Open
2 tasks done
Tracked by #39765

[docs] Adding prepend: true to emotion cache breaks remix example #30359

ShuPink opened this issue Dec 22, 2021 · 6 comments
Assignees
Labels
examples Relating to /examples

Comments

@ShuPink
Copy link
Contributor

ShuPink commented Dec 22, 2021

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Adding prepend: true to the emotion cache used in the remix-with-typescript example to modify the injection order of mui styles and global css styles causes DOMExceptions.

remix-prepend

Removing CssBaseline from entry.client.tsx will remove the DOMException, but the hydration warning remains.

Moving the style tag generator in root.tsx also does not help to remove the hydration warning.

Expected behavior 🤔

Expected the mui styles to move from the bottom of the head element to the top of the head element, and the DOM to render without exceptions.

Steps to reproduce 🕹

Steps:

  1. Clone the https://github.com/mui-org/material-ui/blob/master/examples/remix-with-typescript/ example
  2. Add the prepend: true option to createCache in https://github.com/mui-org/material-ui/blob/master/examples/remix-with-typescript/app/src/createEmotionCache.ts
import createCache from '@emotion/cache';

export default function createEmotionCache() {
  return createCache({ key: 'css', prepend: true });
}
  1. npm install, npm run dev and open in the browser

Context 🔦

Trying to reduce the precedence of mui when interoperating with other style methods (e.g. using global styles)

Your environment 🌎

`npx @mui/envinfo`
 System:
    OS: Linux 4.4 Ubuntu 18.04.4 LTS (Bionic Beaver)
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.10 - /mnt/c/Program Files (x86)/Yarn/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @emotion/react: latest => 11.7.1 
    @emotion/styled: latest => 11.6.0 
    @mui/base:  5.0.0-alpha.61 
    @mui/material: latest => 5.2.5 
    @mui/private-theming:  5.2.3 
    @mui/styled-engine:  5.2.5 
    @mui/system:  5.2.5 
    @mui/types:  7.1.0 
    @mui/utils:  5.2.3 
    @types/react: latest => 17.0.37 
    react: latest => 17.0.2 
    react-dom: latest => 17.0.2 
    typescript: latest => 4.5.4 

Browser used: Firefox
@ShuPink ShuPink added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 22, 2021
@hbjORbj hbjORbj changed the title [docs] Adding prepend: true to emotion cache breaks remix example [docs] Adding prepend: true to emotion cache breaks remix example Dec 22, 2021
@ShuPink
Copy link
Contributor Author

ShuPink commented Dec 23, 2021

@mnajdova I'm not sure why I can't see your reply here... so I guess I'll just look like I'm talking to myself 😅 .

Sorry for not being very clear, I was trying to make my global/shared styles take precedence over mui's because mui's styles would override them.
Hopefully this picture might make it clearer: green = global css file, and blue = mui styles.

global css file being overridden by mui
remix-style

document head element style tag order
remix-head-mu

Um, but I actually managed to get the prepend: true option working with the emotion cache as expected by removing the block that you mentioned: https://github.com/mui-org/material-ui/blob/master/examples/remix-with-typescript/app/root.tsx#L25, so I'll close the issue.

Thanks very much for your time, apologies for the muck about.

@ShuPink ShuPink closed this as completed Dec 23, 2021
@yannickpschroeder
Copy link

@ShuPink I got the same Issue and was not able to get prepend: true working. Are you sure you just removed that eslint-comment? I also removed the whole block and it still overrides my styles defined in the Remix Links function. May you do a pull request with your fixes, so I can directly compare the code. :)

@ShuPink
Copy link
Contributor Author

ShuPink commented Feb 10, 2022

@yannickpschroeder hmm that link was probably not the best work on my part.
This example has undergone some rework and it was pointing at a block of code in the example which has since been removed.

I didn't submit a PR as I'm not so sure about the way forward with this issue, since I don't really know how to resolve it properly.
I'm actually not very familiar with remix, but I did upload a branch off my fork if you want to look at it.

ShuPink@7d64cc6

I can only get rid of the error by:

  • A. Removing CssBaseline
  • B. Removing the injection of styles on entry.server.tsx and root.tsx - but this results in a FOUC , I don't know how to fix this, so not really an appropriate solution.

I also tried moving the <meta name="emotion-insertion-point" content="emotion-insertion-point" /> in root.tsx to the top of the head but it had no effect unfortunately.

I also tried it in a sandbox, without removing the styles from entry.server.tsx and for some reason prepend worked normally... so I am lost.
https://stackblitz.com/edit/github-o2dcek?file=app%2Froutes%2Findex.tsx

I don't know if any of that will help but hopefully it can give you some clues.
Might be best to open a new issue 😞

@mnajdova mnajdova added examples Relating to /examples and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 31, 2022
@mnajdova
Copy link
Member

Sorry for coming a bit late, but it was misleading as the issue was closed. Was this resolved? Can you still see the problem?

@mnajdova mnajdova added the status: waiting for author Issue with insufficient information label May 31, 2022
@ShuPink
Copy link
Contributor Author

ShuPink commented Jun 1, 2022

I originally resolved this issue by removing the global styles, but the remix example was also being updated to remove a double rendering issue which I thought also resolved this error.
#30366

After this PR when I tried to resolve the issue for yannickpschroeder, I couldn't resolve the hydration error that came with css: prepend` consistently (it worked on stackblitz but failed in my local environment).
I wasn't sure what to do from that point onwards.

Not sure if this issue will be resolved with this PR?
#32104

or.. is that why this issue has been reopened 😕

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jun 1, 2022
@mnajdova
Copy link
Member

mnajdova commented Jun 1, 2022

@ShuPink there is definitely some issue with the Remix example, e. g. #31957. I will need to dive deeper before I can share any update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Relating to /examples
Projects
None yet
Development

No branches or pull requests

5 participants