Performance: Await blocks ({#await})
MEDIUM IMPACT
This affects how asynchronous data loading impacts page rendering and user interaction responsiveness.
<script> let promise = fetch('/api/data').then(res => res.json()); </script> {#await promise} <p>Loading...</p> {:then data} <p>{data.value}</p> {:catch error} <p>Error loading data</p> {/await}
<script> let data = fetch('/api/data').then(res => res.json()); </script> {#if !data} Loading... {/if} {#if data} <p>{data.value}</p> {/if}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Incorrect promise handling without await block | Multiple conditional DOM checks | Renders immediately but never updates with data | Paints incorrect/empty content, no data update | [X] Bad |
| Proper await block with fallback and then blocks | Single DOM update on promise resolution | Immediate fallback render, single reflow on data | Lower paint cost with incremental updates | [OK] Good |