-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(RouterView): avoid parent rerenders when possible
Close #1701
- Loading branch information
Showing
5 changed files
with
138 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import { scrollWaiter } from './scrollWaiter' | ||
defineProps<{ simple: boolean }>() | ||
const viewName = ref('default') | ||
function flushWaiter() { | ||
scrollWaiter.flush() | ||
} | ||
function setupWaiter() { | ||
scrollWaiter.add() | ||
} | ||
</script> | ||
|
||
<template> | ||
<RouterView v-if="simple" v-slot="{ Component, route }"> | ||
<component :is="Component" :key="route.meta.key" /> | ||
</RouterView> | ||
|
||
<RouterView | ||
v-else | ||
:name="viewName" | ||
v-slot="{ Component, route }" | ||
key="not-simple" | ||
> | ||
<Transition | ||
:name="route.meta.transition || 'fade'" | ||
mode="out-in" | ||
@before-enter="flushWaiter" | ||
@before-leave="setupWaiter" | ||
> | ||
<!-- <KeepAlive> --> | ||
<!-- <Suspense> | ||
<template #default> --> | ||
<!-- <div v-if="route.path.endsWith('/a')">A</div> | ||
<div v-else>B</div> --> | ||
<component | ||
:is="Component" | ||
:key="route.name === 'repeat' ? route.path : route.meta.key" | ||
/> | ||
<!-- </template> | ||
<template #fallback> Loading... </template> | ||
</Suspense> --> | ||
<!-- </KeepAlive> --> | ||
</Transition> | ||
</RouterView> | ||
</template> |
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,11 @@ | ||
<script lang="ts" setup> | ||
import { onUpdated } from 'vue' | ||
let count = 0 | ||
onUpdated(() => { | ||
console.log(`RerenderCheck.vue render: ${++count}`) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<RouterView key="fixed" /> | ||
</template> |
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