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

[Overlay] Split out AutoLockScrolling #3690

Merged
merged 1 commit into from
Apr 3, 2016

Conversation

cgestes
Copy link
Contributor

@cgestes cgestes commented Mar 14, 2016

One component, one feature.

AutoLockScrolling is useful on it's own.

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

@alitaheri
Copy link
Member

This is very interesting 👍 👍

}
}

_preventScrolling() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the _ from our methods and properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@chrismcv
Copy link
Contributor

There are issues with AutoLockScrolling in the current implementation with nested dialogs, when they unmount out of order. This component doesn't make it better or worse, but would be great to consider it as well when thinking about this.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 14, 2016

@chrismcv tried a fix :)

@cgestes
Copy link
Contributor Author

cgestes commented Mar 16, 2016

gentle ping :)

@oliviertassinari
Copy link
Member

@chrismcv Is right, the AutoLockScrolling is not handling correctly multiple mounted instances. Sorry @cgestes but I don't think that your fix is perfect 😁. I think that the scroll should be locked as soon as one <AutoLockScrolling /> is asking for it.

This really remembers me issues with concurrent access to resources like memory in a multi-thread environment.

What do you think about using a semaphore?
Each token would represent the access to the lock resource. We would only unlocked the screen once all tokens are returned.

@oliviertassinari
Copy link
Member

@cgestes What do you think about just extracting the AutoLockScrolling component in this PR, then tackling the nested issue? (too hard to review like this)

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Mar 16, 2016
@alitaheri
Copy link
Member

What do you think about using a semaphore?

That's really interesting 👍 I think it's the best approach. just keep an integer ( increment with mount decrement with unmount ) and then set with non-zero and set with zero 👍

@cgestes
Copy link
Contributor Author

cgestes commented Mar 16, 2016

@alitaheri & @oliviertassinari I did not know the locker was not supposed to be the unlocker.

Will implement it with a counter, thanks for the idea :)

@chrismcv
Copy link
Contributor

sorry - been a busy day... I agree, in that I don't think the suggested fix would work. In my head, moving the lock variable outside the component this scope would be adequate, but counter approach works well too - again - I'm pretty sure it needs to be outside the this scope.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

updated the PR with a semaphore :)

@oliviertassinari oliviertassinari added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 17, 2016
@chrismcv
Copy link
Contributor

This looks good to me :)

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

Reviewing the commit again...

I dont think it is...

I'll add inline comments

}

allowScrolling() {
lockingCounter = lockingCounter - 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should decrement only if we incremented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a bad feeling that if we switch the lock property on/off while the component is mounted it might go wrong. not sure.

I have a plane to take, so I'll have to check it again carefully later.

Copy link
Contributor

Choose a reason for hiding this comment

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

why? I can't see a problem with always incrementing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fear that we can double increment while decrementing only once. or the reverse.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

I'll add an extra security.

I believe if we have lock = false we decrease the counter without having incremented it.

Please dont merge now.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

I believe this time everything is ok.

It will only unlock if it has been locked.

What do you think?

@oliviertassinari
Copy link
Member

I'm having a new look at this PR.
I don't think that we need the this.locked variable. I think that lockingCounter is enough.

Can we add some unit test to this component?
Each line of code matters here, regressions are likely.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

from what I understand we do.

  • if lock is false the counter get decremented in CWU but never incremented
  • the code is safer to reason about

and better be safe when we play with a global semaphore.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 17, 2016

The code is not gonna evolve a lot. it's just a simple component doing one thing with no possible side effect.
It's nice to have test, but that's not critical for that kind of code from my own experience.

I'll try to add some when I'll come back from ski in 10 days.

I'am not sure how to do unittest which have impact on the DOM.

@oliviertassinari oliviertassinari self-assigned this Mar 18, 2016
@oliviertassinari
Copy link
Member

I'll come back from ski in 10 days.

@cgestes Enjoy ❄️!

@cgestes
Copy link
Contributor Author

cgestes commented Mar 28, 2016

rebased :)

@nathanmarks
Copy link
Member

@cgestes Looks like rebasing went a bit haywire, can you try again?

@cgestes
Copy link
Contributor Author

cgestes commented Mar 28, 2016

fixed. sorry for the inconvenient.

@oliviertassinari
Copy link
Member

@cgestes That seems to work correctly 👍. I'm fine with merging this PR.
But I have some remarks:

  • I think that we can handle the logic without the locked variable. I can't see cases where allowScrolling or disallowScrolling would not increment / decrement the counter correctly.
  • We could be using the ES7 class properties for the locked and not calling the constructor()
  • Some test would be awesome if we want to easily refactor this component later.

@@ -131,7 +94,9 @@ const Overlay = React.createClass({
const styles = getStyles(this.props, this.state);

return (
<div {...other} ref="overlay" style={prepareStyles(Object.assign(styles.root, style))} />
<div {...other} ref="overlay" style={prepareStyles(Object.assign(styles.root, style))}>
{this.props.autoLockScrolling && <AutoLockScrolling lock={this.props.show} />}
Copy link
Member

Choose a reason for hiding this comment

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

The show variable is already destructured. We can use it. It would be good to do the same with autoLockScrolling.

{autoLockScrolling && <AutoLockScrolling lock={show} />}

@mbrookes mbrookes added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 29, 2016
@cgestes
Copy link
Contributor Author

cgestes commented Mar 29, 2016

this.locked is extra safety and code readability.

For example when you mount with lock=false and you unmount this ensure that the counter is not decremented.

@cgestes
Copy link
Contributor Author

cgestes commented Mar 29, 2016

rebased on @mbrookes changes :)

@mbrookes mbrookes removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 29, 2016
@oliviertassinari
Copy link
Member

For example when you mount with lock=false and you unmount this ensure that the counter is not decremented.

True, we had this line to prevent this issue.

rebased on @mbrookes changes :)

Thanks.

@mbrookes mbrookes added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 2, 2016
@cgestes
Copy link
Contributor Author

cgestes commented Apr 2, 2016

second rebase done :)

@oliviertassinari oliviertassinari removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 3, 2016
@mbrookes mbrookes merged commit 839a554 into mui:master Apr 3, 2016
@zannager zannager added the package: system Specific to @mui/system label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants