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

Gutenlypso: Register server-defined blocks attributes #29984

Closed
wants to merge 2 commits into from

Conversation

Copons
Copy link
Contributor

@Copons Copons commented Jan 8, 2019

Changes proposed in this Pull Request

  • Manually register the server-defined dynamic blocks (e.g. Latest Comments) attributes.

Dynamic blocks are registered server-side, and their attribute are loaded through the unstable__bootstrapServerSideBlockDefinitions function, called server-side as well.

Gutenlypso doesn't have access to the same JS globals so it doesn't have any information about the dynamic blocks' schema and attributes.

This PR is a bit of a clumsy workaround, and proposes to manually register the attributes of server-defined blocks during the Gutenlypso initialization.

For now, I've only worked on the Latest Comments block because it's a major offender (all its attributes default to true, so fallbacking all of them to false is very visibly incorrect), and because I'd like to discuss this change before working on more blocks.
Please compare this PR with how the block defines its attributes in PHP.
Is my solution a viable, or even desirable?

Testing instructions

  • Open /block-editor.
  • Insert the Latest Comments block.
  • Check that its preview correspond to its sidebar settings defaults:

screenshot 2019-01-08 at 15 12 23

Fixes #27963

@Copons Copons added [Type] Bug [Type] Question [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Goal] Gutenberg Working towards full integration with Gutenberg labels Jan 8, 2019
@Copons Copons self-assigned this Jan 8, 2019
@matticbot
Copy link
Contributor

@Copons Copons requested a review from a team January 8, 2019 15:24
@Copons Copons added [Pri] High [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 8, 2019
@gwwar
Copy link
Contributor

gwwar commented Jan 9, 2019

We'll want to work with WordPress core to make sure we can access these in a cleaner way. @Copons do you mind filing an enhancement issue in https://github.com/WordPress/gutenberg/issues ?

cc @gziolo @aduth @youknowriad

I'm thinking maybe a custom wpcom endpoint for now to fix the issue, or embedding a similar global on the app skeleton for this section.

@gziolo
Copy link
Member

gziolo commented Jan 9, 2019

No need to create an issue, we have a huge issue which is one of the goals of Gutenberg phase 2 (WordPress/gutenberg#13113).

In fact, there are 2 issues opened:

Please leave your comments there if you have some ideas.

Let me also re-share a part of my comment I left in the last issue:

We did some explorations (#5802) in the past how we could move attributes to the server and even allow to filter them, so plugins could have a better control over it. It's all doable and can still continue to work with the existing JS API.

There was also another exploration (#5652) to use JSON files to share definitions between JS and PHP which I found very promising myself. Example structur:

{
  "name": "core/categories",
  "category": "widgets",
  "supports": {
	"html": false
  },
  "attributes": {
	"showPostCounts": {
	  "type": "boolean",
	  "default": false
	},
	"displayAsDropdown": {
	  "type": "boolean",
	  "default": false
	},
	"showHierarchy": {
	  "type": "boolean",
	  "default": false
	},
	"align": {
	  "type": "string"
	}
  },
  "render_callback": "render_block_core_categories"
}

There might be other ways to solve this. What I'm sharing is what I actually coded as an excercise to see what could work.

@Copons
Copy link
Contributor Author

Copons commented Jan 9, 2019

Alternative approach with a custom WPCOM endpoint at #30045 + D22987-code

@Copons
Copy link
Contributor Author

Copons commented Jan 11, 2019

Replaced by #30045

@Copons Copons closed this Jan 11, 2019
@Copons Copons deleted the fix/27963-dynamic-blocks-attributes branch January 11, 2019 16:55
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Goal] Gutenberg Working towards full integration with Gutenberg [Pri] High [Type] Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gutenberg: Dynamic blocks default attributes aren't loaded
4 participants