-
-
Notifications
You must be signed in to change notification settings - Fork 815
Pass correct arguments to onFinished in Modal #224
Conversation
src/Modal.js
Outdated
| ReactDOM.unmountComponentAtNode(self.getOrCreateContainer()); | ||
|
|
||
| if (props && props.onFinished) props.onFinished.apply(null, arguments); | ||
| if (props && props.onFinished) props.onFinished.call(null, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right - i assume someone passed in closeDialog's arguments to the onFinished prop for a reason... What is the rationale for switching from apply() to call()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I did some searching but couldn't find a case where that was actually used (the event that caused the dialog to be closed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserSettings.onEmailDialogFinished is a similar onFinished callback and expects its first argument to be whether the dialog was accepted or dismissed. It should probably have the same bug (as leave room)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that code was added in d938ba7, which also carries this bug (and does not use arguments in any way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this has been the case every since Modal.js was first written in element-hq/element-web@1b43586
Either way, your fix always passes false to onFinished which means the user won't leave then room even if they click OK. The correct fix here is to explicitly call closeDialog(false) in the background div onClick handler rather than using it as the onClick handler directly (since the event handler will be passed an event as an argument which, when it propagates down to the onFinished handler, will evaluate to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, @dbkr, just did not notice that (or test it.) Is there any plan to add e2e tests for situations like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we need tests in general in vector.
|
I tried to dig into this last night as part of element-hq/element-web#1121 and got completely stuck - the Modal.js API seems entirely confused here in terms of how it handles onFinished(). @aviraldg: looks like you picked one of the most tangled bits of the codebase for a quick fix - sorry! am working through it IRL with @dbkr now. |
|
Okay - so there were two confusions here:
I've fixed both in #232. Huge thanks for doing the initial digging on this, and sorry that Modal.js is such a mess. Totally agreed that we urgently need UI-layer tests on vector, via karma or selenium or whatever. Patches welcome... |
Fixes element-hq/element-web#1169
Works, and I couldn't find a case where this breaks existing behaviour, but since there are no tests to verify I can't be sure.