Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Conversation

@aviraldg
Copy link
Contributor

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.

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);
Copy link
Member

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()?

Copy link
Contributor Author

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)

Copy link
Contributor Author

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)

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@dbkr dbkr removed their assignment Mar 17, 2016
@ara4n
Copy link
Member

ara4n commented Mar 18, 2016

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.

@dbkr dbkr assigned ara4n and unassigned dbkr Mar 18, 2016
@ara4n
Copy link
Member

ara4n commented Mar 18, 2016

Okay - so there were two confusions here:

  1. mx_Dialog_background's onClick needs to pass false through to onFinished() rather than an object. The right place to do this is at the onClick - see deaa5c3#diff-3ddc036af206541151e86f03cfc0c0eeR54. This is because closeDialog() can be called from multiple places (the .close() method on the returned dialog object; the onFinished() of the wrapped Element) and still needs to pass through whatever arguments it takes to onFinished() - we can't just have it always pass through false. This is correctly using apply(null, arguments) in case there are more than one arguments to be passed.
  2. Modal.createDialogWithElement()'s onFinished semantics were completely broken, and has been remove entirely.

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...

@ara4n ara4n closed this Mar 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants