From be0da25d59efe9f9e30260052cc2de82829c2f90 Mon Sep 17 00:00:00 2001 From: Pablo Saavedra Date: Mon, 23 Jul 2018 14:23:54 +0200 Subject: [PATCH] CreateRoomDialog is rendered before get the config default_federate value In React the order of the execution of mount and render functions is: `componentWillMount --> render --> componentDidMount` The `CreateRoomDialog` `render()` function is executed before than the `componentDidMount()` function so the `this.defaultNoFederate = config.default_federate === false;` ; instruction which is executed in the `componentDidMount` function (in `CreateRoomDialog`) is evaluated always after than the rendering of the page. Therefore, the obvious issue is that the values obtained from the `SdkConfig.get()` function (`config.default_federate`) are obtained later than their usage on `render()`. On other hand, if the `render()` method depends on some other data a part of props, you need tell React that the component needs re-rendering by calling setState(). This is need to say React that the status of the checkbox was toggled. (Ref: https://reactjs.org/docs/react-component.html#setstate) This patch made those changes to fix the described issues: * componentWillMount instead of componentDidMount * add toggleDefaultNoFederate to keep synced the status of the property Signed-off-by: Pablo Saavedra --- src/components/views/dialogs/CreateRoomDialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index 3b5369e8f688..3212e53c05f6 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -26,7 +26,7 @@ export default React.createClass({ onFinished: PropTypes.func.isRequired, }, - componentDidMount: function() { + componentWillMount: function() { const config = SdkConfig.get(); // Dialog shows inverse of m.federate (noFederate) strict false check to skip undefined check (default = true) this.defaultNoFederate = config.default_federate === false;