fix(NcReferenceWidget): use nextTick rather than animation frame

Seems more light weight and also fixes the cypress tests

Also add comments as to why we are using nextTick
in the resizeObserver.

Signed-off-by: Max <max@nextcloud.com>
This commit is contained in:
Max 2024-05-08 07:38:22 +02:00 коммит произвёл backportbot[bot]
Родитель c84efacd3d
Коммит d73a7b828a
1 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -30,7 +30,7 @@
</template>
<script>
import { useIntersectionObserver, useResizeObserver } from '@vueuse/core'
import { ref } from 'vue'
import { nextTick, ref } from 'vue'
import { RouterLink } from 'vue-router'
import { t } from '../../l10n.js'
@ -67,15 +67,25 @@ export default {
// This is the widget root node
const widgetRoot = ref()
useIntersectionObserver(widgetRoot, (entries) => {
window.requestAnimationFrame(() => {
isVisible.value = entries[0]?.isIntersecting ?? false
useIntersectionObserver(widgetRoot, () => {
nextTick(() => {
isVisible.value = widgetRoot.value?.isIntersecting ?? false
})
})
useResizeObserver(widgetRoot, (entries) => {
window.requestAnimationFrame(() => {
width.value = entries[0].contentRect.width
/**
* Measure the width of the widgetRoot after a resize
*/
useResizeObserver(widgetRoot, () => {
/**
* Wait till the next tick to allow the resize to finish first
* and avoid triggering content updates during the resize.
*
* Without the nextTick we were seeing crashing browsers
* in cypress tests.
*/
nextTick(() => {
width.value = widgetRoot.value?.contentRect.width ?? 0
})
})