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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ContextMenuTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export default class ContextMenuTrigger extends Component {
id: this.props.id
};
if (data && (typeof data.then === 'function')) {
// it's promise
// 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
Comment on lines +129 to 134
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

Expand Down
Loading