Question presented to candidate:
"Users click a link in our sidebar and nothing seems to happen for a second before the next page appears. How would you give them feedback in Next.js, and where does useLinkStatus fit?"
What a strong answer should cover:
- Why the delay exists: the destination is dynamic, not prefetched, and has no
loading.js, so the router waits for the server before changing the URL. useLinkStatus()fromnext/linkreturns{ pending }for the nearest parent<Link>; it must be called in a Client Component rendered inside that Link.pendingistruefrom the click until the history updates; it is the inline, per-link signal, whileloading.jsis the route-level fallback.- Fix the cause first: a
loading.jsfile or prefetching makes the transition instant;useLinkStatusis the patch for the remaining slow cases. - UX details: a fixed-size, always-rendered hint (no layout shift) and a short animation delay so fast navigations do not flash.
Clarifying questions expected:
- "Is the slow route dynamic, and does it have a
loading.js?" β that decides whether a route fallback already solves it. - "Is prefetching disabled on these links?" β
useLinkStatusmatters most withprefetch={false}.
Code / implementation expected: Yes β a small Client Component using useLinkStatus inside a <Link>, plus the CSS idea for a delayed fade-in.