Skip to content

Commit f0c478d

Browse files
committed
fix: ensure context by setting in block.json and also adding a(n empty) default
1 parent d26534d commit f0c478d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

includes/blocks/subtitle-block/block.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"name": "newspack-block-theme/article-subtitle",
55
"title": "Article Subtitle",
66
"category": "newspack",
7+
"usesContext": [ "postId", "postType" ],
78
"attributes": {},
89
"supports": {
910
"html": false,

includes/blocks/subtitle-block/site-editor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useEntityProp } from '@wordpress/core-data';
1111

1212
import metadata from './block.json';
1313

14-
const EditComponent = ( { context: { postType, postId } } ) => {
14+
const EditComponent = ( { context: { postType, postId } = {} } ) => {
1515
const blockProps = useBlockProps();
1616
const [ postMeta = {} ] = useEntityProp( 'postType', postType, 'meta', postId );
1717
const subtitle = postMeta[ newspack_block_theme_subtitle_block.post_meta_name ] || __( 'Article subtitle', 'newspack-block-theme' );
@@ -25,7 +25,6 @@ const blockData = {
2525
foreground: '#36f',
2626
},
2727
edit: EditComponent,
28-
usesContext: [ 'postId', 'postType' ],
2928
...metadata,
3029
};
3130

0 commit comments

Comments
 (0)