Returns
A promise that resolves after all pending state changes have been applied and the DOM has been updated
Examples
Waiting for DOM updates
Focusing elements after conditional rendering
Measuring elements after update
Scrolling to new content
Sequential state updates
Integration with third-party libraries
Form validation after input
Use cases
- Focus management: Setting focus after elements are rendered
- DOM measurements: Getting element dimensions after updates
- Scroll positioning: Scrolling to new content after it’s added
- Third-party integrations: Ensuring DOM is ready for external libraries
- Testing: Waiting for updates in async tests
- Animations: Starting animations after state changes are reflected in the DOM
Behavior
tick()returns a promise that resolves after the next microtask- Internally calls
flushSync()to ensure all pending updates are applied - Multiple calls to
tick()can be chained withawait - Updates are batched automatically by Svelte for performance
Notes
tick()is asynchronous, unlikeflushSync()which is synchronous- Use
tick()when you don’t need immediate synchronous updates - The promise resolves after Svelte’s internal update cycle completes
- This is the recommended approach for most cases where you need to wait for DOM updates
- Prior to Svelte 5, this was primarily used in Svelte 3/4 lifecycle methods