Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerSideRender: add new skipBlockSupportAttributes prop #44491

Merged
merged 25 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b35e88
ServerSideRender: add new `skipBlockSupportAttributes` prop
t-hamano Sep 27, 2022
2b6ec9a
Update readme
t-hamano Sep 27, 2022
43fde25
update changelog
t-hamano Sep 27, 2022
59a6178
add unit test
t-hamano Sep 27, 2022
b70814f
Fix typo
t-hamano Sep 27, 2022
8791cc3
Don't remove attributes and styles which serialization is omitted
t-hamano Oct 2, 2022
05ab652
Merge branch 'trunk' into enhancement/server-side-render-global-styles
t-hamano Oct 2, 2022
a42b10e
Update unit tests
t-hamano Oct 2, 2022
f1b0670
Update readme
t-hamano Oct 2, 2022
04f3af0
Don't remove custom style
t-hamano Oct 2, 2022
abf2d7e
Support color.link and update tests
t-hamano Oct 2, 2022
e027d44
Update function docs
t-hamano Oct 2, 2022
d9600d6
Revert "Update function docs"
t-hamano Oct 5, 2022
1a7fd7c
Revert "Support color.link and update tests"
t-hamano Oct 5, 2022
43910b2
Revert "Don't remove custom style"
t-hamano Oct 5, 2022
5d811c8
Revert "Update readme"
t-hamano Oct 5, 2022
bd1ff1e
Revert "Update unit tests"
t-hamano Oct 5, 2022
aa507a1
Revert "Don't remove attributes and styles which serialization is omi…
t-hamano Oct 5, 2022
452c11d
Merge branch 'trunk' into enhancement/server-side-render-global-styles
t-hamano Oct 5, 2022
7b02d8d
Don't pass className
t-hamano Oct 5, 2022
4be4688
Update unit test
t-hamano Oct 5, 2022
ce8937a
Update readme
t-hamano Oct 7, 2022
d58e60c
Update readme
t-hamano Oct 7, 2022
60e711d
Fix conflicts
t-hamano Oct 7, 2022
0de5c1f
Revert unexpected changes
t-hamano Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/server-side-render/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Feature

- Add `skipBlockSupportAttributes` props to prevent duplication of styles in the block wrapper and the `ServerSideRender` components. [#44491](https://github.com/WordPress/gutenberg/pull/44491)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the description is unnatural, please feel free to update it 🙏


## 3.16.0 (2022-09-21)

## 3.15.0 (2022-09-13)
Expand Down
7 changes: 7 additions & 0 deletions packages/server-side-render/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function add_rest_method( $endpoints ) {
add_filter( 'rest_endpoints', 'add_rest_method');
```

### skipBlockSupportAttributes

Remove attributes and style properties applied by the block supports. This prevents duplication of styles in the block wrapper and the `ServerSideRender` components. Attributes and styles provided by the block supports for which `__experimentalSkipSerialization` is specified will not be removed.

- Type: `Boolean`
- Required: No
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

### urlQueryArgs

Query arguments to apply to the request URL.
Expand Down
81 changes: 81 additions & 0 deletions packages/server-side-render/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export const ATTRIBUTE_PROPERTY = {
textColor: [ 'color', 'text' ],
backgroundColor: [ 'color', 'background' ],
gradient: [ 'color', 'gradients' ],
fontSize: [ 'typography', 'fontSize' ],
fontFamily: [ 'typography', '__experimentalFontFamily' ],
borderColor: [ '__experimentalBorder', 'color' ],
};

export const STYLE_PROPERTY = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition is based on the following:

export const __EXPERIMENTAL_STYLE_PROPERTY = {

color: {
text: {
support: [ 'color', 'text' ],
},
background: {
support: [ 'color', 'background' ],
},
gradient: {
support: [ 'color', 'gradients' ],
},
},
elements: {
link: {
support: [ 'color', 'link' ],
},
},
typography: {
fontSize: {
support: [ 'typography', 'fontSize' ],
},
fontWeight: {
support: [ 'typography', '__experimentalFontWeight' ],
},
fontStyle: {
support: [ 'typography', '__experimentalFontStyle' ],
},
textTransform: {
support: [ 'typography', '__experimentalTextTransform' ],
},
leterSpacing: {
support: [ 'typography', '__experimentalLetterSpacing' ],
},
textDecoration: {
support: [ 'typography', '__experimentalTextDecoration' ],
},
},
spacing: {
margin: {
support: [ 'spacing', 'margin' ],
},
padding: {
support: [ 'spacing', 'padding' ],
},
blockGap: {
support: [ 'spacing', 'blockGap' ],
},
},
border: {
radius: {
support: [ '__experimentalBorder', 'radius' ],
subProperties: [
'topLeft',
'topRight',
'bottomRight',
'bottomLeft',
],
},
color: {
support: [ '__experimentalBorder', 'color' ],
additionalProperties: [ 'top', 'right', 'bottom', 'left' ],
},
style: {
support: [ '__experimentalBorder', 'style' ],
additionalProperties: [ 'top', 'right', 'bottom', 'left' ],
},
width: {
support: [ '__experimentalBorder', 'width' ],
additionalProperties: [ 'top', 'right', 'bottom', 'left' ],
},
},
};
22 changes: 13 additions & 9 deletions packages/server-side-render/src/server-side-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import { useDebounce, usePrevious } from '@wordpress/compose';
import { RawHTML, useEffect, useRef, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { Placeholder, Spinner } from '@wordpress/components';
import { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';

export function rendererPath( block, attributes = null, urlQueryArgs = {} ) {
return addQueryArgs( `/wp/v2/block-renderer/${ block }`, {
context: 'edit',
...( null !== attributes ? { attributes } : {} ),
...urlQueryArgs,
} );
}
/**
* Internal dependencies
*/
import { rendererPath, removeBlockSupportAttributes } from './utils';

function DefaultEmptyResponsePlaceholder( { className } ) {
return (
Expand Down Expand Up @@ -69,6 +65,7 @@ export default function ServerSideRender( props ) {
className,
httpMethod = 'GET',
urlQueryArgs,
skipBlockSupportAttributes = false,
EmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,
ErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,
LoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,
Expand All @@ -88,10 +85,17 @@ export default function ServerSideRender( props ) {

setIsLoading( true );

const sanitizedAttributes =
let sanitizedAttributes =
attributes &&
__experimentalSanitizeBlockAttributes( block, attributes );

if ( skipBlockSupportAttributes ) {
sanitizedAttributes = removeBlockSupportAttributes(
block,
sanitizedAttributes
);
}

// If httpMethod is 'POST', send the attributes in the request body instead of the URL.
// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.
const isPostRequest = 'POST' === httpMethod;
Expand Down
Loading