From b39f3648a7944a23cf4c1d9d324e320129e9d3ab Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 26 Apr 2018 19:39:10 +0200 Subject: [PATCH 1/3] Tentative fix for #446 --- app/javascript/flavours/glitch/components/status.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index a6c08ba1c..62aa35aae 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -69,6 +69,7 @@ export default class Status extends ImmutablePureComponent { 'collapse', 'notification', 'hidden', + 'expanded', ] updateOnStates = [ From 1222e0a38178d24e9f7d4bbc996d6f7947e8137b Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 26 Apr 2018 20:23:25 +0200 Subject: [PATCH 2/3] Use new getDerivedStateFromProps instead of deprecated componentWillReceiveProps As we are already using the new getSnapshotBeforeUpdate lifecycle method, we apparently cannot use the deprecated ones at all in this component. --- .../flavours/glitch/components/status.js | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 62aa35aae..bff396f04 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -51,7 +51,6 @@ export default class Status extends ImmutablePureComponent { }; state = { - isExpanded: this.props.expanded, isCollapsed: false, autoCollapsed: false, } @@ -80,23 +79,48 @@ export default class Status extends ImmutablePureComponent { // If our settings have changed to disable collapsed statuses, then we // need to make sure that we uncollapse every one. We do that by watching // for changes to `settings.collapsed.enabled` in - // `componentWillReceiveProps()`. + // `getderivedStateFromProps()`. // We also need to watch for changes on the `collapse` prop---if this // changes to anything other than `undefined`, then we need to collapse or // uncollapse our status accordingly. - componentWillReceiveProps (nextProps) { + static getDerivedStateFromProps(nextProps, prevState) { + let update = {}; + let updated = false; + + // Make sure the state mirrors props we trackā€¦ + if (nextProps.collapse !== prevState.collapseProp) { + update.collapseProp = nextProps.collapse; + updated = true; + } + if (nextProps.expanded !== prevState.expandedProp) { + update.expandedProp = nextProps.expanded; + updated = true; + } + + // Update state based on new props if (!nextProps.settings.getIn(['collapsed', 'enabled'])) { - if (this.state.isCollapsed) { - this.setCollapsed(false); + if (prevState.isCollapsed) { + update.isCollapsed = false; + updated = true; } } else if ( - nextProps.collapse !== this.props.collapse && + nextProps.collapse !== prevState.collapseProp && nextProps.collapse !== undefined - ) this.setCollapsed(nextProps.collapse); - if (nextProps.expanded !== this.props.expanded && + ) { + update.isCollapsed = nextProps.collapse; + if (nextProps.collapse) update.isExpanded = false; + updated = true; + } + if (nextProps.expanded !== prevState.expandedProp && nextProps.expanded !== undefined - ) this.setExpansion(nextProps.expanded); + ) { + update.isExpanded = nextProps.expanded; + if (nextProps.expanded) update.isCollapsed = false; + updated = true; + } + + return updated ? update : null; } // When mounting, we just check to see if our status should be collapsed, From 0ce06657c0e1a79d3cc237e243ba8c262bbad2d5 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 27 Apr 2018 00:45:44 +0200 Subject: [PATCH 3/3] Update react-redux to 5.0.7 to fix an issue with getDerivedStateFromProps --- yarn.lock | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/yarn.lock b/yarn.lock index ea54790c3..0513845eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3233,10 +3233,14 @@ hoek@4.x.x: version "4.2.0" resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d" -hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0: +hoist-non-react-statics@^2.3.0: version "2.3.1" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0" +hoist-non-react-statics@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40" + home-or-tmp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" @@ -3477,7 +3481,13 @@ intl@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/intl/-/intl-1.2.5.tgz#82244a2190c4e419f8371f5aa34daa3420e2abde" -invariant@^2.0.0, invariant@^2.1.1, invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2: +invariant@^2.0.0: + version "2.2.4" + resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" + dependencies: + loose-envify "^1.0.0" + +invariant@^2.1.1, invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" dependencies: @@ -4271,7 +4281,11 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash-es@^4.2.0, lodash-es@^4.2.1: +lodash-es@^4.17.5: + version "4.17.10" + resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05" + +lodash-es@^4.2.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7" @@ -4381,10 +4395,14 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.4: +"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" +lodash@^4.17.5, lodash@^4.2.0: + version "4.17.10" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" + loglevel@^1.4.1: version "1.6.0" resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.0.tgz#ae0caa561111498c5ba13723d6fb631d24003934" @@ -6083,15 +6101,15 @@ react-redux-loading-bar@^2.9.3: prop-types "^15.5.6" react-redux@^5.0.4: - version "5.0.6" - resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.6.tgz#23ed3a4f986359d68b5212eaaa681e60d6574946" + version "5.0.7" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.7.tgz#0dc1076d9afb4670f993ffaef44b8f8c1155a4c8" dependencies: - hoist-non-react-statics "^2.2.1" + hoist-non-react-statics "^2.5.0" invariant "^2.0.0" - lodash "^4.2.0" - lodash-es "^4.2.0" + lodash "^4.17.5" + lodash-es "^4.17.5" loose-envify "^1.1.0" - prop-types "^15.5.10" + prop-types "^15.6.0" react-router-dom@^4.1.1: version "4.2.2"