Skip to content

withAPIData doesn't fetch after page reload #6537

Description

@code-flow

Hey guys, thanks for the awesome work around Gutenberg. I want to report the following issue that another guy reproduced already.

Issue Overview

When withAPIData is used, the data is loaded only when the block is added freshly to Gutenberg. If the block was already added and someone reloads the whole page, there is no data.

export default registerBlockType(
	'whatever/categories',
	{
		title:      'Whatever',
		category:   'widgets',
		icon:       'list-view',
		keywords:   [],
		supports:   {
			html: false,
		},
		attributes: {
			headline:       {
				type:    'string',
				default: 'Whatever',
			},
			
		},
		edit:       withAPIData( function () {
			return {
				categoriesList: '/wp/v2/categories?per_page=100&_fields=id,name,parent',
			}
		} )( ( props ) => {
			console.log(props.categoriesList); // no data once the page reloads

			return <div>whatever</div>;
		} ),
		save:       props => {
			return null;
		},
	},
);

Steps to Reproduce (for bugs)

  1. Add the block to Gutenberg. props.categoriesList.data exists and has data.
  2. Reload the page (by pressing the browsers reload-button).
  3. REST-Request finishes with code 200, however props.categoriesList.data is undefined.

I used Firefox developer edition 60.0b16 (64-Bit). But could reproduce it with Chrome 66.0.3359.139 as well.

Expected Behavior

In the example above, props.categoriesList should return {get: ƒ, isLoading: false, path: "/wp/v2/posts?per_page=4", create: ƒ, isCreating: false, data: [array data]}

Current Behavior

In the example above, props.categoriesList returns {get: ƒ, isLoading: true, path: "/wp/v2/posts?per_page=4", create: ƒ, isCreating: false]} (no data)

Possible Solution

That's the question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    REST API InteractionRelated to REST API[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions