-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add ShinyResizeObserver #566
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To avoid contention between outputs within both cards and sidebars
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
@cpsievert This is ready for another review – I have an open PR to add a test to shinycoreci that I will update tomorrow to be automated rather than manual. |
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 8, 2023
cpsievert
reviewed
May 9, 2023
cpsievert
approved these changes
May 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a layer of abstraction around our use of ResizeObservers that will unify our approach to both sidebars and cards.
ShinyResizeObserver
It also improves our use of ResizeObservers:
In particular this PR ensures that contents within a sidebar resize during sidebar transition even when the sidebar appears alone on the page and not within a card.
We now instantiate a single ResizeObserver in the client and use the same ResizeObserver to observe the main areas of any sidebar instances, rather than creating a new ResizeObserver for each sidebar instance.
The
ShinyResizeObserver
class includes a.flush()
method that cleans up observers on elements that are no longer present in the document. In practice, this is called whenever new sidebars are added to the page (and not on pageload), and serves as a light-weight way to ensure that we don't leak memory by keeping references to removed elements.A new feature of the
ShinyResizeObserver
temporarily setswidth
to100%
for plot images during the transition. This allows the image to stretch during the transition; after the transition is complete the image is replaced by the server with a new plot image matching the final container dimensions.The
ShinyResizeObserver
handles contention for the same output by multiple observers.In the case of nested sidebars, an output may be observed by both the outer and inner sidebars. The callback automatically keeps track of which elements have already been handled by the same callback during a resize event cycle.
We also prevent multiple instances of
ShinyResizeObserver
from updating the same output by assigning ownership of an output to the first observer to arrive at the output. This will allow us to use separate instances ofShinyResizeObserver
for cards and sidebars without having to worry about duplicating resize requests.TODO
window
. And our RO doesn't do anything anyway unless we find a.shiny-bound-input
, which should only happen in a Shiny context.Preview
ggplot2 "static"
plotOutput()
Kapture.2023-05-05.at.16.48.33.mp4
Plotly "dynamic" htmlwidget
Kapture.2023-05-05.at.16.50.05.mp4