Skip to content

Don't use select() directly #579

Description

@t-hamano

Description

There are cases where select() is used directly instead of useSelect, even though it is within a component or a hook. For example, like this.

import { select } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';

function Component() {
	const title = select( editorStore ).getEditedPostAttribute( 'title' );
	return title;
}

This means that the data becomes fixed when the component is rendered, and the old data will remain unless the component is re-rendered.

This is causing two problems, as far as I can tell.


Title suggestion

const title = select( editorStore ).getEditedPostAttribute( 'title' );

The button text should be "Regenerate" when the title is empty, and "Regenerate" when the title is not empty, but it is not reactive.

Recording.2026-05-19.190401.mp4

Suggest terms

hasEnoughContent,
handleGenerate,
handleAccept,
handleDismiss,
handleDismissAll,
} = useContentClassification( taxonomy );

// Check if content has enough words.
const hasEnoughContent =
wordCount( content || '', 'words' ) >= MINIMUM_WORD_COUNT;

The suggest terms button becomes interactive when the content includes 150 or more words. However, this button is not reactive to changes in content because its interactivity is determined at the time it is rendered based on the content. Therefore, even if you add or remove words, the button's state will not update.

Recording.2026-05-19.191038.mp4

Another issue with the current implementation is that outdated content may be sent to the server side when generating terms.

Step-by-step reproduction instructions

N/A

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions