UNPKG

2.75 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = void 0;
11
12var React = _interopRequireWildcard(require("react"));
13
14var _propTypes = _interopRequireDefault(require("prop-types"));
15
16var _utils = require("@material-ui/utils");
17
18var useEnhancedEffect = typeof window !== 'undefined' && process.env.NODE_ENV !== 'test' ? React.useLayoutEffect : React.useEffect;
19/**
20 * NoSsr purposely removes components from the subject of Server Side Rendering (SSR).
21 *
22 * This component can be useful in a variety of situations:
23 * - Escape hatch for broken dependencies not supporting SSR.
24 * - Improve the time-to-first paint on the client by only rendering above the fold.
25 * - Reduce the rendering time on the server.
26 * - Under too heavy server load, you can turn on service degradation.
27 */
28
29function NoSsr(props) {
30 var children = props.children,
31 _props$defer = props.defer,
32 defer = _props$defer === void 0 ? false : _props$defer,
33 _props$fallback = props.fallback,
34 fallback = _props$fallback === void 0 ? null : _props$fallback;
35
36 var _React$useState = React.useState(false),
37 mountedState = _React$useState[0],
38 setMountedState = _React$useState[1];
39
40 useEnhancedEffect(function () {
41 if (!defer) {
42 setMountedState(true);
43 }
44 }, [defer]);
45 React.useEffect(function () {
46 if (defer) {
47 setMountedState(true);
48 }
49 }, [defer]); // We need the Fragment here to force react-docgen to recognise NoSsr as a component.
50
51 return /*#__PURE__*/React.createElement(React.Fragment, null, mountedState ? children : fallback);
52}
53
54process.env.NODE_ENV !== "production" ? NoSsr.propTypes = {
55 // ----------------------------- Warning --------------------------------
56 // | These PropTypes are generated from the TypeScript type definitions |
57 // | To update them edit the d.ts file and run "yarn proptypes" |
58 // ----------------------------------------------------------------------
59
60 /**
61 * You can wrap a node.
62 */
63 children: _propTypes.default.node,
64
65 /**
66 * If `true`, the component will not only prevent server-side rendering.
67 * It will also defer the rendering of the children into a different screen frame.
68 */
69 defer: _propTypes.default.bool,
70
71 /**
72 * The fallback content to display.
73 */
74 fallback: _propTypes.default.node
75} : void 0;
76
77if (process.env.NODE_ENV !== 'production') {
78 // eslint-disable-next-line
79 NoSsr['propTypes' + ''] = (0, _utils.exactProp)(NoSsr.propTypes);
80}
81
82var _default = NoSsr;
83exports.default = _default;
\No newline at end of file