-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fix height adjustment in ZoomElement in Safari #21174
Conversation
Problem, as described in [this thread](storybookjs#21138 (review)) affects stories rendered with custom elements using Shadow DOM. Such stories are affected if at the moment ZoomElement measures the height, component did not yet render its contents. Then, when component in a story renders content, it doesn't trigger MutationObserver (mutation callback is not called when Shadow DOM is altered). ResizeObserver is added next to MutationObserver (orignally added via storybookjs#15472), not replaces it, because MutationObserver is better supported by older browsers than ResizeObserver. Problem, as described in the original thread was mitigated by @JReinhold with storybookjs#21163, but even after that fix Safari is excluded from using native `zoom` and needs the fallback behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! How do I test this? Do I just need a setup using web components that changes size over time?
I think we should replace the mutation observer completely with the resize observer because:
- Can I Use shows a great support table for it, and works for all the browsers and versions we support in 7.0.
- It was already introduced in another part of the UI recently as part of Tab UI Improvements #20783, so we've sort of already made it a requirement.
Good point. I will try to provide some reproduction example, but until I find time to get it right
|
@JReinhold I added a repository that reproduces the problem on
If there's a way to integrate that in this repo instead of having a distinct one, please guide me how can I do it the right way.
Let's clarify: do you want me to replace |
Great!
I don't think that'll be necessary in this case.
yup! |
As requested by @JReinhold in storybookjs#21174 (review)
Can be tested with jrencz/storybook-lity-story-height-repro@da1369a with combination of Zoom in/Zoom out on controls and button to alter height of component added in that commit
It should be all right now. I extended the demo and found and fixed a problem, which I initially didn't notice (see commit message of c8509fb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for your contribution!
What I did
I replaced a mutation observer with the hook
useResizeObserver
inside ZoomElement in order to make stories using custom elements resize properly in SafariProblem is visualized in #21138 (comment)
Problem, as described in this thread affects stories rendered with custom elements using Shadow DOM. Such stories are affected if at the moment ZoomElement measures the height, component did not yet render its contents. Then, when component in a story renders content, it doesn't trigger MutationObserver (mutation callback is not called when Shadow DOM is altered).
ResizeObserver replaces the existing MutationObserver (orignally added via #15472).
Problem, as described in the original thread was mitigated by @JReinhold with #21163, but even after that fix Safari is excluded from using native
zoom
and needs the fallback behavior.How to test
See https://github.com/jrencz/storybook-lity-story-height-repro
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]