Performance: Teleport for rendering elsewhere
MEDIUM IMPACT
Teleport affects how and where DOM nodes are inserted, impacting layout and paint performance by moving elements outside their original parent.
<template> <div class="app"> <Teleport to="body"> <Modal v-if="show" /> </Teleport> </div> </template> <script setup> import Modal from './Modal.vue' import { ref } from 'vue' const show = ref(true) </script>
<template> <div class="app"> <Modal v-if="show" /> </div> </template> <script setup> import Modal from './Modal.vue' import { ref } from 'vue' const show = ref(true) </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Rendering modal inside app container | High (nested nodes) | Multiple reflows on toggle | High paint cost due to layout shifts | [X] Bad |
| Rendering modal with Teleport to body | Moderate (direct child of body) | Single reflow isolated to overlay | Lower paint cost, stable layout | [OK] Good |