Skip to content

Disabling Custom Fields in Preferences prevents to listen Paste Event in Block Editor #62145

@webaxones

Description

@webaxones

Description

In a typography correction plugin, I need to listen for the Paste event to process blocks when the user pastes content. This was working until recently but no longer functions.
I noticed that by enabling Custom Fields in Preferences, I could listen to the event again.
To rule out the possibility that my code is causing the issue, I tested a simple script with which I can reproduce the problem.

Step-by-step reproduction instructions

  1. Launch WordPress in its latest version on PHP 8.x with Gutenberg (even using the latest PRs).
  2. Create a simple plugin with the following PHP and JS code.
  3. Upload the plugin and activate it.
  4. Create a new post and open the console.
  5. Paste text into the editor and see that no events are logged in the console.
  6. Enable Custom Fields in Preferences and paste text into the editor again.
  7. Notice that the event is now being listened to and appears in the console.
<?php
/*
Plugin Name: pasteEventListenerPlugin
Description: A simple plugin to load a JS script in the Gutenberg block editor to display something
Version: 1.0
Author: Nobody
*/
defined( 'ABSPATH' ) || exit;

function paste_event_listener_plugin_enqueue_script() {
	// Enqueue the script only in the block editor
	wp_enqueue_script(
		'paste-event-listener-plugin',
		plugin_dir_url( __FILE__ ) . 'paste-event-listener-plugin.js',
		array( 'wp-blocks', 'wp-element', 'wp-editor' ),
		filemtime( plugin_dir_path( __FILE__ ) . 'paste-event-listener-plugin.js' )
	);
}
add_action( 'enqueue_block_editor_assets', 'paste_event_listener_plugin_enqueue_script' );
wp.domReady( () => {
	// Intercept clipboard paste
	var editorElement = document.querySelector('#editor');

	if (editorElement) {
    	editorElement.addEventListener('paste', function(e) {
        	console.log(e);
    	} );
	}
} );

Screenshots, screen recording, code snippet

image

Environment info

WP 6.5.3
Gutenberg PR 62144
PHP 8.3
Chrome

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

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions