-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Description
Seems like every selector i use for core/block-editor returns false for this check.
I'm adapting useBlockLock function for my own purposes, but I tried adding hasFinishedResolution and no bueno. isLocked fires more than once, once with false and then with true. I'd rather just wait until its actually finished. (Perhaps what's happening is it has finished resolving whatever it needs to check, but something else is causing it to flip isLocked as a side effect.)
below is the example code i've tried:
wp.data.select('core/block-editor').canEditBlock(wp.data.select('core/block-editor').getSelectedBlockClientId())
// true
wp.data.select('core/block-editor').hasFinishedResolution('canEditBlock', [wp.data.select('core/block-editor').getSelectedBlockClientId()])
// false
// also tried it without the wrapping array for the second arg;
so, yeah. not sure what's up, maybe hasFinishedResolution was never intended to work with the block editor? Hard pressed to find examples in the codebase where it's been used in conjunction with the block editor store - if so, what would be a valid way to do something to the equivalent?
Step-by-step reproduction instructions
- open block editor, inspector console
- enter
wp.data.select('core/block-editor').canEditBlock(wp.data.select('core/block-editor').getSelectedBlockClientId()) - should see it return false or true, true if the block is indeed editable. should mention that you should try this with an editable block.
- after, run
wp.data.select('core/block-editor').hasFinishedResolution('canEditBlock', [wp.data.select('core/block-editor').getSelectedBlockClientId()]) - should see it return false, even though
canEditBlockhas run with those params already.
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure