Skip to content

Prevent an error in <ServerSideRender> by allowing POST request - #21068

Merged
swissspidy merged 14 commits into
WordPress:masterfrom
kienstra:add/ssr-post-support
Aug 15, 2020
Merged

swissspidy merged 14 commits into
WordPress:masterfrom
kienstra:add/ssr-post-support

Conversation

@kienstra

@kienstra kienstra commented Mar 23, 2020 •

Copy link
Copy Markdown
Contributor

Description

Allows optionally using POST requests in <ServerSideRender> to prevent an error when the attributes object is too big.

<ServerSideRender> uses GET requests in apiFetch(), but they can fail when the attributes object is too big:

error-att

This uses @swissspidy's suggestion in #16396 (comment) to allow using POST requests for large attributes.

It adds an optional prop httpMethod, and if it's 'POST', it causes <ServerSideRender> to make POST requests. It's prevented errors in my testing.

Also, it depends on WordPress/wordpress-develop#196.

Reported in:
#19935
#16396 (comment)
https://wordpress.org/support/topic/error-loading-block-the-response-is-not-a-valid-json-response-2/

How has this been tested?

  1. wp core update --version=5.5-RC1 # or any version 5.5+, as this depends on Allow POST requests in endpoint for ServerSideRender block component wordpress-develop#196, which was merged into 5.5
  2. checkout this PR's branch and do npm install && npm run dev
  3. clone https://github.com/kienstra/ssr-demo into your plugins/ directory in order to test this PR
  4. Follow the Usage instructions to test this PR with the httpMethod prop
  5. Expected: even a very large attributes object doesn't cause an error in the <ServerSideRender> component
  6. Actual: same as expected
  7. Regression testing on Core blocks that use <ServerSideRender> looks good, like 'Archives', 'Latest Comments', and 'Latest Posts'

Screenshots

expected-block

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

There can be an issue if the attributes object is big,
and the GET request fails and causes an error message
in the block.
This allows POSTing the attributes, preventing the error message.
See the PR to Core supporting the POST request.
There are 2 failed e2e tests,
though it doesn't look like they're caused by this PR.
@kienstra

Copy link
Copy Markdown
Contributor Author

The E2E test failures above don't look to be related to this PR, but maybe I missed something.

@kienstra

kienstra commented May 4, 2020 •

Copy link
Copy Markdown
Contributor Author

Now that WordPress/wordpress-develop@5460e0d was merged, this PR's dependency is satsfied.

@kienstra

kienstra commented Jul 29, 2020 •

Copy link
Copy Markdown
Contributor Author

Hi @ocean90,
Hope you're doing well.

Would you be able to review this, or point me to someone who could?

The Core patch for this is merged. It now has the latest from master, and still works.

Thanks, Dominik!

Comment thread packages/server-side-render/README.md Resolved
As Pascal mentioned,
it's easier to understand what this does.
@swissspidy swissspidy added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jul 30, 2020

@ocean90 ocean90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be good to document this change in CHANGELOG.md.

@kienstra

kienstra commented Aug 3, 2020

Copy link
Copy Markdown
Contributor Author

Hi @ocean90,

Would be good to document this change in CHANGELOG.md.

Good idea, the CHANGELOG.md entry is now added.

@JohnRDOrazio

Copy link
Copy Markdown
Contributor

Was this patch not included in 5.5?

@swissspidy

Copy link
Copy Markdown
Member

@JohnRDOrazio No. As you can see this PR has not been merged yet.

@JohnRDOrazio

Copy link
Copy Markdown
Contributor

ok, is there a workaround I can use until it's merged? A filter I can use to use POST instead of GET for ServerSideRender?

@kienstra

kienstra commented Aug 15, 2020 •

Copy link
Copy Markdown
Contributor Author

There's not really a workaround, other than forking this component. It'd be great if this could be merged, I really appreciate the reviews here.

@swissspidy
swissspidy merged commit 068064a into WordPress:master Aug 15, 2020
@github-actions github-actions Bot added this to the Gutenberg 8.8 milestone Aug 15, 2020
@kienstra

Copy link
Copy Markdown
Contributor Author

Thanks a lot for merging this!

lipemat added a commit to lipemat/js-boilerplate-gutenberg that referenced this pull request Aug 20, 2020
@JohnRDOrazio

JohnRDOrazio commented Aug 21, 2020 •

Copy link
Copy Markdown
Contributor

Thanks a lot for merging this!

yes thank you for merging this, I have just updated the Gutenberg plugin on one of my websites, and I tested using httpMethod: 'POST' and I can confirm it is working well!

@kienstra

Copy link
Copy Markdown
Contributor Author

Great to hear, thanks a lot for testing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Package] Server Side Render /packages/server-side-render

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants