Skip to content

Commit

Permalink
test: fix warn 'Maximum recursive updates exceeded' (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed May 20, 2022
1 parent 82c929d commit 0967d4c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/cdk/scroll/src/virtual/contents/Holder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import type { OriginScroll } from '../composables/useOriginScroll'
import type { CSSProperties, Ref } from 'vue'

import { computed, defineComponent, inject, onBeforeUnmount, ref } from 'vue'
import { computed, defineComponent, inject, onBeforeUnmount, onMounted, ref } from 'vue'

import { throttle } from 'lodash-es'

import { useResizeObserver } from '@idux/cdk/resize'
import { offResize, onResize } from '@idux/cdk/resize'
import { callEmit, cancelRAF, off, on, rAF } from '@idux/cdk/utils'

import { virtualScrollToken } from '../token'
Expand Down Expand Up @@ -78,7 +78,12 @@ export default defineComponent({
}

const { handleWheel, handleTouchStart } = useEvents(holderRef, syncScrollTop, originScroll)
const { contentRef } = useContentResize(collectHeights)

const contentRef = ref<HTMLDivElement>()
const onContentResize = throttle(collectHeights, 16)
// 这里不能用 useResizeObserver, 会有 test 爆栈警告, 具体原因后面再排查。
onMounted(() => onResize(contentRef.value, onContentResize))
onBeforeUnmount(() => offResize(contentRef.value, onContentResize))

return () => {
const virtual = useVirtual.value
Expand Down Expand Up @@ -204,12 +209,3 @@ function useEvents(

return { handleWheel, handleTouchStart }
}

function useContentResize(collectHeights: () => void) {
const contentRef = ref<HTMLDivElement>()
const onContentResize = throttle(collectHeights, 16)

useResizeObserver(contentRef, onContentResize)

return { contentRef }
}

0 comments on commit 0967d4c

Please sign in to comment.