Wp-calypso: Gutenberg: Add new category link causes editor error

Created on 31 Oct 2018  路  5Comments  路  Source: Automattic/wp-calypso

Steps to reproduce

  1. Starting at URL:https://wpcalypso.wordpress.com/gutenberg
  2. Choose a blog
  3. Click "Add a Category" in the document settings bar

What I expected

I expected to be able to add a new category

What happened instead

I see this:
image

Recovery doesn't work and the error message I can copy is:

TypeError: Cannot read property 'length' of null
    at t.value (https://wpcalypso.wordpress.com/calypso/vendors~async-load-gutenberg-blocks~gutenberg-editor.b877787ec6dbfc28dcad.min.js:1:405788)
    at cb (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:59761)
    at zb (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:59556)
    at db (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:63369)
    at Ib (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:77720)
    at Ub (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:78094)
    at Xr (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:84180)
    at jr (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:83719)
    at xr (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:91241)
    at jt (https://wpcalypso.wordpress.com/calypso/vendors~build.fe7128f14bb2403405db.min.js:79:30610)

Browser / OS version

Chrome 70.0.3538.77 macOS 10.14

[Goal] Gutenberg [Pri] High [Type] Bug

All 5 comments

Probably related to the 4.1 upgrade. cc @vindl if you already started to look. pretty sure we need to update API middleware, wpcom should have examples.

~Are we a little too strict in our public.api implementation @mdawaffe? I can certainly filter this out on the client, but I think Gutenberg is making this call directly.~

screen shot 2018-11-02 at 4 52 21 pm

screen shot 2018-11-02 at 4 51 42 pm

Edit: it turns out Gutenberg has special middleware to rewrite this

From a Jetpack site that should be per_page=100, let me see if something is off

screen shot 2018-11-02 at 5 00 36 pm

Oh fun! I guess breaking chains has consequences 馃憤 Going to pull this in for our use.

https://github.com/WordPress/gutenberg/blob/master/packages/api-fetch/src/middlewares/fetch-all-middleware.js

// The REST API enforces an upper limit on the per_page option. To handle large
// collections, apiFetch consumers can pass `per_page=-1`; this middleware will
// then recursively assemble a full response array from all available pages.
const fetchAllMiddleware = async ( options, next ) => {
    if ( options.parse === false ) {
        // If a consumer has opted out of parsing, do not apply middleware.
        return next( options );
    }
    if ( ! requestContainsUnboundedQuery( options ) ) {
        // If neither url nor path is requesting all items, do not apply middleware.
        return next( options );
    }

    // Retrieve requested page of results.
    const response = await next( {
        ...modifyQuery( options, {
            per_page: 100,
        } ),
        // Ensure headers are returned for page 1.
        parse: false,
    } );

    const results = await parseResponse( response );

    if ( ! Array.isArray( results ) ) {
        // We have no reliable way of merging non-array results.
        return results;
    }

    let nextPage = getNextPageUrl( response );

    if ( ! nextPage ) {
        // There are no further pages to request.
        return results;
    }

    // Iteratively fetch all remaining pages until no "next" header is found.
    let mergedResults = [].concat( results );
    while ( nextPage ) {
        const nextResponse = await next( {
            ...options,
            // Ensure the URL for the next page is used instead of any provided path.
            path: undefined,
            url: nextPage,
            // Ensure we still get headers so we can identify the next page.
            parse: false,
        } );
        const nextResults = await parseResponse( nextResponse );
        mergedResults = mergedResults.concat( nextResults );
        nextPage = getNextPageUrl( nextResponse );
    }
    return mergedResults;
};

export default fetchAllMiddleware;

Oh fun! I guess breaking chains has consequences 馃憤 Going to pull this in for our use.

A bit late, but now I remembered that this was already discussed in the comments section of p7jreA-1Se-p2.

Was this page helpful?
0 / 5 - 0 ratings