@wordpress/server-side-render 6.1.0 → 6.2.1-next.719a03cbe.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.2.0 (2025-06-25)
6
+
5
7
  ## 6.1.0 (2025-06-04)
6
8
 
7
9
  ## 6.0.0 (2025-05-22)
package/README.md CHANGED
@@ -52,31 +52,12 @@ Examples: "my-custom-server-side-rendered".
52
52
 
53
53
  ### httpMethod
54
54
 
55
- The HTTP request method to use, either 'GET' or 'POST'. It's 'GET' by default. The 'POST' value will cause an error on WP earlier than 5.5, unless 'rest_endpoints' is filtered in PHP to allow this. If 'POST', this sends the attributes in the request body, not in the URL. This can allow a bigger attributes object.
55
+ The HTTP request method to use is either `GET` or `POST`, with `GET` as the default. When using `POST`, attributes are sent in the request body rather than the URL, allowing for a larger attributes object.
56
56
 
57
57
  - Type: `String`
58
58
  - Required: No
59
59
  - Default: 'GET'
60
60
 
61
- #### Example:
62
-
63
- ```php
64
- function add_rest_method( $endpoints ) {
65
- if ( is_wp_version_compatible( '5.5' ) ) {
66
- return $endpoints;
67
- }
68
-
69
- foreach ( $endpoints as $route => $handler ) {
70
- if ( isset( $endpoints[ $route ][0] ) ) {
71
- $endpoints[ $route ][0]['methods'] = [ WP_REST_Server::READABLE, WP_REST_Server::CREATABLE ];
72
- }
73
- }
74
-
75
- return $endpoints;
76
- }
77
- add_filter( 'rest_endpoints', 'add_rest_method');
78
- ```
79
-
80
61
  ### skipBlockSupportAttributes
81
62
 
82
63
  Remove attributes and style properties applied by the block supports. This prevents duplication of styles in the block wrapper and the `ServerSideRender` components. Even if certain features skip serialization to HTML markup by `__experimentalSkipSerialization`, all attributes and style properties are removed.
package/build/index.js CHANGED
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.default = ExportedServerSideRender;
8
8
  var _element = require("@wordpress/element");
9
9
  var _data = require("@wordpress/data");
10
10
  var _serverSideRender = _interopRequireDefault(require("./server-side-render"));
@@ -20,29 +20,22 @@ var _jsxRuntime = require("react/jsx-runtime");
20
20
  /**
21
21
  * Constants
22
22
  */const EMPTY_OBJECT = {};
23
- const ExportedServerSideRender = (0, _data.withSelect)(select => {
24
- // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
25
- // It is used by blocks that can be loaded into a *non-post* block editor.
26
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
27
- const coreEditorSelect = select('core/editor');
28
- if (coreEditorSelect) {
29
- const currentPostId = coreEditorSelect.getCurrentPostId();
23
+ function ExportedServerSideRender({
24
+ urlQueryArgs = EMPTY_OBJECT,
25
+ ...props
26
+ }) {
27
+ const currentPostId = (0, _data.useSelect)(select => {
28
+ // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
29
+ // It is used by blocks that can be loaded into a *non-post* block editor.
30
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
31
+ const postId = select('core/editor')?.getCurrentPostId();
32
+
30
33
  // For templates and template parts we use a custom ID format.
31
34
  // Since they aren't real posts, we don't want to use their ID
32
35
  // for server-side rendering. Since they use a string based ID,
33
36
  // we can assume real post IDs are numbers.
34
- if (currentPostId && typeof currentPostId === 'number') {
35
- return {
36
- currentPostId
37
- };
38
- }
39
- }
40
- return EMPTY_OBJECT;
41
- })(({
42
- urlQueryArgs = EMPTY_OBJECT,
43
- currentPostId,
44
- ...props
45
- }) => {
37
+ return postId && typeof postId === 'number' ? postId : null;
38
+ }, []);
46
39
  const newUrlQueryArgs = (0, _element.useMemo)(() => {
47
40
  if (!currentPostId) {
48
41
  return urlQueryArgs;
@@ -56,6 +49,5 @@ const ExportedServerSideRender = (0, _data.withSelect)(select => {
56
49
  urlQueryArgs: newUrlQueryArgs,
57
50
  ...props
58
51
  });
59
- });
60
- var _default = exports.default = ExportedServerSideRender;
52
+ }
61
53
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_data","_serverSideRender","_interopRequireDefault","_jsxRuntime","EMPTY_OBJECT","ExportedServerSideRender","withSelect","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","useMemo","post_id","jsx","default","_default","exports"],"sources":["@wordpress/server-side-render/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nexport default ExportedServerSideRender;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoD,IAAAI,WAAA,GAAAJ,OAAA;AATpD;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA,GACA,MAAMK,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAMC,wBAAwB,GAAG,IAAAC,gBAAU,EAAIC,MAAM,IAAM;EAC1D;EACA;EACA;EACA,MAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAc,CAAC;EAChD,IAAKC,gBAAgB,EAAG;IACvB,MAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAgB,CAAC,CAAC;IACzD;IACA;IACA;IACA;IACA,IAAKD,aAAa,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAG;MACzD,OAAO;QACNA;MACD,CAAC;IACF;EACD;EACA,OAAOL,YAAY;AACpB,CAAE,CAAC,CAAE,CAAE;EAAEO,YAAY,GAAGP,YAAY;EAAEK,aAAa;EAAE,GAAGG;AAAM,CAAC,KAAM;EACpE,MAAMC,eAAe,GAAG,IAAAC,gBAAO,EAAE,MAAM;IACtC,IAAK,CAAEL,aAAa,EAAG;MACtB,OAAOE,YAAY;IACpB;IACA,OAAO;MACNI,OAAO,EAAEN,aAAa;MACtB,GAAGE;IACJ,CAAC;EACF,CAAC,EAAE,CAAEF,aAAa,EAAEE,YAAY,CAAG,CAAC;EAEpC,oBAAO,IAAAR,WAAA,CAAAa,GAAA,EAACf,iBAAA,CAAAgB,OAAgB;IAACN,YAAY,EAAGE,eAAiB;IAAA,GAAMD;EAAK,CAAI,CAAC;AAC1E,CAAE,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAEWZ,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_data","_serverSideRender","_interopRequireDefault","_jsxRuntime","EMPTY_OBJECT","ExportedServerSideRender","urlQueryArgs","props","currentPostId","useSelect","select","postId","getCurrentPostId","newUrlQueryArgs","useMemo","post_id","jsx","default"],"sources":["@wordpress/server-side-render/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nexport default function ExportedServerSideRender( {\n\turlQueryArgs = EMPTY_OBJECT,\n\t...props\n} ) {\n\tconst currentPostId = useSelect( ( select ) => {\n\t\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\tconst postId = select( 'core/editor' )?.getCurrentPostId();\n\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\treturn postId && typeof postId === 'number' ? postId : null;\n\t}, [] );\n\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoD,IAAAI,WAAA,GAAAJ,OAAA;AATpD;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA,GACA,MAAMK,YAAY,GAAG,CAAC,CAAC;AAER,SAASC,wBAAwBA,CAAE;EACjDC,YAAY,GAAGF,YAAY;EAC3B,GAAGG;AACJ,CAAC,EAAG;EACH,MAAMC,aAAa,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC9C;IACA;IACA;IACA,MAAMC,MAAM,GAAGD,MAAM,CAAE,aAAc,CAAC,EAAEE,gBAAgB,CAAC,CAAC;;IAE1D;IACA;IACA;IACA;IACA,OAAOD,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,IAAI;EAC5D,CAAC,EAAE,EAAG,CAAC;EAEP,MAAME,eAAe,GAAG,IAAAC,gBAAO,EAAE,MAAM;IACtC,IAAK,CAAEN,aAAa,EAAG;MACtB,OAAOF,YAAY;IACpB;IACA,OAAO;MACNS,OAAO,EAAEP,aAAa;MACtB,GAAGF;IACJ,CAAC;EACF,CAAC,EAAE,CAAEE,aAAa,EAAEF,YAAY,CAAG,CAAC;EAEpC,oBAAO,IAAAH,WAAA,CAAAa,GAAA,EAACf,iBAAA,CAAAgB,OAAgB;IAACX,YAAY,EAAGO,eAAiB;IAAA,GAAMN;EAAK,CAAI,CAAC;AAC1E","ignoreList":[]}
@@ -79,22 +79,16 @@ function DefaultErrorResponsePlaceholder({
79
79
  });
80
80
  }
81
81
  function DefaultLoadingResponsePlaceholder({
82
- children,
83
- isLoading
82
+ children
84
83
  }) {
85
84
  const [showLoader, setShowLoader] = (0, _element.useState)(false);
86
85
  (0, _element.useEffect)(() => {
87
- if (!isLoading) {
88
- setShowLoader(false);
89
- return;
90
- }
91
-
92
86
  // Schedule showing the Spinner after 1 second.
93
87
  const timeout = setTimeout(() => {
94
88
  setShowLoader(true);
95
89
  }, 1000);
96
90
  return () => clearTimeout(timeout);
97
- }, [isLoading]);
91
+ }, []);
98
92
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
99
93
  style: {
100
94
  position: 'relative'
@@ -208,7 +202,6 @@ function ServerSideRender(props) {
208
202
  if (isLoading) {
209
203
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingResponsePlaceholder, {
210
204
  ...props,
211
- isLoading: isLoading,
212
205
  children: hasResponse && !hasError && /*#__PURE__*/(0, _jsxRuntime.jsx)(_element.RawHTML, {
213
206
  className: className,
214
207
  children: response
@@ -1 +1 @@
1
- {"version":3,"names":["_es","_interopRequireDefault","require","_compose","_element","_i18n","_apiFetch","_url","_components","_blocks","_jsxRuntime","EMPTY_OBJECT","rendererPath","block","attributes","urlQueryArgs","addQueryArgs","context","removeBlockSupportAttributes","backgroundColor","borderColor","fontFamily","fontSize","gradient","textColor","className","restAttributes","border","color","elements","spacing","typography","restStyles","style","DefaultEmptyResponsePlaceholder","jsx","Placeholder","children","__","DefaultErrorResponsePlaceholder","response","errorMessage","sprintf","errorMsg","DefaultLoadingResponsePlaceholder","isLoading","showLoader","setShowLoader","useState","useEffect","timeout","setTimeout","clearTimeout","jsxs","position","top","left","marginTop","marginLeft","Spinner","opacity","ServerSideRender","props","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","useRef","fetchRequestRef","setResponse","prevProps","usePrevious","setIsLoading","latestPropsRef","useLayoutEffect","current","fetchData","useCallback","_sanitizedAttributes","_sanitizedAttributes2","skipBlockSupportAttributes","httpMethod","sanitizedAttributes","__experimentalSanitizeBlockAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","apiFetch","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","useDebounce","undefined","fastDeepEqual","hasResponse","hasEmptyResponse","hasError","RawHTML"],"sources":["@wordpress/server-side-render/src/server-side-render.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport {\n\tRawHTML,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nconst EMPTY_OBJECT = {};\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nexport function removeBlockSupportAttributes( attributes ) {\n\tconst {\n\t\tbackgroundColor,\n\t\tborderColor,\n\t\tfontFamily,\n\t\tfontSize,\n\t\tgradient,\n\t\ttextColor,\n\t\tclassName,\n\t\t...restAttributes\n\t} = attributes;\n\n\tconst { border, color, elements, spacing, typography, ...restStyles } =\n\t\tattributes?.style || EMPTY_OBJECT;\n\n\treturn {\n\t\t...restAttributes,\n\t\tstyle: restStyles,\n\t};\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, isLoading } ) {\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\tsetShowLoader( false );\n\t\t\treturn;\n\t\t}\n\n\t\t// Schedule showing the Spinner after 1 second.\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tclassName,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst latestPropsRef = useRef( props );\n\n\tuseLayoutEffect( () => {\n\t\tlatestPropsRef.current = props;\n\t}, [ props ] );\n\n\tconst fetchData = useCallback( () => {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tattributes,\n\t\t\tblock,\n\t\t\tskipBlockSupportAttributes = false,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs,\n\t\t} = latestPropsRef.current;\n\n\t\tsetIsLoading( true );\n\n\t\tlet sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\tif ( skipBlockSupportAttributes ) {\n\t\t\tsanitizedAttributes =\n\t\t\t\tremoveBlockSupportAttributes( sanitizedAttributes );\n\t\t}\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}, [] );\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect( () => {\n\t\tisMountedRef.current = true;\n\t\treturn () => {\n\t\t\tisMountedRef.current = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible.\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! fastDeepEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = !! response?.error;\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } isLoading={ isLoading }>\n\t\t\t\t{ hasResponse && ! hasError && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAQA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAA0E,IAAAQ,WAAA,GAAAR,OAAA;AArB1E;AACA;AACA;;AAGA;AACA;AACA;;AAgBA,MAAMS,YAAY,GAAG,CAAC,CAAC;AAEhB,SAASC,YAAYA,CAAEC,KAAK,EAAEC,UAAU,GAAG,IAAI,EAAEC,YAAY,GAAG,CAAC,CAAC,EAAG;EAC3E,OAAO,IAAAC,iBAAY,EAAE,yBAA0BH,KAAK,EAAG,EAAE;IACxDI,OAAO,EAAE,MAAM;IACf,IAAK,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ACjDoC,kBAAkB,CAAC,CAAC;IACrB;EACD,CAAE,CAAC;EAEH,MAAMI,WAAW,GAAG,CAAC,CAAE9D,QAAQ;EAC/B,MAAM+D,gBAAgB,GAAG/D,QAAQ,KAAK,EAAE;EACxC,MAAMgE,QAAQ,GAAG,CAAC,CAAEhE,QAAQ,EAAEuD,KAAK;EAEnC,IAAKlD,SAAS,EAAG;IAChB,oBACC,IAAAnC,WAAA,CAAAyB,GAAA,EAAC8B,0BAA0B;MAAA,GAAMH,KAAK;MAAGjB,SAAS,EAAGA,SAAW;MAAAR,QAAA,EAC7DiE,WAAW,IAAI,CAAEE,QAAQ,iBAC1B,IAAA9F,WAAA,CAAAyB,GAAA,EAAC/B,QAAA,CAAAqG,OAAO;QAAChF,SAAS,EAAGA,SAAW;QAAAY,QAAA,EAAGG;MAAQ,CAAW;IACtD,CAC0B,CAAC;EAE/B;EAEA,IAAK+D,gBAAgB,IAAI,CAAED,WAAW,EAAG;IACxC,oBAAO,IAAA5F,WAAA,CAAAyB,GAAA,EAAC4B,wBAAwB;MAAA,GAAMD;IAAK,CAAI,CAAC;EACjD;EAEA,IAAK0C,QAAQ,EAAG;IACf,oBAAO,IAAA9F,WAAA,CAAAyB,GAAA,EAAC6B,wBAAwB;MAACxB,QAAQ,EAAGA,QAAU;MAAA,GAAMsB;IAAK,CAAI,CAAC;EACvE;EAEA,oBAAO,IAAApD,WAAA,CAAAyB,GAAA,EAAC/B,QAAA,CAAAqG,OAAO;IAAChF,SAAS,EAAGA,SAAW;IAAAY,QAAA,EAAGG;EAAQ,CAAW,CAAC;AAC/D","ignoreList":[]}
1
+ {"version":3,"names":["_es","_interopRequireDefault","require","_compose","_element","_i18n","_apiFetch","_url","_components","_blocks","_jsxRuntime","EMPTY_OBJECT","rendererPath","block","attributes","urlQueryArgs","addQueryArgs","context","removeBlockSupportAttributes","backgroundColor","borderColor","fontFamily","fontSize","gradient","textColor","className","restAttributes","border","color","elements","spacing","typography","restStyles","style","DefaultEmptyResponsePlaceholder","jsx","Placeholder","children","__","DefaultErrorResponsePlaceholder","response","errorMessage","sprintf","errorMsg","DefaultLoadingResponsePlaceholder","showLoader","setShowLoader","useState","useEffect","timeout","setTimeout","clearTimeout","jsxs","position","top","left","marginTop","marginLeft","Spinner","opacity","ServerSideRender","props","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","useRef","fetchRequestRef","setResponse","prevProps","usePrevious","isLoading","setIsLoading","latestPropsRef","useLayoutEffect","current","fetchData","useCallback","_sanitizedAttributes","_sanitizedAttributes2","skipBlockSupportAttributes","httpMethod","sanitizedAttributes","__experimentalSanitizeBlockAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","apiFetch","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","useDebounce","undefined","fastDeepEqual","hasResponse","hasEmptyResponse","hasError","RawHTML"],"sources":["@wordpress/server-side-render/src/server-side-render.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport {\n\tRawHTML,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nconst EMPTY_OBJECT = {};\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nexport function removeBlockSupportAttributes( attributes ) {\n\tconst {\n\t\tbackgroundColor,\n\t\tborderColor,\n\t\tfontFamily,\n\t\tfontSize,\n\t\tgradient,\n\t\ttextColor,\n\t\tclassName,\n\t\t...restAttributes\n\t} = attributes;\n\n\tconst { border, color, elements, spacing, typography, ...restStyles } =\n\t\tattributes?.style || EMPTY_OBJECT;\n\n\treturn {\n\t\t...restAttributes,\n\t\tstyle: restStyles,\n\t};\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children } ) {\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\n\tuseEffect( () => {\n\t\t// Schedule showing the Spinner after 1 second.\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [] );\n\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tclassName,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst latestPropsRef = useRef( props );\n\n\tuseLayoutEffect( () => {\n\t\tlatestPropsRef.current = props;\n\t}, [ props ] );\n\n\tconst fetchData = useCallback( () => {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tattributes,\n\t\t\tblock,\n\t\t\tskipBlockSupportAttributes = false,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs,\n\t\t} = latestPropsRef.current;\n\n\t\tsetIsLoading( true );\n\n\t\tlet sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\tif ( skipBlockSupportAttributes ) {\n\t\t\tsanitizedAttributes =\n\t\t\t\tremoveBlockSupportAttributes( sanitizedAttributes );\n\t\t}\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}, [] );\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect( () => {\n\t\tisMountedRef.current = true;\n\t\treturn () => {\n\t\t\tisMountedRef.current = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible.\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! fastDeepEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = !! response?.error;\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props }>\n\t\t\t\t{ hasResponse && ! hasError && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAQA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAA0E,IAAAQ,WAAA,GAAAR,OAAA;AArB1E;AACA;AACA;;AAGA;AACA;AACA;;AAgBA,MAAMS,YAAY,GAAG,CAAC,CAAC;AAEhB,SAASC,YAAYA,CAAEC,KAAK,EAAEC,UAAU,GAAG,IAAI,EAAEC,YAAY,GAAG,CAAC,CAAC,EAAG;EAC3E,OAAO,IAAAC,iBAAY,EAAE,yBAA0BH,KAAK,EAAG,EAAE;IACxDI,OAAO,EAAE,MAAM;IACf,IAAK,IAAI,KAAKH,UAAU,GAAG;MAAEA;IAAW,CAAC,GAAG,CAAC,CAAC,CAAE;IAChD,GAAGC;EACJ,CAAE,CAAC;AACJ;AAEO,SAASG,4BAA4BA,CAAEJ,UAAU,EAAG;EAC1D,MAAM;IACLK,eAAe;IACfC,WAAW;IACXC,UAAU;IACVC,QAAQ;IACRC,QAAQ;IACRC,SAAS;IACTC,SAAS;IACT,GAAGC;EACJ,CAAC,GAAGZ,UAAU;EAEd,MAAM;IAAEa,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,OAAO;IAAEC,UAAU;IAAE,GAAGC;EAAW,CAAC,GACpElB,UAAU,EAAEmB,KAAK,IAAItB,YAAY;EAElC,OAAO;IACN,GAAGe,cAAc;IACjBO,KAAK,EAAED;EAC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AA5F,WAAA,CAAAyB,GAAA,EAAC2B,wBAAwB;MAAA,GAAMD;IAAK,CAAI,CAAC;EACjD;EAEA,IAAK2C,QAAQ,EAAG;IACf,oBAAO,IAAA9F,WAAA,CAAAyB,GAAA,EAAC4B,wBAAwB;MAACvB,QAAQ,EAAGA,QAAU;MAAA,GAAMqB;IAAK,CAAI,CAAC;EACvE;EAEA,oBAAO,IAAAnD,WAAA,CAAAyB,GAAA,EAAC/B,QAAA,CAAAqG,OAAO;IAAChF,SAAS,EAAGA,SAAW;IAAAY,QAAA,EAAGG;EAAQ,CAAW,CAAC;AAC/D","ignoreList":[]}
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useMemo } from '@wordpress/element';
5
- import { withSelect } from '@wordpress/data';
5
+ import { useSelect } from '@wordpress/data';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -14,29 +14,22 @@ import ServerSideRender from './server-side-render';
14
14
  */
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  const EMPTY_OBJECT = {};
17
- const ExportedServerSideRender = withSelect(select => {
18
- // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
19
- // It is used by blocks that can be loaded into a *non-post* block editor.
20
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
21
- const coreEditorSelect = select('core/editor');
22
- if (coreEditorSelect) {
23
- const currentPostId = coreEditorSelect.getCurrentPostId();
17
+ export default function ExportedServerSideRender({
18
+ urlQueryArgs = EMPTY_OBJECT,
19
+ ...props
20
+ }) {
21
+ const currentPostId = useSelect(select => {
22
+ // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
23
+ // It is used by blocks that can be loaded into a *non-post* block editor.
24
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
25
+ const postId = select('core/editor')?.getCurrentPostId();
26
+
24
27
  // For templates and template parts we use a custom ID format.
25
28
  // Since they aren't real posts, we don't want to use their ID
26
29
  // for server-side rendering. Since they use a string based ID,
27
30
  // we can assume real post IDs are numbers.
28
- if (currentPostId && typeof currentPostId === 'number') {
29
- return {
30
- currentPostId
31
- };
32
- }
33
- }
34
- return EMPTY_OBJECT;
35
- })(({
36
- urlQueryArgs = EMPTY_OBJECT,
37
- currentPostId,
38
- ...props
39
- }) => {
31
+ return postId && typeof postId === 'number' ? postId : null;
32
+ }, []);
40
33
  const newUrlQueryArgs = useMemo(() => {
41
34
  if (!currentPostId) {
42
35
  return urlQueryArgs;
@@ -50,6 +43,5 @@ const ExportedServerSideRender = withSelect(select => {
50
43
  urlQueryArgs: newUrlQueryArgs,
51
44
  ...props
52
45
  });
53
- });
54
- export default ExportedServerSideRender;
46
+ }
55
47
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useMemo","withSelect","ServerSideRender","jsx","_jsx","EMPTY_OBJECT","ExportedServerSideRender","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","post_id"],"sources":["@wordpress/server-side-render/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nexport default ExportedServerSideRender;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,UAAU,QAAQ,iBAAiB;;AAE5C;AACA;AACA;AACA,OAAOC,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAGA,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAMC,wBAAwB,GAAGL,UAAU,CAAIM,MAAM,IAAM;EAC1D;EACA;EACA;EACA,MAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAc,CAAC;EAChD,IAAKC,gBAAgB,EAAG;IACvB,MAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAgB,CAAC,CAAC;IACzD;IACA;IACA;IACA;IACA,IAAKD,aAAa,IAAI,OAAOA,aAAa,KAAK,QAAQ,EAAG;MACzD,OAAO;QACNA;MACD,CAAC;IACF;EACD;EACA,OAAOJ,YAAY;AACpB,CAAE,CAAC,CAAE,CAAE;EAAEM,YAAY,GAAGN,YAAY;EAAEI,aAAa;EAAE,GAAGG;AAAM,CAAC,KAAM;EACpE,MAAMC,eAAe,GAAGb,OAAO,CAAE,MAAM;IACtC,IAAK,CAAES,aAAa,EAAG;MACtB,OAAOE,YAAY;IACpB;IACA,OAAO;MACNG,OAAO,EAAEL,aAAa;MACtB,GAAGE;IACJ,CAAC;EACF,CAAC,EAAE,CAAEF,aAAa,EAAEE,YAAY,CAAG,CAAC;EAEpC,oBAAOP,IAAA,CAACF,gBAAgB;IAACS,YAAY,EAAGE,eAAiB;IAAA,GAAMD;EAAK,CAAI,CAAC;AAC1E,CAAE,CAAC;AAEH,eAAeN,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["useMemo","useSelect","ServerSideRender","jsx","_jsx","EMPTY_OBJECT","ExportedServerSideRender","urlQueryArgs","props","currentPostId","select","postId","getCurrentPostId","newUrlQueryArgs","post_id"],"sources":["@wordpress/server-side-render/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nexport default function ExportedServerSideRender( {\n\turlQueryArgs = EMPTY_OBJECT,\n\t...props\n} ) {\n\tconst currentPostId = useSelect( ( select ) => {\n\t\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\tconst postId = select( 'core/editor' )?.getCurrentPostId();\n\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\treturn postId && typeof postId === 'number' ? postId : null;\n\t}, [] );\n\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,OAAOC,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAGA,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,eAAe,SAASC,wBAAwBA,CAAE;EACjDC,YAAY,GAAGF,YAAY;EAC3B,GAAGG;AACJ,CAAC,EAAG;EACH,MAAMC,aAAa,GAAGR,SAAS,CAAIS,MAAM,IAAM;IAC9C;IACA;IACA;IACA,MAAMC,MAAM,GAAGD,MAAM,CAAE,aAAc,CAAC,EAAEE,gBAAgB,CAAC,CAAC;;IAE1D;IACA;IACA;IACA;IACA,OAAOD,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,IAAI;EAC5D,CAAC,EAAE,EAAG,CAAC;EAEP,MAAME,eAAe,GAAGb,OAAO,CAAE,MAAM;IACtC,IAAK,CAAES,aAAa,EAAG;MACtB,OAAOF,YAAY;IACpB;IACA,OAAO;MACNO,OAAO,EAAEL,aAAa;MACtB,GAAGF;IACJ,CAAC;EACF,CAAC,EAAE,CAAEE,aAAa,EAAEF,YAAY,CAAG,CAAC;EAEpC,oBAAOH,IAAA,CAACF,gBAAgB;IAACK,YAAY,EAAGM,eAAiB;IAAA,GAAML;EAAK,CAAI,CAAC;AAC1E","ignoreList":[]}
@@ -69,22 +69,16 @@ function DefaultErrorResponsePlaceholder({
69
69
  });
70
70
  }
71
71
  function DefaultLoadingResponsePlaceholder({
72
- children,
73
- isLoading
72
+ children
74
73
  }) {
75
74
  const [showLoader, setShowLoader] = useState(false);
76
75
  useEffect(() => {
77
- if (!isLoading) {
78
- setShowLoader(false);
79
- return;
80
- }
81
-
82
76
  // Schedule showing the Spinner after 1 second.
83
77
  const timeout = setTimeout(() => {
84
78
  setShowLoader(true);
85
79
  }, 1000);
86
80
  return () => clearTimeout(timeout);
87
- }, [isLoading]);
81
+ }, []);
88
82
  return /*#__PURE__*/_jsxs("div", {
89
83
  style: {
90
84
  position: 'relative'
@@ -198,7 +192,6 @@ export default function ServerSideRender(props) {
198
192
  if (isLoading) {
199
193
  return /*#__PURE__*/_jsx(LoadingResponsePlaceholder, {
200
194
  ...props,
201
- isLoading: isLoading,
202
195
  children: hasResponse && !hasError && /*#__PURE__*/_jsx(RawHTML, {
203
196
  className: className,
204
197
  children: response
@@ -1 +1 @@
1
- {"version":3,"names":["fastDeepEqual","useDebounce","usePrevious","RawHTML","useCallback","useEffect","useLayoutEffect","useRef","useState","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","__experimentalSanitizeBlockAttributes","jsx","_jsx","jsxs","_jsxs","EMPTY_OBJECT","rendererPath","block","attributes","urlQueryArgs","context","removeBlockSupportAttributes","backgroundColor","borderColor","fontFamily","fontSize","gradient","textColor","className","restAttributes","border","color","elements","spacing","typography","restStyles","style","DefaultEmptyResponsePlaceholder","children","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","isLoading","showLoader","setShowLoader","timeout","setTimeout","clearTimeout","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","fetchRequestRef","setResponse","prevProps","setIsLoading","latestPropsRef","current","fetchData","_sanitizedAttributes","_sanitizedAttributes2","skipBlockSupportAttributes","httpMethod","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","hasResponse","hasEmptyResponse","hasError"],"sources":["@wordpress/server-side-render/src/server-side-render.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport {\n\tRawHTML,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nconst EMPTY_OBJECT = {};\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nexport function removeBlockSupportAttributes( attributes ) {\n\tconst {\n\t\tbackgroundColor,\n\t\tborderColor,\n\t\tfontFamily,\n\t\tfontSize,\n\t\tgradient,\n\t\ttextColor,\n\t\tclassName,\n\t\t...restAttributes\n\t} = attributes;\n\n\tconst { border, color, elements, spacing, typography, ...restStyles } =\n\t\tattributes?.style || EMPTY_OBJECT;\n\n\treturn {\n\t\t...restAttributes,\n\t\tstyle: restStyles,\n\t};\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, isLoading } ) {\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\tsetShowLoader( false );\n\t\t\treturn;\n\t\t}\n\n\t\t// Schedule showing the Spinner after 1 second.\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tclassName,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst latestPropsRef = useRef( props );\n\n\tuseLayoutEffect( () => {\n\t\tlatestPropsRef.current = props;\n\t}, [ props ] );\n\n\tconst fetchData = useCallback( () => {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tattributes,\n\t\t\tblock,\n\t\t\tskipBlockSupportAttributes = false,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs,\n\t\t} = latestPropsRef.current;\n\n\t\tsetIsLoading( true );\n\n\t\tlet sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\tif ( skipBlockSupportAttributes ) {\n\t\t\tsanitizedAttributes =\n\t\t\t\tremoveBlockSupportAttributes( sanitizedAttributes );\n\t\t}\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}, [] );\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect( () => {\n\t\tisMountedRef.current = true;\n\t\treturn () => {\n\t\t\tisMountedRef.current = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible.\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! fastDeepEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = !! response?.error;\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } isLoading={ isLoading }>\n\t\t\t\t{ hasResponse && ! hasError && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,WAAW,EAAEC,WAAW,QAAQ,oBAAoB;AAC7D,SACCC,OAAO,EACPC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACF,oBAAoB;AAC3B,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AAC5D,SAASC,qCAAqC,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE1E,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,OAAO,SAASC,YAAYA,CAAEC,KAAK,EAAEC,UAAU,GAAG,IAAI,EAA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E;EACxC,MAAMmD,QAAQ,GAAG,CAAC,CAAEnD,QAAQ,EAAE4C,KAAK;EAEnC,IAAKxC,SAAS,EAAG;IAChB,oBACChC,IAAA,CAACgD,0BAA0B;MAAA,GAAMH,KAAK;MAAGb,SAAS,EAAGA,SAAW;MAAAN,QAAA,EAC7DmD,WAAW,IAAI,CAAEE,QAAQ,iBAC1B/E,IAAA,CAACd,OAAO;QAAC8B,SAAS,EAAGA,SAAW;QAAAU,QAAA,EAAGE;MAAQ,CAAW;IACtD,CAC0B,CAAC;EAE/B;EAEA,IAAKkD,gBAAgB,IAAI,CAAED,WAAW,EAAG;IACxC,oBAAO7E,IAAA,CAAC8C,wBAAwB;MAAA,GAAMD;IAAK,CAAI,CAAC;EACjD;EAEA,IAAKkC,QAAQ,EAAG;IACf,oBAAO/E,IAAA,CAAC+C,wBAAwB;MAACnB,QAAQ,EAAGA,QAAU;MAAA,GAAMiB;IAAK,CAAI,CAAC;EACvE;EAEA,oBAAO7C,IAAA,CAACd,OAAO;IAAC8B,SAAS,EAAGA,SAAW;IAAAU,QAAA,EAAGE;EAAQ,CAAW,CAAC;AAC/D","ignoreList":[]}
1
+ {"version":3,"names":["fastDeepEqual","useDebounce","usePrevious","RawHTML","useCallback","useEffect","useLayoutEffect","useRef","useState","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","__experimentalSanitizeBlockAttributes","jsx","_jsx","jsxs","_jsxs","EMPTY_OBJECT","rendererPath","block","attributes","urlQueryArgs","context","removeBlockSupportAttributes","backgroundColor","borderColor","fontFamily","fontSize","gradient","textColor","className","restAttributes","border","color","elements","spacing","typography","restStyles","style","DefaultEmptyResponsePlaceholder","children","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","showLoader","setShowLoader","timeout","setTimeout","clearTimeout","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","fetchRequestRef","setResponse","prevProps","isLoading","setIsLoading","latestPropsRef","current","fetchData","_sanitizedAttributes","_sanitizedAttributes2","skipBlockSupportAttributes","httpMethod","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","hasResponse","hasEmptyResponse","hasError"],"sources":["@wordpress/server-side-render/src/server-side-render.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport {\n\tRawHTML,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nconst EMPTY_OBJECT = {};\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nexport function removeBlockSupportAttributes( attributes ) {\n\tconst {\n\t\tbackgroundColor,\n\t\tborderColor,\n\t\tfontFamily,\n\t\tfontSize,\n\t\tgradient,\n\t\ttextColor,\n\t\tclassName,\n\t\t...restAttributes\n\t} = attributes;\n\n\tconst { border, color, elements, spacing, typography, ...restStyles } =\n\t\tattributes?.style || EMPTY_OBJECT;\n\n\treturn {\n\t\t...restAttributes,\n\t\tstyle: restStyles,\n\t};\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children } ) {\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\n\tuseEffect( () => {\n\t\t// Schedule showing the Spinner after 1 second.\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [] );\n\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tclassName,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst latestPropsRef = useRef( props );\n\n\tuseLayoutEffect( () => {\n\t\tlatestPropsRef.current = props;\n\t}, [ props ] );\n\n\tconst fetchData = useCallback( () => {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tattributes,\n\t\t\tblock,\n\t\t\tskipBlockSupportAttributes = false,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs,\n\t\t} = latestPropsRef.current;\n\n\t\tsetIsLoading( true );\n\n\t\tlet sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\tif ( skipBlockSupportAttributes ) {\n\t\t\tsanitizedAttributes =\n\t\t\t\tremoveBlockSupportAttributes( sanitizedAttributes );\n\t\t}\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}, [] );\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect( () => {\n\t\tisMountedRef.current = true;\n\t\treturn () => {\n\t\t\tisMountedRef.current = false;\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible.\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! fastDeepEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = !! response?.error;\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props }>\n\t\t\t\t{ hasResponse && ! hasError && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,WAAW,EAAEC,WAAW,QAAQ,oBAAoB;AAC7D,SACCC,OAAO,EACPC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,E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ACA,IAAK+D,SAAS,KAAKyB,SAAS,EAAG;MAC9BpB,SAAS,CAAC,CAAC;IACZ,CAAC,MAAM,IAAK,CAAEzE,aAAa,CAAEoE,SAAS,EAAEP,KAAM,CAAC,EAAG;MACjD+B,kBAAkB,CAAC,CAAC;IACrB;EACD,CAAE,CAAC;EAEH,MAAME,WAAW,GAAG,CAAC,CAAEjD,QAAQ;EAC/B,MAAMkD,gBAAgB,GAAGlD,QAAQ,KAAK,EAAE;EACxC,MAAMmD,QAAQ,GAAG,CAAC,CAAEnD,QAAQ,EAAE4C,KAAK;EAEnC,IAAKpB,SAAS,EAAG;IAChB,oBACCpD,IAAA,CAAC+C,0BAA0B;MAAA,GAAMH,KAAK;MAAAlB,QAAA,EACnCmD,WAAW,IAAI,CAAEE,QAAQ,iBAC1B/E,IAAA,CAACd,OAAO;QAAC8B,SAAS,EAAGA,SAAW;QAAAU,QAAA,EAAGE;MAAQ,CAAW;IACtD,CAC0B,CAAC;EAE/B;EAEA,IAAKkD,gBAAgB,IAAI,CAAED,WAAW,EAAG;IACxC,oBAAO7E,IAAA,CAAC6C,wBAAwB;MAAA,GAAMD;IAAK,CAAI,CAAC;EACjD;EAEA,IAAKmC,QAAQ,EAAG;IACf,oBAAO/E,IAAA,CAAC8C,wBAAwB;MAAClB,QAAQ,EAAGA,QAAU;MAAA,GAAMgB;IAAK,CAAI,CAAC;EACvE;EAEA,oBAAO5C,IAAA,CAACd,OAAO;IAAC8B,SAAS,EAAGA,SAAW;IAAAU,QAAA,EAAGE;EAAQ,CAAW,CAAC;AAC/D","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/server-side-render",
3
- "version": "6.1.0",
3
+ "version": "6.2.1-next.719a03cbe.0",
4
4
  "description": "The component used with WordPress to server-side render a preview of dynamic blocks to display in the editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,15 +29,15 @@
29
29
  "wpScript": true,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "7.25.7",
32
- "@wordpress/api-fetch": "^7.25.0",
33
- "@wordpress/blocks": "^14.14.0",
34
- "@wordpress/components": "^29.11.0",
35
- "@wordpress/compose": "^7.25.0",
36
- "@wordpress/data": "^10.25.0",
37
- "@wordpress/deprecated": "^4.25.0",
38
- "@wordpress/element": "^6.25.0",
39
- "@wordpress/i18n": "^5.25.0",
40
- "@wordpress/url": "^4.25.0",
32
+ "@wordpress/api-fetch": "^7.26.1-next.719a03cbe.0",
33
+ "@wordpress/blocks": "^14.15.1-next.719a03cbe.0",
34
+ "@wordpress/components": "^29.13.1-next.719a03cbe.0",
35
+ "@wordpress/compose": "^7.26.1-next.719a03cbe.0",
36
+ "@wordpress/data": "^10.26.1-next.719a03cbe.0",
37
+ "@wordpress/deprecated": "^4.26.1-next.719a03cbe.0",
38
+ "@wordpress/element": "^6.26.1-next.719a03cbe.0",
39
+ "@wordpress/i18n": "^6.0.1-next.719a03cbe.0",
40
+ "@wordpress/url": "^4.26.1-next.719a03cbe.0",
41
41
  "fast-deep-equal": "^3.1.3"
42
42
  },
43
43
  "peerDependencies": {
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "d1acd76ffff33ab01f0a948d2f51e5e45c95158d"
50
+ "gitHead": "5e146e949c2765411a8310bcc2641a88d036a6d9"
51
51
  }
package/src/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useMemo } from '@wordpress/element';
5
- import { withSelect } from '@wordpress/data';
5
+ import { useSelect } from '@wordpress/data';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -14,25 +14,23 @@ import ServerSideRender from './server-side-render';
14
14
  */
15
15
  const EMPTY_OBJECT = {};
16
16
 
17
- const ExportedServerSideRender = withSelect( ( select ) => {
18
- // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
19
- // It is used by blocks that can be loaded into a *non-post* block editor.
20
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
21
- const coreEditorSelect = select( 'core/editor' );
22
- if ( coreEditorSelect ) {
23
- const currentPostId = coreEditorSelect.getCurrentPostId();
17
+ export default function ExportedServerSideRender( {
18
+ urlQueryArgs = EMPTY_OBJECT,
19
+ ...props
20
+ } ) {
21
+ const currentPostId = useSelect( ( select ) => {
22
+ // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
23
+ // It is used by blocks that can be loaded into a *non-post* block editor.
24
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
25
+ const postId = select( 'core/editor' )?.getCurrentPostId();
26
+
24
27
  // For templates and template parts we use a custom ID format.
25
28
  // Since they aren't real posts, we don't want to use their ID
26
29
  // for server-side rendering. Since they use a string based ID,
27
30
  // we can assume real post IDs are numbers.
28
- if ( currentPostId && typeof currentPostId === 'number' ) {
29
- return {
30
- currentPostId,
31
- };
32
- }
33
- }
34
- return EMPTY_OBJECT;
35
- } )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {
31
+ return postId && typeof postId === 'number' ? postId : null;
32
+ }, [] );
33
+
36
34
  const newUrlQueryArgs = useMemo( () => {
37
35
  if ( ! currentPostId ) {
38
36
  return urlQueryArgs;
@@ -44,6 +42,4 @@ const ExportedServerSideRender = withSelect( ( select ) => {
44
42
  }, [ currentPostId, urlQueryArgs ] );
45
43
 
46
44
  return <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;
47
- } );
48
-
49
- export default ExportedServerSideRender;
45
+ }
@@ -69,21 +69,16 @@ function DefaultErrorResponsePlaceholder( { response, className } ) {
69
69
  return <Placeholder className={ className }>{ errorMessage }</Placeholder>;
70
70
  }
71
71
 
72
- function DefaultLoadingResponsePlaceholder( { children, isLoading } ) {
72
+ function DefaultLoadingResponsePlaceholder( { children } ) {
73
73
  const [ showLoader, setShowLoader ] = useState( false );
74
74
 
75
75
  useEffect( () => {
76
- if ( ! isLoading ) {
77
- setShowLoader( false );
78
- return;
79
- }
80
-
81
76
  // Schedule showing the Spinner after 1 second.
82
77
  const timeout = setTimeout( () => {
83
78
  setShowLoader( true );
84
79
  }, 1000 );
85
80
  return () => clearTimeout( timeout );
86
- }, [ isLoading ] );
81
+ }, [] );
87
82
 
88
83
  return (
89
84
  <div style={ { position: 'relative' } }>
@@ -227,7 +222,7 @@ export default function ServerSideRender( props ) {
227
222
 
228
223
  if ( isLoading ) {
229
224
  return (
230
- <LoadingResponsePlaceholder { ...props } isLoading={ isLoading }>
225
+ <LoadingResponsePlaceholder { ...props }>
231
226
  { hasResponse && ! hasError && (
232
227
  <RawHTML className={ className }>{ response }</RawHTML>
233
228
  ) }