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

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

Merged
merged 14 commits into from
Aug 15, 2020

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Mar 23, 2020

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
Contributor Author

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

@kienstra
Copy link
Contributor Author

kienstra commented May 4, 2020

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

@kienstra
Copy link
Contributor Author

kienstra commented Jul 29, 2020

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!

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
Copy link
Member

@ocean90 ocean90 left a comment

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.

packages/server-side-render/src/server-side-render.js Outdated Show resolved Hide resolved
@kienstra
Copy link
Contributor Author

kienstra commented Aug 3, 2020

Hi @ocean90,

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

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

@JohnRDOrazio
Copy link
Contributor

Was this patch not included in 5.5?

@swissspidy
Copy link
Member

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

@JohnRDOrazio
Copy link
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
Copy link
Contributor Author

kienstra commented Aug 15, 2020

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
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
Copy link
Contributor

JohnRDOrazio commented Aug 21, 2020

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
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.

None yet

4 participants