question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning "Material-UI: this elevation `1` is not implemented" with disableGeneration to true

See original GitHub issue
  • 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 😯

Error message

Expected Behavior 🤔

No warning should occur.

Steps to Reproduce 🕹

This issue happens in SSR. On the server. We use ServerStyleSheets with disableGeneration to true (for performance gains).

const sheetsPrepass = new ServerStyleSheets({ disableGeneration: true }); and wrap the react element such as this sheetsPrepass.collect(reactElement).

The issue occurs only when disableGeneration is set to true.

I think this is due to this. classes is empty with disableGeneration on the server, while it’s not in other cases. I’m not sure how it should be fixed though.

https://github.com/mui-org/material-ui/blob/51b2b927cf31b59f16dbe7d2a51ef1ee111845cc/packages/material-ui/src/Paper/Paper.js#L44-L49

I don’t think a codesandbox si necessary here as most of the information is there.

Thank you 🚀 !

Tech Version
Material-UI v4.9.5
React v16.12.0
Browser NodeJS on the server

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Sep 5, 2020

@nesso-pfl I don’t think that we can use the prop-type check anymore. Something in this order (maybe need to improve the warning message)

diff --git a/packages/material-ui/src/Paper/Paper.js b/packages/material-ui/src/Paper/Paper.js
index b1431b60d4..6cf24d052b 100644
--- a/packages/material-ui/src/Paper/Paper.js
+++ b/packages/material-ui/src/Paper/Paper.js
@@ -1,9 +1,9 @@
 import * as React from 'react';
 import PropTypes from 'prop-types';
 import clsx from 'clsx';
-import { chainPropTypes } from '@material-ui/utils';
 import { useThemeVariants } from '@material-ui/styles';
 import withStyles from '../styles/withStyles';
+import useTheme from '../styles/useTheme';

 export const styles = (theme) => {
   const elevations = {};
@@ -56,6 +56,14 @@ const Paper = React.forwardRef(function Paper(props, ref) {
     'MuiPaper',
   );

+  if (process.env.NODE_ENV !== 'production') {
+    // eslint-disable-next-line react-hooks/rules-of-hooks
+    const theme = useTheme();
+    if (theme.shadows[elevation] === undefined) {
+      console.warn(`Material-UI: The elevation provided <Paper elevation={${elevation}}> is not available in the theme.`);
+    }
+  }
+
   return (
     <Component
       className={clsx(
@@ -101,17 +109,7 @@ Paper.propTypes = {
    * It accepts values between 0 and 24 inclusive.
    * @default 1
    */
-  elevation: chainPropTypes(PropTypes.number, (props) => {
-    const { classes, elevation } = props;
-    // in case `withStyles` fails to inject we don't need this warning
-    if (classes === undefined) {
-      return null;
-    }
-    if (elevation != null && classes[`elevation${elevation}`] === undefined) {
-      return new Error(`Material-UI: This elevation \`${elevation}\` is not implemented.`);
-    }
-    return null;
-  }),
+  elevation: PropTypes.number,
   /**
    * If `true`, rounded corners are disabled.
    * @default false
1reaction
oliviertassinaricommented, Sep 4, 2020

As far as I know, the problem still stand. We rely on the classes, while we should depend on the theme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning "Material-UI: this elevation 1 is not implemented" with ...
The issue occurs only when disableGeneration is set to true. I think this is due to this. classes is empty with disableGeneration on...
Read more >
Material-UI: "The key provided to the classes property is not ...
I am using the withStyles() HOC to override some MUI component styles, theme and breakpoints. There is obviously something I do not understand ......
Read more >
Paper API - Material UI - MUI
elevation, integer, 1. Shadow depth, corresponds to dp in the spec. It accepts values between 0 and 24 inclusive. square, bool, false. If...
Read more >
Migration from v3 to v4 - Material UI - MUI
This is implemented by using React.forwardRef() . This affects the internal component tree and display name and therefore might break shallow or snapshot...
Read more >
Breaking changes in v5, part two: core components - Material UI
Change the CSS rules that use [data-focus="true"] to use .Mui-focused . The data-focus attribute is not set on the focused option anymore; instead, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found