Skip to content

Component with mixins: componentWillUnmount should be called in reverse order (of componentDidMount) #2789

Closed
@rickbeerendonk

Description

@rickbeerendonk

componentDidMount() and componentWillUnmount() allow for DOM manipulation outside React's reach. DOM manipulations done in componentDidMount() should be undone in reverse order in componentWillUnmount(). This is currently not possible in components with mixins (see footnote) due to the order in which the events are fired:

Current order:

  1. mixin1.componentDidMount()
  2. mixin2.componentDidMount()
  3. component.componentDidMount()
  4. mixin1.componentWillUnmount()
  5. mixin2.componentWillUnmount()
  6. component.componentWillUnmount()

Correct order:

  1. mixin1.componentDidMount()
  2. mixin2.componentDidMount()
  3. component.componentDidMount()
  4. component.componentWillUnmount()
  5. mixin2.componentWillUnmount()
  6. mixin1.componentWillUnmount()

JSFiddle: http://jsfiddle.net/rickbeerendonk/3cm3sso5/

Full lifecycle example: https://github.com/rickbeerendonk/react-om-examples/blob/d59eda2b67e07d345a44f9552a2ab231b4127f8a/Extra%2002a.%20ComponentLifecycle%20with%20Mixins/jsx/index.html

Footnote: If all the mixins and the component with those mixins are manipulating the DOM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions