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

fix: unpersisted event is handed off into a promise resolution callback #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jstarpl
Copy link

@jstarpl jstarpl commented Jun 14, 2024

The event needs to be persisted before using event.target as that event object can be reused by React by the time the promise resolves.

Copy link

netlify bot commented Jun 14, 2024

Deploy Preview for firefox-devtools-react-contextmenu ready!

Name Link
🔨 Latest commit 9019c38
🔍 Latest deploy log https://app.netlify.com/sites/firefox-devtools-react-contextmenu/deploys/666bee54c90791000852657b
😎 Deploy Preview https://deploy-preview-216--firefox-devtools-react-contextmenu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@julienw
Copy link

julienw commented Jun 24, 2024

Is this a fix for React 16 ?
I see on their website that it's a noop on React 17:
image

@julienw
Copy link

julienw commented Jun 24, 2024

Can you also please share some "steps to reproduce" that would be fixed with your patch?

Comment on lines +129 to 134
// it's promise, the event needs to be persisted, so that React
// doesn't reuse the event object while the data function resolves
event.persist();
data.then((resp) => {
showMenuConfig.data = assign({}, resp, {
target: event.target
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively:

Suggested change
// it's promise, the event needs to be persisted, so that React
// doesn't reuse the event object while the data function resolves
event.persist();
data.then((resp) => {
showMenuConfig.data = assign({}, resp, {
target: event.target
// It's a promise.
// In React 16, event objects can be reused, therefore it's not safe
// to use it directly. Let's keep a reference to the target in a local variable.
const { target } = event;
data.then((resp) => {
showMenuConfig.data = assign({}, resp, {
target

@julienw
Copy link

julienw commented Jun 24, 2024

I've left an alternative solution, but I don't mind using yours if you prefer.
Please at least add a reference to React 16 in the comment so that we can remove this code if we remove the support later.

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.

None yet

2 participants