Skip to content

hasFinishedResolution always returns false for blockEditorStore selectors #70255

@albanyacademy

Description

@albanyacademy

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

  1. open block editor, inspector console
  2. enter wp.data.select('core/block-editor').canEditBlock(wp.data.select('core/block-editor').getSelectedBlockClientId())
  3. 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.
  4. after, run wp.data.select('core/block-editor').hasFinishedResolution('canEditBlock', [wp.data.select('core/block-editor').getSelectedBlockClientId()])
  5. should see it return false, even though canEditBlock has 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions