-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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 expiring polls not being displayed as such in the WebUI #11835
Conversation
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 is very likely to run into issues when components are re-used by the renderer and passed completely different props.
Good point (although honestly that's not something that should happen 😩), I'll look into that |
@@ -32,8 +32,36 @@ class Poll extends ImmutablePureComponent { | |||
|
|||
state = { | |||
selected: {}, | |||
expired: this.props.poll.get('expired') || (new Date(this.props.poll.get('expires_at'))).getTime() < this.props.intl.now(), |
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.
Set this to null.
Create _setupTimer
method. Call this method from componentDidMount
. Call this method from componentWillReceiveProps
if nextProps.poll.get('expired') !== this.props.poll.get('expired')
etc.
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.
Setting it to null and then changing it in componentDidMount
would incur an useless extra render cycle for every poll.
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.
Well, realistically, there's no reason to store expired
in state, for example RelativeTimestamp
component stores current timestamp in the state, and then the render method takes care of calculating the difference. That's probably the cleanest approach.
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.
I'd say there's no reason to store the current timestamp either, tbh.
Changed it to not use the deprecated componentWillReceiveProps
and refactor it, it's cleaner imho, and should not do useless renders. However, it will re-fire the timer each time a poll gets updated even if its expiration date does not change. This is infrequent and cheaper than a render, though.
366fa72
to
d489216
Compare
d489216
to
59a201d
Compare
…#11835) * Fix expiring polls not being displayed as such in the WebUI * Reset expiration state and timer when a poll changes * Refactor timer logic in `_setupTimer`, only set expiration if props have changed * Refactor and do not use deprecated React lifecycles
No description provided.