New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'before-unmount' is called after destroying the DOM on child tags #2480

Closed
continuata opened this Issue Nov 3, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@continuata
Contributor

continuata commented Nov 3, 2017

  1. Describe your issue:
    Unmounting a parent destroys the DOM (and virtual DOM on IE) of child tags before the lifecycle methods are called.
    This is caused by the fact that unmount traverses the tree of tags top-down. It therefore performs an unmount and an innerHTML = '' at each level. So all child tags are destroyed before even getting there. When the 'before-unmount' lifecycle method is called there is nothing in the DOM to query. In Chrome it seems to keep a reference to the virtual DOM, so it is possible to query refs in 'before-unmount' in a child tag, this is not possible in IE ... and may not be possible in Chrome in the future or in other browsers depending on garbage collection. Unmounting should work from bottom up so that each tag is alive when its lifecycle method is called.

  2. Can you reproduce the issue?
    http://jsfiddle.net/continuata/LzxnLjek/2/
    Run the code, then unmount the child ... you can see the DOM in the lifecycle method
    Run the code, then unmount the parent ... you will see the DOM element is null in the lifecycle method

  3. On which browser/OS does the issue appear?
    All .. but IE also has no access to virtual DOM as well as real DOM, due to it garbage collecting in a different way.

  4. Which version of Riot does it affect?
    All ASFAIK

  5. How would you tag this issue?

  • Question
  • [ x ] Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@continuata

This comment has been minimized.

Show comment
Hide comment
@continuata

continuata Nov 3, 2017

Contributor

I've also just encountered this same issue on other lifecycle methods. (e.g. update)
The update event was called on a child that was attempting to perform DOM operations after its parent was unmounted ... and the element had already been nuked (by innerHTML = '' on the parent)

Contributor

continuata commented Nov 3, 2017

I've also just encountered this same issue on other lifecycle methods. (e.g. update)
The update event was called on a child that was attempting to perform DOM operations after its parent was unmounted ... and the element had already been nuked (by innerHTML = '' on the parent)

@continuata

This comment has been minimized.

Show comment
Hide comment
@continuata

continuata Nov 3, 2017

Contributor

I am looking at a proposed fix for this bug now, will raise a PR when I have a solution and you can comment on whether you agree or not.

Contributor

continuata commented Nov 3, 2017

I am looking at a proposed fix for this bug now, will raise a PR when I have a solution and you can comment on whether you agree or not.

GianlucaGuarini added a commit that referenced this issue Nov 5, 2017

Merge branch 'feature/refactor-unmount' into dev
* feature/refactor-unmount:
  updated: closes #2480 and refactor expressions parsing and unmount method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment