I am encountering an error when using onNavigateToEntityRecordin combination with useEntityBlockEditor, useEntityRecord, or getEditedEntityRecord. Navigation to entity records does not work as expected, and the function throws an error instead.
Step-by-step reproduction instructions
Create a custom block with wordpress/create-block package
Open src > edit.js file and replace the code with the below code,
import { __ } from '@wordpress/i18n';
import {
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import './editor.scss';
import { useSelect } from '@wordpress/data';
import { useEntityBlockEditor } from '@wordpress/core-data';
import { Button } from '@wordpress/components';
export default function Edit() {
const ref = 357; //This is the static post id of loop template
const {
onNavigateToEntityRecord,
} = useSelect(
(select) => {
const { getSettings } = select(blockEditorStore);
return {
onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord,
};
},
[]
);
const [blocks] = useEntityBlockEditor('postType', 'post', {
id: ref,
});
const blockProps = useBlockProps();
const handleEditOriginal = () => {
onNavigateToEntityRecord({ postId: ref, postType: 'post' })
};
return (
<>
<div {...blockProps}>
<Button onClick={handleEditOriginal} variant="primary">Edit Original</Button>
</div>
</>
);
}
Replace ref with the actual post ID to navigate to a specific post
build and active the plugin
use your block
You will see a button click on it After that, you will see the error
Screenshots, screen recording, code snippet
const [blocks] = useEntityBlockEditor('postType', 'post', {
id: ref,
}); //Throw error when I write this line
Additional Context
I am also using useEntityRecord and getEditedEntityRecord in this block.
The issue only occurs when using these hooks together with onNavigateToEntityRecord. Separately, the hooks work without errors.
Environment info
WordPress Version: 6.6.2
With Gutenberg or without Gutenberg throw error my version was: 19.2.0
Browser: Chrome 129
OS: Windows 11
Please confirm that you have searched existing issues in the repo.
[X] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Description
I am encountering an error when using
onNavigateToEntityRecord
in combination withuseEntityBlockEditor
,useEntityRecord
, orgetEditedEntityRecord
. Navigation to entity records does not work as expected, and the function throws an error instead.Step-by-step reproduction instructions
Open src > edit.js file and replace the code with the below code,
Screenshots, screen recording, code snippet
Additional Context
I am also using useEntityRecord and getEditedEntityRecord in this block.
The issue only occurs when using these hooks together with onNavigateToEntityRecord. Separately, the hooks work without errors.
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.