Skip to content

Visual Revisions: Global data methods like 'select' don't work in this mode #75926

@pbiron

Description

@pbiron

Description

I've got a custom block that has worked just fine in the post editor since ~2021. When I go to see the 7.0-beta1 Visual Revisions for a page that uses that block I get the dreaded "This block has encountered an error and cannot be previewed." message.

In my block's edit script, at one point I call

const parent         = select( 'core/block-editor' ).getBlockParentsByBlockName( clientId, 'myblocks/my-parent-block-name' );
const { buttonOnly } = select( 'core/block-editor' ).getBlockAttributes( Array.isArray( parent ) ? parent[0] : parent );

That works fine in the editor (i.e., parent gets set to an array with the clientId of the parent block).  But when I load the Visual Revision screen getBlockParentsByBlockName() returns an empty array, and thus the next call to getBlockAttributes() results in a run-time error.

A little bit of context in case it helps:

  • this is an apiVersion: 1 block. Don't know if that part of the prob. Eventually, I'll need to fix that before 7.0 comes out, but I don't have time to do that right now...

Step-by-step reproduction instructions

n/a

Screenshots, screen recording, code snippet

No response

Environment info

  • 7.0-beta1, custom hybrid theme
  • Chrome 145.0.7632.110
  • Win11 Pro for Workstations

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

Labels

[Feature] HistoryHistory, undo, redo, revisions, autosave.[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions