Skip to content

Commit

Permalink
refactor(core): rename observer var
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Nov 10, 2024
1 parent 173c97e commit 56caa45
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/lazyLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function createPlaceholderFromHash(

// Keep track of elements that have a `data-sizes="auto"` attribute
// and need to be updated when their size changes
const resizeElementStore = new WeakMap<HTMLImageElement | HTMLSourceElement, ResizeObserver>()
const elementResizeObserverMap = new WeakMap<HTMLImageElement | HTMLSourceElement, ResizeObserver>()

function updateSizesAttribute(
element: HTMLImageElement | HTMLSourceElement,
Expand Down Expand Up @@ -215,18 +215,18 @@ function updateSizesAttribute(
}

if (options?.updateOnResize) {
if (!resizeElementStore.has(element)) {
if (!elementResizeObserverMap.has(element)) {
const debounceResize = debounce(() => updateSizesAttribute(element), 500)
const observerInstance = new ResizeObserver(debounceResize)
resizeElementStore.set(element, observerInstance)
elementResizeObserverMap.set(element, observerInstance)
observerInstance.observe(element)
}

return () => {
const observerInstance = resizeElementStore.get(element)
const observerInstance = elementResizeObserverMap.get(element)
if (observerInstance) {
observerInstance.disconnect()
resizeElementStore.delete(element)
elementResizeObserverMap.delete(element)
}
}
}
Expand Down

0 comments on commit 56caa45

Please sign in to comment.