Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

CreateRoomDialog is rendered before getting the config default_federate #2078

Merged

Conversation

psaavedra
Copy link
Contributor

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
(Ref: https://stackoverflow.com/questions/45337165/react-render-is-being-called-before-componentdidmount and https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/birth/premounting_with_componentwillmount.html )

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 psaavedra@igalia.com

@psaavedra psaavedra force-pushed the fix_render_in_CreateRoomDialog branch 6 times, most recently from f199e9b to c9e3d23 Compare July 23, 2018 13:24
@t3chguy
Copy link
Member

t3chguy commented Jul 23, 2018

The intent is for the checkbox to remain uncontrolled, so the setState and onChange stuff is undesirable. The will/did mount stuff is a good spot though

@psaavedra psaavedra force-pushed the fix_render_in_CreateRoomDialog branch 2 times, most recently from be0da25 to 8f68cdd Compare July 23, 2018 15:16
@psaavedra
Copy link
Contributor Author

New version for the patch sent

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()`.

This patch makes this change to fix the described issue:

* componentWillMount instead of componentDidMount

Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
@psaavedra psaavedra force-pushed the fix_render_in_CreateRoomDialog branch from 8f68cdd to 77ab7d2 Compare July 23, 2018 15:52
@psaavedra
Copy link
Contributor Author

WDYT, can be merged?

@t3chguy
Copy link
Member

t3chguy commented Jul 24, 2018

I'll definitely review this today

@t3chguy
Copy link
Member

t3chguy commented Jul 24, 2018

Yup thanks for this

@t3chguy t3chguy merged commit fe3850d into matrix-org:develop Jul 24, 2018
@psaavedra psaavedra deleted the fix_render_in_CreateRoomDialog branch July 25, 2018 07:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants