diff --git a/components/server-side-render/README.md b/components/server-side-render/README.md index ae6be3fbf55a1..5b360aa31764d 100644 --- a/components/server-side-render/README.md +++ b/components/server-side-render/README.md @@ -11,7 +11,7 @@ Render core/archives preview. ```jsx ``` diff --git a/components/server-side-render/index.js b/components/server-side-render/index.js index 1d9a9daeefeb0..71364378149da 100644 --- a/components/server-side-render/index.js +++ b/components/server-side-render/index.js @@ -1,7 +1,7 @@ /** * External dependencies. */ -import { isEqual } from 'lodash'; +import { isEqual, isObject, map } from 'lodash'; /** * WordPress dependencies @@ -32,11 +32,7 @@ export class ServerSideRender extends Component { fetch( props ) { this.setState( { response: null } ); - const { block } = props; - const attributes = Object.assign( {}, props ); - - // Delete 'block' from attributes, only registered block attributes are allowed. - delete attributes.block; + const { block, attributes } = props; let apiURL = this.getQueryUrlFromObject( { attributes: attributes, @@ -52,20 +48,12 @@ export class ServerSideRender extends Component { } getQueryUrlFromObject( obj, prefix ) { - const str = []; - let param; - for ( param in obj ) { - if ( obj.hasOwnProperty( param ) ) { - const key = prefix ? prefix + '[' + param + ']' : param, - value = obj[ param ]; - str.push( - ( value !== null && 'object' === typeof value ) ? - this.getQueryUrlFromObject( value, key ) : - encodeURIComponent( key ) + '=' + encodeURIComponent( value ) - ); - } - } - return str.join( '&' ); + return map( obj, ( paramValue, paramName ) => { + const key = prefix ? prefix + '[' + paramName + ']' : paramName, + value = obj[ paramName ]; + return isObject( paramValue ) ? this.getQueryUrlFromObject( value, key ) : + encodeURIComponent( key ) + '=' + encodeURIComponent( value ) + } ).join( '&' ); } render() {