Material-ui: Toolbar in Dialog Title -> Warning: You cannot call prepareStyles() on the same style object more than once.

Created on 11 May 2016  路  11Comments  路  Source: mui-org/material-ui

I try to use a toolbar in the dialog title:
<Dialog title={<Toolbar></Toolbar>} />

Console output:

Warning: You cannot call prepareStyles() on the same style object more than once.

What am I doing wrong here?

  • Material-UI: v0.15.0
  • React: 15.0.2
  • Browser: Chrome 50

Most helpful comment

What's the resolve to this issue?

Edit: in most case, a workaround is to wrap the component inside a div. For example :

<Dialog title={ <div><Tabs ... /></div> } ... >

All 11 comments

I also get this warning on LinearProgress with something like this

<CardMedia>
...
          <LinearProgress
            key={`progress-buffer-${track.id}`}
            className={s.trackListItemProgressBar}
            mode="determinate"
            value={this.state.buffered}
            max={this.state.duration} />
...
</CardMedia>

I am also getting the same error including a Paper element within a CardText

<CardMedia>
    <Paper zDepth={3}>
        <RemoteApiImage path={answerImage} width={width}/>
    </Paper>
</CardMedia>

Also getting this for:

<Dialog
  title={
    <AppBar
      title="Legg til Rase"
      showMenuIconButton={false}
      style={{paddingTop: "10px", paddingBottom: "10px"}}
    ></AppBar>
  }
  modal={true}
  open={this.props.open}
> ... </Dialog>

Also getting for <CardActions style={{ textAlign: 'center', padding: '0px' }}> ... </CardActions>

Also getting this for <Dialog title={<Tabs ... />} />.

Also getting this when nesting Cards. Seems to be related to getStyles in Paper, but stopped looking.

<Card>
  <Card>
  </Card>
</Card>
  • Material UI 0.16.4

What's the resolve to this issue?

Edit: in most case, a workaround is to wrap the component inside a div. For example :

<Dialog title={ <div><Tabs ... /></div> } ... >

@ochicf and I we have come with a hack that omits this warning: https://github.com/callemall/material-ui/blob/master/src/utils/callOnce.js

Use Case
We wanted to use <Paper/> as the containerElement for a <GridTile/>, it worked but we were getting the annoying warning.

Hack
And I say hack and not solution, because this feels like a total hack:

import React from 'react';
import {Paper} from 'material-ui';
import _ from 'lodash';

class PaperForGridTile extends React.Component {
  render() {
    return (
        <Paper
          {...this.props}
          style={_.omit(this.props.style, [ 'muiPrepared' ])}
        />
    );
  }
}

export default PaperForGridTile;

What is the worst that can happen?

@yanickrochon true, in nested FlatButton in MediaCard also works 馃憤

@yanickrochon Thanks That works for me

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. We changed the styling solution, it's no longer an issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmiddlesworth picture mattmiddlesworth  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

finaiized picture finaiized  路  3Comments

revskill10 picture revskill10  路  3Comments

ericraffin picture ericraffin  路  3Comments