Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
b00cb2ae
Commit
b00cb2ae
authored
7 years ago
by
Nolan Lawson
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve shouldComponentUpdate for status and status_action_bar (#3323)
parent
7c67cb59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/javascript/mastodon/components/status.js
+29
-8
29 additions, 8 deletions
app/javascript/mastodon/components/status.js
app/javascript/mastodon/components/status_action_bar.js
+10
-1
10 additions, 1 deletion
app/javascript/mastodon/components/status_action_bar.js
with
39 additions
and
9 deletions
app/javascript/mastodon/components/status.js
+
29
−
8
View file @
b00cb2ae
...
...
@@ -44,6 +44,35 @@ class Status extends ImmutablePureComponent {
isHidden
:
false
,
}
// Avoid checking props that are functions (and whose equality will always
// evaluate to false. See react-immutable-pure-component for usage.
updateOnProps
=
[
'
status
'
,
'
account
'
,
'
wrapped
'
,
'
me
'
,
'
boostModal
'
,
'
autoPlayGif
'
,
'
muted
'
,
]
updateOnStates
=
[]
shouldComponentUpdate
(
nextProps
,
nextState
)
{
if
(
nextProps
.
isIntersecting
===
false
&&
nextState
.
isHidden
)
{
// It's only if we're not intersecting (i.e. offscreen) and isHidden is true
// that either "isIntersecting" or "isHidden" matter, and then they're
// the only things that matter.
return
this
.
props
.
isIntersecting
!==
false
||
!
this
.
state
.
isHidden
;
}
else
if
(
nextProps
.
isIntersecting
!==
false
&&
this
.
props
.
isIntersecting
===
false
)
{
// If we're going from a non-intersecting state to an intersecting state,
// (i.e. offscreen to onscreen), then we definitely need to re-render
return
true
;
}
// Otherwise, diff based on "updateOnProps" and "updateOnStates"
return
super
.
shouldComponentUpdate
(
nextProps
,
nextState
);
}
componentWillReceiveProps
(
nextProps
)
{
if
(
nextProps
.
isIntersecting
===
false
&&
this
.
props
.
isIntersecting
!==
false
)
{
requestIdleCallback
(()
=>
this
.
setState
({
isHidden
:
true
}));
...
...
@@ -52,14 +81,6 @@ class Status extends ImmutablePureComponent {
}
}
shouldComponentUpdate
(
nextProps
,
nextState
)
{
if
(
nextProps
.
isIntersecting
===
false
&&
this
.
props
.
isIntersecting
!==
false
)
{
return
nextState
.
isHidden
;
}
return
true
;
}
handleRef
=
(
node
)
=>
{
if
(
this
.
props
.
onRef
)
{
this
.
props
.
onRef
(
node
);
...
...
This diff is collapsed.
Click to expand it.
app/javascript/mastodon/components/status_action_bar.js
+
10
−
1
View file @
b00cb2ae
...
...
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import
IconButton
from
'
./icon_button
'
;
import
DropdownMenu
from
'
./dropdown_menu
'
;
import
{
defineMessages
,
injectIntl
}
from
'
react-intl
'
;
import
ImmutablePureComponent
from
'
react-immutable-pure-component
'
;
const
messages
=
defineMessages
({
delete
:
{
id
:
'
status.delete
'
,
defaultMessage
:
'
Delete
'
},
...
...
@@ -21,7 +22,7 @@ const messages = defineMessages({
unmuteConversation
:
{
id
:
'
status.unmute_conversation
'
,
defaultMessage
:
'
Unmute conversation
'
},
});
class
StatusActionBar
extends
React
.
PureComponent
{
class
StatusActionBar
extends
Immutable
PureComponent
{
static
contextTypes
=
{
router
:
PropTypes
.
object
,
...
...
@@ -43,6 +44,14 @@ class StatusActionBar extends React.PureComponent {
intl
:
PropTypes
.
object
.
isRequired
,
};
// Avoid checking props that are functions (and whose equality will always
// evaluate to false. See react-immutable-pure-component for usage.
updateOnProps
=
[
'
status
'
,
'
me
'
,
'
withDismiss
'
,
]
handleReplyClick
=
()
=>
{
this
.
props
.
onReply
(
this
.
props
.
status
,
this
.
context
.
router
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment