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

Blocks with post meta attributes stopped working after update 6.6.0 #17767

Closed
razwan opened this issue Oct 4, 2019 · 8 comments · Fixed by #17820
Closed

Blocks with post meta attributes stopped working after update 6.6.0 #17767

razwan opened this issue Oct 4, 2019 · 8 comments · Fixed by #17820
Assignees
Labels
[Feature] Block API API that allows to express the block paradigm. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@razwan
Copy link
Contributor

razwan commented Oct 4, 2019

Describe the bug
The 6.6.0 update seems to cause an issue where the editor breaks when I add blocks that use post meta as source for one of their attributes.

I've created a small plugin to test this and got the same result:

Cannot read property 'my_block_meta' of undefined

The error comes from the withMetaAttributeSource filter here

To reproduce
Steps to reproduce the behavior:

  1. Register a block type that has an attribute with post meta as source
  2. Try to add that block type to the content
  3. The editor encounters an unexpected error.

Trace

index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17 Uncaught TypeError: Cannot read property 'my_block_meta' of undefined
    at index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
    at Array.reduce (<anonymous>)
    at index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
    at mountMemo (react-dom.8b3dda97.js:15807)
    at Object.useMemo (react-dom.8b3dda97.js:16029)
    at useMemo (react.eef5f5a3.js:1680)
    at index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
    at WithMetaAttributeSource((Component)) (index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17)
    at renderWithHooks (react-dom.8b3dda97.js:15246)
    at mountIndeterminateComponent (react-dom.8b3dda97.js:17480)
(anonymous) @ index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
(anonymous) @ index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
mountMemo @ react-dom.8b3dda97.js:15807
useMemo @ react-dom.8b3dda97.js:16029
useMemo @ react.eef5f5a3.js:1680
(anonymous) @ index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
WithMetaAttributeSource((Component)) @ index.js?ver=2e2b78de4a8a9e8f1ec023c58f617ba6:17
renderWithHooks @ react-dom.8b3dda97.js:15246
mountIndeterminateComponent @ react-dom.8b3dda97.js:17480
beginWork$1 @ react-dom.8b3dda97.js:18624
callCallback @ react-dom.8b3dda97.js:341
invokeGuardedCallbackDev @ react-dom.8b3dda97.js:391
invokeGuardedCallback @ react-dom.8b3dda97.js:448
beginWork$$1 @ react-dom.8b3dda97.js:23355
performUnitOfWork @ react-dom.8b3dda97.js:22349
workLoopSync @ react-dom.8b3dda97.js:22323
renderRoot @ react-dom.8b3dda97.js:22016
runRootCallback @ react-dom.8b3dda97.js:21692
(anonymous) @ react-dom.8b3dda97.js:11491
unstable_runWithPriority @ react.eef5f5a3.js:2820
runWithPriority$2 @ react-dom.8b3dda97.js:11443
flushSyncCallbackQueueImpl @ react-dom.8b3dda97.js:11487
flushSyncCallbackQueue @ react-dom.8b3dda97.js:11476
discreteUpdates$1 @ react-dom.8b3dda97.js:21815
discreteUpdates @ react-dom.8b3dda97.js:2357
dispatchDiscreteEvent @ react-dom.8b3dda97.js:6104
react-dom.8b3dda97.js:19952 The above error occurred in the <WithMetaAttributeSource((Component))> component:
    in WithMetaAttributeSource((Component)) (created by WithFilters(Component))
    in WithFilters(Component) (created by IfCondition(WithFilters(Component)))
    in IfCondition(WithFilters(Component)) (created by WithDispatch(IfCondition(WithFilters(Component))))
    in WithDispatch(IfCondition(WithFilters(Component)))
    in Unknown (created by WithSelect(WithDispatch(IfCondition(WithFilters(Component)))))
    in WithSelect(WithDispatch(IfCondition(WithFilters(Component))))
    in Unknown (created by Pure(WithViewportMatch(WithSelect(WithDispatch(IfCondition(WithFilters(Component)))))))
    in Pure(WithViewportMatch(WithSelect(WithDispatch(IfCondition(WithFilters(Component)))))) (created by t)
    in Br (created by t)
    in div (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by WithSelect(WithDispatch(t)))
    in WithSelect(WithDispatch(t))
    in Unknown (created by yt)
    in div
    in Unknown (created by WithDispatch(Component))
    in WithDispatch(Component) (created by yt)
    in div (created by t)
    in t (created by WithSafeTimeout(t))
    in WithSafeTimeout(t) (created by WithDispatch(WithSafeTimeout(t)))
    in WithDispatch(WithSafeTimeout(t))
    in Unknown (created by WithSelect(WithDispatch(WithSafeTimeout(t))))
    in WithSelect(WithDispatch(WithSafeTimeout(t))) (created by yt)
    in div (created by t)
    in div (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by WithSelect(WithDispatch(t)))
    in WithSelect(WithDispatch(t)) (created by yt)
    in div (created by t)
    in t
    in Unknown (created by WithSelect(t))
    in WithSelect(t) (created by yt)
    in div (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by WithSelect(WithDispatch(t)))
    in WithSelect(WithDispatch(t)) (created by yt)
    in yt
    in div
    in div (created by t)
    in t
    in Unknown
    in Unknown (created by WithViewportMatch(Component))
    in WithViewportMatch(Component) (created by NavigateRegions(WithViewportMatch(Component)))
    in div (created by NavigateRegions(WithViewportMatch(Component)))
    in NavigateRegions(WithViewportMatch(Component)) (created by WithDispatch(NavigateRegions(WithViewportMatch(Component))))
    in WithDispatch(NavigateRegions(WithViewportMatch(Component)))
    in Unknown (created by WithSelect(WithDispatch(NavigateRegions(WithViewportMatch(Component)))))
    in WithSelect(WithDispatch(NavigateRegions(WithViewportMatch(Component)))) (created by t)
    in t (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(WithDispatch(t)) (created by t)
    in ht (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by WithSelect(WithDispatch(t)))
    in WithSelect(WithDispatch(t))
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(WithSelect(WithDispatch(t))) (created by t)
    in div (created by t)
    in t (created by t)
    in t (created by t)
    in StrictMode (created by t)
    in t (created by WithDispatch(t))
    in WithDispatch(t)
    in Unknown (created by WithSelect(WithDispatch(t)))
    in WithSelect(WithDispatch(t))

React will try to recreate this component tree from scratch using the error boundary you provided, t.

Additional context
Gutenberg 6.6.0

@youknowriad youknowriad added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. Needs Testing Needs further testing to be confirmed. labels Oct 4, 2019
@youknowriad
Copy link
Contributor

cc @epiqueras

@epiqueras
Copy link
Contributor

Hi @razwan,

I can't reproduce this.

Something in your setup is causing the post object returned from the API to not have a meta property. Are you running any plugins that could be doing that?

@retlehs
Copy link
Contributor

retlehs commented Oct 4, 2019

i'm seeing the same thing - both on an existing setup that has a block with meta sources, along with a fresh install using gutenberg 6.6.0 and no other plugins

@epiqueras
Copy link
Contributor

Can you try logging/inspecting the result of the REST API call for fetching the post when the editor loads. For some reason the meta property is missing, although I can't reproduce it. It might be related to a change in Core.

If this is the case, we'll need to think about where to throw an error when that happens, because other parts of the codebase might assume that it is there and fail in different ways.

@razwan
Copy link
Contributor Author

razwan commented Oct 7, 2019

hey @epiqueras

I've tested on a fresh installation of WordPress 5.2.3 where I've only installed Gutenberg 6.6.0 and the plugin I mentioned above. I created a new post and the only REST API calls made when the editor loads are made to

v2/users/me
v2/users/
v2/taxonomies

when i try to add a block two more request are made to

v2/types/wp_block
v2/blocks

and if I try to add the test block I made the editor crashed.

The preloaded data used in the createPreloadingMiddleware call seems to have a value for the my_block_meta field for both creating a new post or editing a new one.

	"\/wp\/v2\/pages\/8?context=edit": {
		"body": {
			"id": 8,
			"date": "2019-10-07T06:39:31",
			"date_gmt": "2019-10-07T06:39:31",
			"guid": {
				"rendered": "http:\/\/gutenbergtest.local\/?page_id=8",
				"raw": "http:\/\/gutenbergtest.local\/?page_id=8"
			},
			"modified": "2019-10-07T06:41:20",
			"modified_gmt": "2019-10-07T06:41:20",
			"password": "",
			"slug": "gutenberg-test",
			"status": "publish",
			"type": "page",
			"link": "http:\/\/gutenbergtest.local\/gutenberg-test\/",
			"title": {"raw": "Gutenberg test", "rendered": "Gutenberg test"},
			"content": {
				"raw": "<!-- wp:paragraph -->\n<p>Test paragraph<\/p>\n<!-- \/wp:paragraph -->",
				"rendered": "\n<p>Test paragraph<\/p>\n",
				"protected": false,
				"block_version": 1
			},
			"excerpt": {"raw": "", "rendered": "<p>Test paragraph<\/p>\n", "protected": false},
			"author": 1,
			"featured_media": 0,
			"parent": 0,
			"menu_order": 0,
			"comment_status": "closed",
			"ping_status": "closed",
			"template": "",
			"meta": {"my_block_meta": 0},
			"permalink_template": "http:\/\/gutenbergtest.local\/%pagename%\/",
			"generated_slug": "gutenberg-test",
			"_links": {
				"self": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8"}],
				"collection": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages"}],
				"about": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/types\/page"}],
				"author": [{"embeddable": true, "href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/users\/1"}],
				"replies": [
					{
						"embeddable": true,
						"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/comments?post=8"
					}
				],
				"version-history": [
					{
						"count": 2,
						"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8\/revisions"
					}
				],
				"predecessor-version": [
					{
						"id": 10,
						"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8\/revisions\/10"
					}
				],
				"wp:attachment": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/media?parent=8"}],
				"wp:action-publish": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8"}],
				"wp:action-unfiltered-html": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8"}],
				"wp:action-assign-author": [{"href": "http:\/\/gutenbergtest.local\/wp-json\/wp\/v2\/pages\/8"}],
				"curies": [{"name": "wp", "href": "https:\/\/api.w.org\/{rel}", "templated": true}]
			}
		}, "headers": {"Link": "<http:\/\/gutenbergtest.local\/gutenberg-test\/>; rel=\"alternate\"; type=text\/html"}
	},

@epiqueras epiqueras removed the Needs Testing Needs further testing to be confirmed. label Oct 7, 2019
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Oct 7, 2019
@epiqueras
Copy link
Contributor

@razwan Thanks for the info!

The difference between our setups was that you were using a page.

Here is the fix: #17820

@razwan
Copy link
Contributor Author

razwan commented Oct 8, 2019

@epiqueras sorry for the misinformation, I guess I overlooked that aspect. I'm glad I could help and that this got fixed in such a short time. Thanks!

@epiqueras
Copy link
Contributor

It wasn't misinformation 😄 A page is still a post. Thanks for being so responsive so that we could fix this quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Status] In Progress Tracking issues with work in progress [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