Open daattali opened 1 year ago
I'm pretty sure https://github.com/rstudio/shiny/pull/3682 (using ResizeObserver()
/IntersectionObserver()
/MutationObserver()
to detect changes in size/visibility) would solve this (as well as a whole other set of issues)
Originally reported in https://github.com/daattali/shinyjs/issues/266
When an element is being hidden from the DOM, a
trigger("hidden")
javacript call needs to be made on that element, to notify shiny to not render it anymore. The classic way to hide an element is using the.hide()
method. However, it seems like elements that are being hidden using animation javascript do not properly get hidden in the reactive graph. Example:In this code, an element is being hidden using jquery's
fadeOut()
. You can see that despite triggering thehidden
event, the output still gets rendered. A similar thing happens when usingslideUp()
instead offadeOut()
.It seems that if you make the animation very fast, for example using
fadeOut(5)
(5 milliseconds), then the trigger does hold.I noticed that if I add a callback function to the animation
fadeOut(500, function() { $(this).trigger('hidden'); })
then it does work correctly. Because of this, my theory is that whenhidden
is triggered, shiny looks at the element, and only acts if the element hasdisplay:none
.