Skip to content

Commit

Permalink
[docs] Defer NProgressBar rendering to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 29, 2018
1 parent 89f6c30 commit e5d757d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/material-ui-docs/src/NProgressBar/NProgressBar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import NProgress from 'nprogress';
import React from 'react';
import PropTypes from 'prop-types';
import NProgress from 'nprogress';
import { withStyles } from '@material-ui/core/styles';
import NoSsr from '@material-ui/core/NoSsr';
import exactProp from '@material-ui/core/utils/exactProp';

NProgress.configure({
Expand Down Expand Up @@ -76,20 +78,23 @@ const styles = theme => {
};
};

const GlobalStyles = withStyles(styles, { flip: false })(() => null);

/**
* Elegant and ready to use wrapper on top of https://github.com/rstacruz/nprogress/.
* The implementation is highly inspired by the YouTube version.
* The implementation is highly inspired by the YouTube one.
*/
function NProgressBar(props) {
return props.children;
return (
<NoSsr>
{props.children}
<GlobalStyles />
</NoSsr>
);
}

NProgressBar.propTypes = {
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
};

NProgressBar.propTypes = exactProp(NProgressBar.propTypes, 'NProgressBar');
Expand All @@ -98,4 +103,4 @@ NProgressBar.defaultProps = {
children: null,
};

export default withStyles(styles, { flip: false })(NProgressBar);
export default NProgressBar;

1 comment on commit e5d757d

@oliviertassinari
Copy link
Member Author

Choose a reason for hiding this comment

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

This way, we can reduce the SSR payload and have a faster reconciliation process.

Please sign in to comment.