1 | ;
|
2 | 'use client';
|
3 |
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
6 | Object.defineProperty(exports, "__esModule", {
|
7 | value: true
|
8 | });
|
9 | exports.default = void 0;
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
12 | var _utils = require("@mui/utils");
|
13 | var _jsxRuntime = require("react/jsx-runtime");
|
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/material-ui/react-no-ssr/)
|
27 | *
|
28 | * API:
|
29 | *
|
30 | * - [NoSsr API](https://mui.com/material-ui/api/no-ssr/)
|
31 | */
|
32 | function 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 | }
|
55 | process.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 the TypeScript types and run `pnpm 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;
|
76 | if (process.env.NODE_ENV !== 'production') {
|
77 | // eslint-disable-next-line
|
78 | NoSsr['propTypes' + ''] = (0, _utils.exactProp)(NoSsr.propTypes);
|
79 | }
|
80 | var _default = exports.default = NoSsr; |
\ | No newline at end of file |