Skip to content
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

feat(useResizeObserver): add ResizeObserver using when supported #8055

Merged
merged 9 commits into from
Dec 11, 2024

Conversation

EldarMuhamethanov
Copy link
Contributor

@EldarMuhamethanov EldarMuhamethanov commented Dec 9, 2024

  • Unit-тесты
  • Release notes

Описание

Когда нам надо было реагировать на размеры компонента или отдельной его части. Мы подписывались на событие resize всего window. Это в основном покрывает большую часть кейсов, но не все. Есть кейсы когда размеры компонента могут поменять, даже когда размер окна не поменялся. Это приводит к багам. Поэтому появляется потребность отслеживать изменения самого компонента. Это можно сделать с помощью ResizeObserver, но он не поддерживается всем браузерами, которые поддерживаем мы. Поэтому у нас есть CustomResizeObserver, который на некотором уровне выполняет функционал ResizeObserver, но все равно хуже. В связи с этим нужно доработать хук useResizeObserver так, чтобы по возможности он использовать ResizeObserver вместо CustomResizeObserver там где это возможно

Изменения

  • Доработал хук useResizeObserver, так чтобы он мог использовать ResizeObserver при наличии его.
  • Доработал хук useResizeObserver, так чтобы он мог принимать в качестве ref window. В таком случае будет использовать нативный addEventListener('resize'...)
  • Добавил использование хука useResizeObserver в BaseGallery и CarouselBase, чтобы обрабатывать кейсы, когда размеры контейнера изменились и произошел пересчет позиций слайдов
  • Выпилил useGlobalEventListener(window, 'resize'), вместо него добавил useResizeObserver(window, () => {})
  • Добавил свойство resizeSource, данное свойство позволяет выбрать тип источника для отслеживания размера:

Release notes

Улучшения

  • Gallery: добавлено свойство resizeSource для возможности выбрать тип источника, на котором нужно отслеживать изменения размеров
    • 'window' – пересчет позиции слайдов будет происходить при изменении размеров window
    • 'element' – пересчет позиции слайдов будет происходить при изменении размеров компонента

Copy link

codesandbox-ci bot commented Dec 9, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Contributor

github-actions bot commented Dec 9, 2024

size-limit report 📦

Path Size
JS 391.52 KB (+0.08% 🔺)
JS (gzip) 118.44 KB (+0.13% 🔺)
JS (brotli) 97.45 KB (+0.21% 🔺)
JS import Div (tree shaking) 1.56 KB (0%)
CSS 340.75 KB (0%)
CSS (gzip) 42.18 KB (0%)
CSS (brotli) 33.56 KB (0%)

Copy link
Contributor

github-actions bot commented Dec 9, 2024

e2e tests

⚠️ Some screenshots were failed. See Playwright Report.

Playwright Report

Copy link
Contributor

github-actions bot commented Dec 9, 2024

👀 Docs deployed

Commit e1312c1

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.55%. Comparing base (5d5a08e) to head (e1312c1).
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8055      +/-   ##
==========================================
+ Coverage   95.53%   95.55%   +0.02%     
==========================================
  Files         398      398              
  Lines       11313    11321       +8     
  Branches     3737     3743       +6     
==========================================
+ Hits        10808    10818      +10     
+ Misses        505      503       -2     
Flag Coverage Δ
unittests 95.55% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@andrey-medvedev-vk andrey-medvedev-vk left a comment

Choose a reason for hiding this comment

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

Класс! 👍


Можно только немножко подробнее в PR или в Release notes расписать саму проблему?

Исправлена проблема с ресайзом контейнера

А то в изменениях про это есть, но оно не бросается в глаза.

Copy link
Contributor

@andrey-medvedev-vk andrey-medvedev-vk left a comment

Choose a reason for hiding this comment

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

💅

inomdzhon
inomdzhon previously approved these changes Dec 11, 2024
Copy link
Contributor

@inomdzhon inomdzhon left a comment

Choose a reason for hiding this comment

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

🙏 👏 🚀

# Conflicts:
#	packages/vkui/src/hooks/useResizeObserver.ts
@EldarMuhamethanov EldarMuhamethanov merged commit 691f411 into master Dec 11, 2024
28 checks passed
@EldarMuhamethanov EldarMuhamethanov deleted the e.muhamethanov/add-resize-overser-use branch December 11, 2024 14:50
BlackySoul pushed a commit that referenced this pull request Dec 16, 2024
* feat(useResizeObserver): add ResizeObserver using when supported

* fix(Gallery): add handle resize Gallery container and remove window resize handler

* test(useResizeObserver, Gallery): fix tests with mock ResizeObserver

* fix(Gallery): add condition to use resize hooks

* feat(useResizeObserver): add logic with window in parameter

* feat(Gallery): add prop resizeSource

* doc(Gallery): fix doc description

* fix(useResizeObserver): run prettier
@vkcom-publisher
Copy link
Contributor

v7.1.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants