Skip to content

Conversation

@elcapo
Copy link

@elcapo elcapo commented Jul 23, 2025

Hi @mtoensing,

Here's my second attempt at fixing #69. I did some checks and now:

  • it works under Gutenberg
  • it doesn't produce any issue in the widgets screen

It still doesn't work from the widgets screen but that makes sense as there is no related post available.

Please, double check before merging, just in case I'm still missing something. Feel free to discard both the PR and the issue if you think it doesn't worth the fix.

Here's what I did:

  1. I replaced the import of the editorStore with a constant that catches it if it's available. That causes npm run build to not include wp-editor as a dependency but still uses it when it's available (ex. Gutenberg editor).
  2. I added an "early exit" so that the editorStore isn't used when it's not available (ex. the widget screen).

Thanks for the patience!

@mtoensing
Copy link
Owner

I will check.

@mtoensing
Copy link
Owner

Thanks!

@mtoensing
Copy link
Owner

Here’s what I’d check before merging:
1. Correct store + feature detection

prefer feature detection over assumptions:

    ```
    import { select } from '@wordpress/data';
    
    const editor = select( 'core/editor' );
    const canReadPost = !!editor && typeof editor.getEditedPostAttribute === 'function';
    ```

If you only need block-editor state, consider swapping any core/editor calls for core/block-editor where possible; core/editor is brittle in non-post editors.

  1. Avoid calling selectors during render if not needed

If you’re using hooks like useSelect, ensure the selector returns a stable value and the guard prevents unnecessary rerenders. If it’s a one-off check, using select() outside render (e.g., in an effect) may reduce churn.

@mtoensing
Copy link
Owner

mtoensing commented Aug 17, 2025

and it is not obvious why we need such a hack. The widgets menu is deprecated, isn't it? Same applies to this case: #69

@elcapo elcapo closed this by deleting the head repository Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants