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.

Snackbar is using a <p> after upgrading to 3.2

See original GitHub issue

I upgraded to 3.2 and set useNextVariants: true and the Snackbar component started using a <p> element for its container, which throws a warning in the browser if you have a <div> as a child.

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Snackbar should use a <div> as its container element.

Current Behavior

Snackbar is using a <p> as its container element.

Steps to Reproduce

Open the live example (https://codesandbox.io/s/82wp5l1jkl) and check the console logs. You’ll see

Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.
    in div (created by App)
    in div (created by SnackbarContent)
    in p (created by Typography)
    in Typography (created by WithStyles(Typography))
    in WithStyles(Typography) (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by SnackbarContent)
    in SnackbarContent (created by WithStyles(SnackbarContent))
    in WithStyles(SnackbarContent) (created by Snackbar)
    in Transition (created by Slide)
    in EventListener (created by Slide)
    in Slide (created by WithTheme(Slide))
    in WithTheme(Slide) (created by Snackbar)
    in div (created by Snackbar)
    in ClickAwayListener (created by Snackbar)
    in Snackbar (created by WithStyles(Snackbar))
    in WithStyles(Snackbar) (created by App)
    in MuiThemeProvider (created by App)
    in App

Here is the same example working with v3.1.2: https://codesandbox.io/s/32p389xr15

I’m guessing it has something to do with this line: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/SnackbarContent/SnackbarContent.js#L55. I’m not passing in a variant for the Typography component, so I don’t think the headlineMapping is getting applied.

I was able to work around this bug by doing:

<Snackbar
  ContentProps={{
    variant: `body1`,
  }}
/>

Your Environment

Tech Version
Material-UI v3.2.0
React 16.5.2
Browser Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

10reactions
eps1loncommented, Oct 10, 2018

While a fix in HEAD is good I failed to add a temporary workaround for everyone affected:

https://codesandbox.io/s/248j265l5r:

-<Snackbar message={<div>Testing</div>} open />
+<Snackbar ContentProps={{
+      headlineMapping: {
+        body1: "div",
+        body2: "div"
+      }
+    }} message={<div>Testing</div>} open />

Basically add to ContentProps the headlineMapping conforming to the above shape.

1reaction
eps1loncommented, Oct 13, 2018

@brauliodiez Sorry I need to manage by sandboxes better. I had to delete everything recently because I reached the free usage limit.

Updated link: https://codesandbox.io/s/zz6wnqklzm (demo.js#71-74)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snackbar is using a <p> after upgrading to 3.2 #13144 - GitHub
I upgraded to 3.2 and set useNextVariants: true and the Snackbar component started using a <p> element for its container, which throws a ......
Read more >
Working with the Floating Action Button and Snackbar
A new Snackbar is then displayed indicating that the last item has been removed from the list.
Read more >
AP Statistics Course and Exam Description, Effective Fall 2020
College Board strongly encourages educators to make equitable access a guiding principle for their AP programs by giving all willing and academically prepared....
Read more >
Stripes Delivery Menu | Order Online | 6511 TX-317 Belton
Turkey & Cheddar Cheese with Crackers Lunchables 3.2oz ... SAVORY SNACK BAR: a perfect on-the-go snack featuring bison, bacon and cranberries with 7...
Read more >
MoY - River Thames Conditions
Busco mayordomo para finca en antioquia, Red yeast rice 1200 with coq10, ... lymph node swelling, Berchtesgaden then and now, Signature nail spa...
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