Skip to content

with-media-library-notice: block editor crash when editor.MediaUpload filter returns a functional component #8167

@saroshaga

Description

@saroshaga

Summary

The with-media-library-notice.js component uses class inheritance (class extends InitialMediaUpload) to wrap the editor.MediaUpload filter result. This crashes the block editor when any other plugin returns a functional (arrow function) component from that filter, because arrow functions have no [[Construct]] internal method and cannot be used as a base class.

Error

TypeError: Class extends value l=>{...} is not a constructor or null
    at p (amp-block-editor.js:3:1219)

All blocks on the page display "This block has encountered an error and cannot be previewed", making the editor completely unusable.

Root cause

In assets/src/block-editor/components/with-media-library-notice.js:

return class FeaturedImageMediaUpload extends InitialMediaUpload {
    buildAndSetFeatureImageFrame() { /* ... */ }
};

This assumes InitialMediaUpload is always a class component. Since React and WordPress are moving toward functional components, other plugins hooking into editor.MediaUpload may return function components that cannot be extended this way.

Steps to reproduce

  1. Install a plugin that returns a functional component from the editor.MediaUpload filter (e.g. any HOC using createHigherOrderComponent that returns an arrow function)
  2. Activate the AMP plugin
  3. Open any post or page in the block editor
  4. All blocks crash with the TypeError above

Suggested fix

Use composition instead of class inheritance — wrap the component in a functional HOC rather than extending it. The AMP plugin already uses this pattern in with-featured-image-notice.js, which could serve as a reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions