Skip to content

Commit 0efc81d

Browse files
[docs] Document NoSsr (#12317)
1 parent 59759c2 commit 0efc81d

File tree

20 files changed

+166
-45
lines changed

20 files changed

+166
-45
lines changed

docs/src/modules/components/HomeBackers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
4-
import NoSSR from '@material-ui/core/NoSSR';
4+
import NoSsr from '@material-ui/core/NoSsr';
55
import MarkdownElement from '@material-ui/docs/MarkdownElement';
66

77
const styles = theme => ({
@@ -21,7 +21,7 @@ function HomeBackers(props) {
2121

2222
return (
2323
<div className={classes.root}>
24-
<NoSSR>
24+
<NoSsr>
2525
<MarkdownElement
2626
className={classes.markdownElement}
2727
text={`
@@ -84,7 +84,7 @@ ${[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
8484
.join('')}
8585
`}
8686
/>
87-
</NoSSR>
87+
</NoSsr>
8888
</div>
8989
);
9090
}

docs/src/modules/components/HomeSteps.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FileDownloadIcon from '@material-ui/docs/svgIcons/FileDownload';
1010
import BuildIcon from '@material-ui/icons/Build'; // eslint-disable-line import/no-unresolved
1111
import WhatshotIcon from '@material-ui/icons/Whatshot';
1212
import MarkdownElement from '@material-ui/docs/MarkdownElement';
13-
import NoSSR from '@material-ui/core/NoSSR';
13+
import NoSsr from '@material-ui/core/NoSsr';
1414
import Link from 'docs/src/modules/components/Link';
1515

1616
const styles = theme => ({
@@ -181,9 +181,9 @@ function HomeSteps(props) {
181181
our official marketplace—all built on Material-UI.`}
182182
</Typography>
183183
<Link prefetch href="/premium-themes" className={classes.link}>
184-
<NoSSR>
184+
<NoSsr>
185185
<img className={classes.img} alt="themes" src="/static/images/themes.jpg" />
186-
</NoSSR>
186+
</NoSsr>
187187
</Link>
188188
</div>
189189
<Divider className={classes.divider} />

docs/src/modules/components/withRoot.js

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ const pages = [
101101
{
102102
pathname: '/utils/portal',
103103
},
104+
{
105+
pathname: '/utils/no-ssr',
106+
title: 'No SSR',
107+
},
104108
{
105109
pathname: '/utils/click-away-listener',
106110
},

docs/src/pages/demos/autocomplete/IntegrationReactSelect.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import classNames from 'classnames';
66
import Select from 'react-select';
77
import { withStyles } from '@material-ui/core/styles';
88
import Typography from '@material-ui/core/Typography';
9-
import NoSSR from '@material-ui/core/NoSSR';
9+
import NoSsr from '@material-ui/core/NoSsr';
1010
import TextField from '@material-ui/core/TextField';
1111
import Chip from '@material-ui/core/Chip';
1212
import MenuItem from '@material-ui/core/MenuItem';
@@ -205,7 +205,7 @@ class IntegrationReactSelect extends React.Component {
205205

206206
return (
207207
<div className={classes.root}>
208-
<NoSSR>
208+
<NoSsr>
209209
<Select
210210
classes={classes}
211211
options={suggestions}
@@ -223,7 +223,7 @@ class IntegrationReactSelect extends React.Component {
223223
placeholder="Select multiple countries"
224224
isMulti
225225
/>
226-
</NoSSR>
226+
</NoSsr>
227227
</div>
228228
);
229229
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { withStyles } from '@material-ui/core/styles';
4+
import NoSsr from '@material-ui/core/NoSsr';
5+
import Button from '@material-ui/core/Button';
6+
7+
const styles = theme => ({
8+
button: {
9+
display: 'block',
10+
margin: theme.spacing.unit * 2,
11+
},
12+
});
13+
14+
function SimpleNoSsr(props) {
15+
const { classes } = props;
16+
17+
return (
18+
<div>
19+
<Button className={classes.button} variant="contained" color="primary">
20+
Server & Client
21+
</Button>
22+
<NoSsr>
23+
<Button className={classes.button} variant="contained" color="secondary">
24+
Client only
25+
</Button>
26+
</NoSsr>
27+
</div>
28+
);
29+
}
30+
31+
SimpleNoSsr.propTypes = {
32+
classes: PropTypes.object.isRequired,
33+
};
34+
35+
export default withStyles(styles)(SimpleNoSsr);

docs/src/pages/utils/no-ssr/no-ssr.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: No SSR React component
3+
components: NoSsr
4+
---
5+
6+
# No SSR
7+
8+
<p class="description">NoSsr purposely removes components from the subject of Server Side Rendering (SSR).</p>
9+
10+
This component can be useful in a variety of situations:
11+
- Escape hatch for broken dependencies not supporting SSR.
12+
- Improve the time-to-first paint on the client by only rendering above the fold.
13+
- Reduce the rendering time on the server.
14+
- Under too heavy server load, you can turn on service degradation.
15+
16+
{{"demo": "pages/utils/no-ssr/SimpleNoSsr.js"}}

packages/material-ui/src/NoSSR/NoSSR.d.ts

-10
This file was deleted.

packages/material-ui/src/NoSSR/index.d.ts

-2
This file was deleted.

packages/material-ui/src/NoSSR/index.js

-1
This file was deleted.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
3+
export interface NoSsrProps {
4+
children: React.ReactNode;
5+
fallback?: React.ReactNode;
6+
}
7+
8+
declare const NoSsr: React.ComponentType<NoSsrProps>;
9+
10+
export default NoSsr;

packages/material-ui/src/NoSSR/NoSSR.js packages/material-ui/src/NoSsr/NoSsr.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import exactProp from '../utils/exactProp';
55
const Fallback = () => null;
66

77
/**
8-
* Only render the component on the client.
9-
* It can be useful in a variety of situations:
10-
* - Reduce the rendering time on the server.
11-
* - Under too heavy server load, you can apply service degradation.
12-
* - Improve the time-to-first paint on the client by only rendering above the fold.
8+
* NoSsr purposely removes components from the subject of Server Side Rendering (SSR).
9+
*
10+
* This component can be useful in a variety of situations:
1311
* - Escape hatch for broken dependencies not supporting SSR.
12+
* - Improve the time-to-first paint on the client by only rendering above the fold.
13+
* - Reduce the rendering time on the server.
14+
* - Under too heavy server load, you can turn on service degradation.
1415
*/
15-
class NoSSR extends React.Component {
16+
class NoSsr extends React.Component {
1617
state = {
1718
mounted: false,
1819
};
@@ -28,15 +29,15 @@ class NoSSR extends React.Component {
2829
}
2930
}
3031

31-
NoSSR.propTypes = {
32+
NoSsr.propTypes = {
3233
children: PropTypes.node.isRequired,
3334
fallback: PropTypes.node,
3435
};
3536

36-
NoSSR.propTypes = exactProp(NoSSR.propTypes);
37+
NoSsr.propTypes = exactProp(NoSsr.propTypes);
3738

38-
NoSSR.defaultProps = {
39+
NoSsr.defaultProps = {
3940
fallback: <Fallback />,
4041
};
4142

42-
export default NoSSR;
43+
export default NoSsr;

packages/material-ui/src/NoSSR/NoSSR.test.js packages/material-ui/src/NoSsr/NoSsr.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import React from 'react';
44
import { assert } from 'chai';
55
import { createMount, createShallow } from '../test-utils';
6-
import NoSSR from './NoSSR';
6+
import NoSsr from './NoSsr';
77

8-
describe('<NoSSR />', () => {
8+
describe('<NoSsr />', () => {
99
let mount;
1010
let shallow;
1111

@@ -21,9 +21,9 @@ describe('<NoSSR />', () => {
2121
describe('server side rendering', () => {
2222
it('should not render the children as the width is unknown', () => {
2323
const wrapper = shallow(
24-
<NoSSR>
24+
<NoSsr>
2525
<span>Hello</span>
26-
</NoSSR>,
26+
</NoSsr>,
2727
);
2828
assert.strictEqual(wrapper.name(), 'Fallback');
2929
});
@@ -32,9 +32,9 @@ describe('<NoSSR />', () => {
3232
describe('mounted', () => {
3333
it('should render the children', () => {
3434
const wrapper = mount(
35-
<NoSSR>
35+
<NoSsr>
3636
<span>Hello</span>
37-
</NoSSR>,
37+
</NoSsr>,
3838
);
3939
assert.strictEqual(wrapper.find('span').length, 1);
4040
});
@@ -43,9 +43,9 @@ describe('<NoSSR />', () => {
4343
describe('prop: fallback', () => {
4444
it('should render the fallback', () => {
4545
const wrapper = shallow(
46-
<NoSSR fallback="fallback">
46+
<NoSsr fallback="fallback">
4747
<span>Hello</span>
48-
</NoSSR>,
48+
</NoSsr>,
4949
);
5050
assert.strictEqual(wrapper.text(), 'fallback');
5151
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default } from './NoSsr';
2+
export * from './NoSsr';
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './NoSsr';

packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Drawer, { getAnchor, isHorizontal } from '../Drawer/Drawer';
88
import { duration } from '../styles/transitions';
99
import withTheme from '../styles/withTheme';
1010
import { getTransitionProps } from '../transitions/utils';
11-
import NoSSR from '../NoSSR';
11+
import NoSsr from '../NoSsr';
1212
import SwipeArea from './SwipeArea';
1313

1414
// This value is closed to what browsers are using internally to
@@ -373,9 +373,9 @@ class SwipeableDrawer extends React.Component {
373373
{!disableDiscovery &&
374374
!disableSwipeToOpen &&
375375
variant === 'temporary' && (
376-
<NoSSR>
376+
<NoSsr>
377377
<SwipeArea anchor={anchor} width={swipeAreaWidth} />
378-
</NoSSR>
378+
</NoSsr>
379379
)}
380380
</React.Fragment>
381381
);

packages/material-ui/src/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export { default as MenuList } from './MenuList';
141141
export { default as MobileStepper } from './MobileStepper';
142142
export { default as Modal, ModalManager } from './Modal';
143143
export { default as NativeSelect } from './NativeSelect';
144-
export { default as NoSSR } from './NoSSR';
144+
export { default as NoSsr } from './NoSsr';
145145
export { default as Paper } from './Paper';
146146
export { default as Popover } from './Popover';
147147
export { default as Popper } from './Popper';

packages/material-ui/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export { default as MenuList } from './MenuList';
7474
export { default as MobileStepper } from './MobileStepper';
7575
export { default as Modal, ModalManager } from './Modal';
7676
export { default as NativeSelect } from './NativeSelect';
77-
export { default as NoSSR } from './NoSSR';
77+
export { default as NoSsr } from './NoSsr';
7878
export { default as Paper } from './Paper';
7979
export { default as Popover } from './Popover';
8080
export { default as Popper } from './Popper';

pages/api/no-ssr.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import withRoot from 'docs/src/modules/components/withRoot';
3+
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
4+
import markdown from './no-ssr.md';
5+
6+
function Page() {
7+
return <MarkdownDocs markdown={markdown} />;
8+
}
9+
10+
export default withRoot(Page);

pages/api/no-ssr.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
filename: /packages/material-ui/src/NoSsr/NoSsr.js
3+
title: NoSsr API
4+
---
5+
6+
<!--- This documentation is automatically generated, do not try to edit it. -->
7+
8+
# NoSsr
9+
10+
<p class="description">The API documentation of the NoSsr React component.</p>
11+
12+
NoSsr purposely removes components from the subject of Server Side Rendering (SSR).
13+
14+
This component can be useful in a variety of situations:
15+
- Escape hatch for broken dependencies not supporting SSR.
16+
- Improve the time-to-first paint on the client by only rendering above the fold.
17+
- Reduce the rendering time on the server.
18+
- Under too heavy server load, you can turn on service degradation.
19+
20+
## Props
21+
22+
| Name | Type | Default | Description |
23+
|:-----|:-----|:--------|:------------|
24+
| <span class="prop-name required">children *</span> | <span class="prop-type">node |   | |
25+
| <span class="prop-name">fallback</span> | <span class="prop-type">node | <span class="prop-default">&lt;Fallback /></span> | |
26+
27+
Any other properties supplied will be spread to the root element (native element).
28+
29+
## Demos
30+
31+
- [No Ssr](/utils/no-ssr)
32+

pages/utils/no-ssr.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import withRoot from 'docs/src/modules/components/withRoot';
3+
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
4+
import markdown from 'docs/src/pages/utils/no-ssr/no-ssr.md';
5+
6+
function Page() {
7+
return (
8+
<MarkdownDocs
9+
markdown={markdown}
10+
demos={{
11+
'pages/utils/no-ssr/SimpleNoSsr.js': {
12+
js: require('docs/src/pages/utils/no-ssr/SimpleNoSsr').default,
13+
raw: preval`
14+
module.exports = require('fs')
15+
.readFileSync(require.resolve('docs/src/pages/utils/no-ssr/SimpleNoSsr'), 'utf8')
16+
`,
17+
},
18+
}}
19+
/>
20+
);
21+
}
22+
23+
export default withRoot(Page);

0 commit comments

Comments
 (0)