Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Svelte: add mutation observer to sizeToFit#63620

Merged
camdencheek merged 1 commit into
mainfrom
cc/trigger-resize-on-mutation
Jul 3, 2024
Merged

Svelte: add mutation observer to sizeToFit#63620
camdencheek merged 1 commit into
mainfrom
cc/trigger-resize-on-mutation

Conversation

@camdencheek

Copy link
Copy Markdown
Member

Previously, this only listened for resize events. However, shrink/grow might also be required if the contents of the element change. This adds a MutationObserver to sizeToFit to recalculate the sizing when the element (or its children) is mutated.

Fixes SRCH-679

Test plan

https://share.cleanshot.com/Xdz6g16m

@cla-bot cla-bot Bot added the cla-signed label Jul 3, 2024
@camdencheek camdencheek marked this pull request as ready for review July 3, 2024 18:05
@camdencheek camdencheek requested a review from a team July 3, 2024 18:05
const resizeObserver = new ResizeObserver(resizeOnce)
resizeObserver.observe(target)
const mutationObserver = new MutationObserver(resizeOnce)
mutationObserver.observe(target, { attributes: true, childList: true, characterData: true, subtree: true })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need attributes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attributes can change the size of the element, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess if style or class changes... yeah.

@camdencheek camdencheek merged commit aa0eecd into main Jul 3, 2024
@camdencheek camdencheek deleted the cc/trigger-resize-on-mutation branch July 3, 2024 18:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants