From 7ffd7e36af350e83317558da863f1e1a4a2bc4e8 Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Wed, 8 Apr 2026 12:36:46 +0530 Subject: [PATCH] Fix block editor crash when editor.MediaUpload is a functional component The `with-media-library-notice` wrapper uses `class extends InitialMediaUpload` to override `buildAndSetFeatureImageFrame`. This crashes the entire block editor when another plugin returns a functional (arrow function) component from the `editor.MediaUpload` filter, because arrow functions have no [[Construct]] and cannot be used as a base class. Add a guard that checks `isReactComponent` on the prototype before attempting class inheritance. When the component is not a class, return it as-is so the editor remains functional. Fixes #8167 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../components/with-media-library-notice.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assets/src/block-editor/components/with-media-library-notice.js b/assets/src/block-editor/components/with-media-library-notice.js index 84bbfcb10c9..47d2152a8ea 100644 --- a/assets/src/block-editor/components/with-media-library-notice.js +++ b/assets/src/block-editor/components/with-media-library-notice.js @@ -145,6 +145,17 @@ export default (InitialMediaUpload, minImageDimensions) => { }); }; + // If the component is not a class (e.g. a functional or arrow function component + // returned by another plugin's filter), it cannot be extended via `class extends`. + // In that case, return it as-is to avoid crashing the editor with: + // "TypeError: Class extends value ... is not a constructor or null" + if ( + !InitialMediaUpload.prototype || + !InitialMediaUpload.prototype.isReactComponent + ) { + return InitialMediaUpload; + } + /** * Extends the MediaUpload component to display a notice for small images. */