Next.js · Middle · Question 36 of 75
How do you run code (e.g. analytics) after the response is sent, without delaying the user?
- ✓Correct answer: Use
after()fromnext/server - 2Start a promise without
awaitin a server component - 3Call
setTimeoutin a server component
Explanation
after(() => log(...)) schedules work after the response finishes (in server components, Server Actions, Route Handlers, proxy). A "dangling" promise in a serverless environment can be cut off when the function ends, and its errors get lost.