UNPKG

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