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

withAPIData doesn't fetch after page reload #6537

Closed
code-flow opened this issue May 2, 2018 · 2 comments · Fixed by #8584
Closed

withAPIData doesn't fetch after page reload #6537

code-flow opened this issue May 2, 2018 · 2 comments · Fixed by #8584
Labels
REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended

Comments

@code-flow
Copy link
Contributor

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.

@aduth
Copy link
Member

aduth commented May 2, 2018

Possibly related: #6277 (pending fix at #6303)

@keesiemeijer
Copy link

Possibly related: #6379

keesiemeijer added a commit to keesiemeijer/related-posts-by-taxonomy that referenced this issue May 7, 2018
Sometimes blocks are randomly stuck in a loading state.
See WordPress/gutenberg#6537

This commit also replaces the focus property with isSelected
@danielbachhuber danielbachhuber added [Type] Bug An existing feature does not function as intended REST API Interaction Related to REST API labels May 17, 2018
@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants