Skip to content

Dynamic Block: ServerSideRender not using POST method for attributes (max URL length limit reached using GET) #19935

Closed

Description

@nhterry

Description
The problem is when using ServerSideRender component, the number of attributes are limited to the max URL length of 2048 characters. My Dynamic Block has more attributes than are able to be passed through the GET method with the ServerSideRender component. This is because the ServerSideRender component defaults to using the GET method with apiFetch instead of POST. I wasn't able to figure out how to use the POST method with the block-renderer.

To reproduce
Steps to reproduce the behavior:

  1. Create a Dynamic Block component using ServerSideRender. (https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/)
  2. In the edit admin, specify attributes for the block that will be longer than 2048 characters for the GET request to apiFetch (/wp-json/wp/v2/block-renderer/block/name)
  3. See error in edit admin (ServerSideRender component): Error loading block: The response is not a valid JSON response.
  4. See error in console: net::ERR_CONNECTION_CLOSED api-fetch.js (809)
    https://domain.com/wp-json/wp/v2/block-renderer/block/name?context=edit&attributes%5Bname%5D=attributename ..{more than the allowed number of characters in URL}.. &_locale=user
  5. However, when viewing the live page (or preview), the block is rendered how it should be with no limit on the number of attributes.

Expected behavior
The ServerSideRender component seems like it should use the POST method with apiFetch so that you can pass in as many attributes as you would like rather than being limited to the max URL query string length.

Additional context

  • Wordpress v5.3.2

Activity

  1. jorgefilipecosta commented on Jan 30, 2020

    @jorgefilipecosta
    Member

    The block does not have any side effect so the API opted for GET request. But I agree that GET requests are very restrictive in terms of their size.
    @youknowriad any thoughts on suggesting the change to POST (in core)?

  2. added
    [Type] Enhancement
    Core REST API Task
    on Jan 30, 2020
  3. youknowriad commented on Jan 30, 2020

    @youknowriad
    Contributor

    No strong concerns for me but I feel there should be a trac ticket discussed with the REST API team. I also assume we need to keep both for backward compat?

  4. added
    [Package] Server Side Render
    on Jun 8, 2020
  5. metalandcoffee commented on Oct 9, 2020

    @metalandcoffee

    I'm wondering what the status on this is. I ran into this issue where once I've hit this limit - all the rest of my dynamic blocks stop working.
    image

  6. TimothyBJacobs commented on Mar 31, 2021

    @TimothyBJacobs
    Member

    This has been supported for some time. ServerSideRender accepts an httpMethod prop that can be used to switch to a POST request: https://github.com/WordPress/gutenberg/tree/trunk/packages/server-side-render

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Core REST API Task[Package] Server Side Render[Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions