Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent crossbrowser onBeforeInput paste event behavior #21742

Open
johtso opened this issue Jun 24, 2021 · 3 comments
Open

Inconsistent crossbrowser onBeforeInput paste event behavior #21742

johtso opened this issue Jun 24, 2021 · 3 comments
Labels
Component: DOM Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@johtso
Copy link

johtso commented Jun 24, 2021

React version: 17.0.2

In Chrome, pasting triggers onPaste and onBeforeInput, with the nativeEvents ClipboardEvent and TextEvent respectively.

In Firefox, pasting only triggers onPaste with nativeEvent paste.

If I'm not mistaken, this seems to be the code responsible for not triggering onBeforeInput on native paste events:

case 'paste':
// If a paste event occurs after a keypress, throw out the input
// chars. Paste events should not lead to BeforeInput events.
return null;

React version: 17.0.2 and 18.0.0

17.0.2
https://codesandbox.io/s/condescending-cerf-e1qt9?file=/src/App.js
18.0.0
https://codesandbox.io/s/sparkling-sun-fylti?file=/src/App.js

@johtso johtso added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jun 24, 2021
@eps1lon
Copy link
Collaborator

eps1lon commented Jun 24, 2021

Thanks for the report.

The behavior is the same, except in chrome pasting triggers both onPaste and onBeforeInput rather than just onPaste

This is also the behavior in React 17 for me.

On the other hand with Firefox, pasting seems to never cause onBeforeInput to be called.

This sounds like a bug to me considering firefox does dispatch an beforeinput native event: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event#simple_logger

@johtso
Copy link
Author

johtso commented Jun 24, 2021

The behavior is the same, except in chrome pasting triggers both onPaste and onBeforeInput rather than just onPaste

This is also the behavior in React 17 for me.

You're right! Well that simplifies things if nothing's changed in 18. Updated my initial description.

From the code comments it seems like the intention is for pasting to not trigger onBeforeInput?

case 'paste':
// If a paste event occurs after a keypress, throw out the input
// chars. Paste events should not lead to BeforeInput events.
return null;

@eps1lon
Copy link
Collaborator

eps1lon commented Jun 24, 2021

Huh. Especially the following sentence is odd:

// chars. Paste events should not lead to BeforeInput events.

I'm not sure where they took the "should" from because that's not following current browser implementations. Would be nice to find out what the purpose of this change was.

Though I think this particular issue is already tracked in #11211 because in FireFox onBeforeInput would trigger if the native event would be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: DOM Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants