AdvancedCustomFields / AdvancedCustomFields/acf
Bug in the second object passed to the callback function in "render_block_preview".
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I'm trying to build a Gutenberg block using ACF Pro, unfortunately I've encountered what I think is a bug in the JavaScript library.
It seems like there's a difference in the block object passed as the second parameter in the function that get called whenever a "render_block_preview" triggers.
On the first calls (when you open wordpress editor page), the block.data is correctly formatted such as
nameOfTheField: value.
On every subsequent call, block.data is formatted differently, using the key instead of the name of the field:
keyOfTheField: value.
I'm attaching an example since I dont think I've been clear in the previous wall of text. In my javascript code, i have the following code as by the documentation:
if( window.acf ) {
window.acf.addAction( 'render_block_preview/type=myblock', myfunction );
}
And myfunction
function myfunction (element, block) {
console.log(block);
}
This is what my functions receives when loading the editor:
{
id: "block_5e37a5b20e1c0",
name: "acf/slider-prodotti"
data: {
test: "value"
_test "field_5e27345afe9d7"
...
}
...
}
And this is everytime it gets called because a field has been changed in the editor:
{
id: "block_5e37a5b20e1c0"
name: "acf/slider-prodotti"
data: {
field_5e27345afe9d7: "value"
...
}
...
}
Is it supposed to behave like this? That would force the user to write some logic to handle the different key name between the first calls and the following ones.
I'm using the latest (5.8.7) version of ACF Pro.
Thanks in advance
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the WordPress editor with ACF Pro 5.8.7 using the render_block_preview/type=myblock action and the provided myfunction callback. Compare block.data on the initial render and after a field change; done means the callback behavior is consistent or the differing formats are clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wordpress
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100