-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10379 from hassnian/issue-10307
perf: improve drop first load speed
- Loading branch information
Showing
5 changed files
with
55 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div v-if="!props.target" ref="target" /> | ||
|
||
<template v-if="targetIsVisible"> | ||
<slot /> | ||
</template> | ||
</template> | ||
<script lang="ts" setup> | ||
const props = withDefaults( | ||
defineProps<{ | ||
target?: HTMLHtmlElement | ||
}>(), | ||
{ | ||
target: undefined, | ||
}, | ||
) | ||
const target = ref<HTMLHtmlElement>() | ||
const targetIsVisible = useOnceIsVisible( | ||
computed(() => props.target || target.value), | ||
) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function (target: Ref<HTMLHtmlElement | undefined>) { | ||
const targetIsVisible = ref(false) | ||
|
||
useIntersectionObserver(target, ([{ isIntersecting }]) => { | ||
// set visible only once | ||
if (!targetIsVisible.value && isIntersecting) { | ||
targetIsVisible.value = isIntersecting | ||
} | ||
}) | ||
|
||
return targetIsVisible | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters