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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StyledEngineProvider] Fix issue with cache not being defined #36162

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Feb 13, 2023

Fixes #36096, a regression from #36001. The emotion cache provided previously could have been undefined, which was throwing an error. The changes were tested locally, the codesandboxes takes ages to load for me 馃槙

Before: https://codesandbox.io/s/lucid-dan-n6hu29?file=/package.json
After: https://codesandbox.io/s/pensive-violet-on5wym?file=/package.json

@mnajdova mnajdova added bug 馃悰 Something doesn't work package: styled-engine Specific to @mui/styled-engine labels Feb 13, 2023
@mui-bot
Copy link

mui-bot commented Feb 13, 2023

Netlify deploy preview

No updates.

Bundle size report

Details of bundle changes

Generated by 馃毇 dangerJS against a855cd9

@mnajdova mnajdova marked this pull request as ready for review February 13, 2023 08:47
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could write a test for this? Is it possible to remove document at the beginning of the test?

@mnajdova
Copy link
Member Author

I guess we could write a test for this? Is it possible to remove document at the beginning of the test?

The problem with removing the document is that the render from createRenderer no longer works, we will need some kind of a server side rendering util, which I don't think the react-testing-library provides, based on testing-library/react-testing-library#561

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like we could also revert this change and improve the check I added in #36001. For mui/mui-x#7770, I only need to prevent creating the cache if MUI Core is being used inside a web worker. My first idea was to check the presence of document because the error message mentioned this, but checking if importScript is available (there're other approaches too) might be more reliable to avoid false-positives.

@mnajdova
Copy link
Member Author

If you like we could also revert this change and improve the check I added in #36001. For mui/mui-x#7770, I only need to prevent creating the cache if MUI Core is being used inside a web worker. My first idea was to check the presence of document because the error message mentioned this, but checking if importScript is available (there're other approaches too) might be more reliable to avoid false-positives.

@m4theushw can this be conditionally added on MUI X side (for example using StyledEngineProvider only when it makes sense)? In my opinion most of the people would anyway need a custom cache, but seems like it broke quite a lot of people, so maybe it's worth adding the check in MUI Core, for similar scenarios.

@m4theushw
Copy link
Member

can this be conditionally added on MUI X side (for example using StyledEngineProvider only when it makes sense)?

No, we actually don't even use StyledEngineProvider in the web worker. The problem is that as soon as MUI Core is imported the cache is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work package: styled-engine Specific to @mui/styled-engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MUI v5.11.8 release breaks build of NextJS v13.1.6
5 participants