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