• Hello,

    Thank you for maintaining Widget Options. I would like to report a compatibility bug with the Gutenberg Page & Post Block Options module, and request a fix.

    Environment

    • Widget Options version: 4.2.5
    • WordPress: 7.0.4
    • Gutenberg / Block Editor (core)

    What happens

    When Gutenberg Page & Post Block Options is enabled:

    1. Open the block editor on a page/post.
    2. Insert or open a custom block whose registered edit component is wrapped with React.memo (or another non-callable React element type such as forwardRef / lazy).
    3. The block fails to mount and shows:
      “This block has encountered an error and cannot be previewed.”
    4. Browser console error (minified variable name may differ):
      TypeError: d is not a constructor
      at the filter registered on blocks.registerBlockType in
      includes/widgets/gutenberg/build/index.js
      (namespace: extended-widget-options/sidebar-component), inside the try / catch that ends with return new d(e).

    Core blocks such as Paragraph work normally.
    The issue only appears for blocks whose registered edit is not a plain function/class (for example, memo-wrapped components).

    Disabling Gutenberg Page & Post Block Options resolves the error immediately.

    Root cause

    In includes/widgets/gutenberg/build/index.js, the plugin adds a blocks.registerBlockType filter that wraps every block’s edit roughly like this:

    const d = settings.edit;
    settings.edit = function ( props ) {
    // ... initialize extended_widget_opts_* attributes ...
    try {
    return d( props ); // call as a function
    } catch ( err ) {
    return new d( props ); // fallback: treat as a class constructor
    }
    };

    This is not how React components should be rendered.

    • Gutenberg normally renders edit via wp.element.createElement( OriginalEdit, props ).
    • Calling OriginalEdit(props) only works for plain function components.
    • new OriginalEdit(props) only works for class components.
    • Components created with React.memo()forwardRef()lazy(), etc. are objects, not callable functions and not constructors. For those:
      • d(props) throws (e.g. “is not a function”)
      • new d(props) throws TypeError: d is not a constructor ← the error we see

    That is why core blocks (plain function edit) still work, while many modern third-party blocks break.

    This is independent of any specific Lazy Edit / code-splitting feature in other plugins: any block that registers a memoized edit is affected.

    Requested fix

    Please change the wrapper so it always renders the original edit with createElement (or equivalent), for example:

    const OriginalEdit = settings.edit;

    settings.edit = function ( props ) {
    // … your attribute initialization …
    return wp.element.createElement( OriginalEdit, props );
    };

    There is no need for the try { OriginalEdit(props) } catch { new OriginalEdit(props) } pattern.

    Expected result

    With Gutenberg Page & Post Block Options enabled, third-party blocks that use React.memo (and similar) for edit should mount normally, the same as core blocks.

    I would appreciate it if you could confirm and ship a fix in an upcoming release. Happy to provide more details or test a patch if helpful.

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Mej de Castro

    (@mej)

    Hi @masakingston,

    Thanks for reporting the issue and for taking the time to suggest a possible fix.

    We truly appreciate the information you’ve provided. We’ll relay your findings and suggested solution to our development team for review.

    We’ll get back to you once we have more information from our dev team.

    Thanks again for your help and patience!

    Kind Regards,
    Mej, Widget Options Team

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.