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