Files
b1713c8517 [RSC HMR] Fix a flurry of refetches when a editing component imported from many routes (#96102)
Fixes a flurry of requests when doing server HMR.

To reproduce the issue, create a server component imported from multiple
routes:

- Route `/a` imports that component
- Route `/b` imports that component
- Route `/c` imports that component
- (...and so on...)

Then edit that server component.

Expected: one request in terminal per open tab.
Actual: a flurry of requests.

There's two separate causes for the flurry of requests:

- The "server component updated" messages were emitted once per
already-compiled route, so a single tab would receive a flurry of
messages one right after another, and process them all.
- Also, the `debounce` for these messages is broken (it always fires
instead of delaying) due to a wrong condition inside it. So if we tried
coalescing messages by key, we'd still see multiple requests per tab.
- We should probably fix `debounce` but that's more risky because I
don't know if either existing caller could rely on the bug. Luckily, for
the fix below this doesn't matter.

Anyway, to get the desired behavior (one refresh per page), we switch to
expressing server component changes as a final message that gets sent at
the end of the update using a dirty flag. Then we don't need to worry
about how they get deduped or how many of them gets received.

There are probably other ways to factor this but this one seemed fine to
me.

## Before

A flurry of requests.


https://github.com/user-attachments/assets/337183e9-6fe2-4633-858d-6c1db6779618

## After

One request per open tab.


https://github.com/user-attachments/assets/3543619e-7ab3-4b74-bbdf-2151e16e2c2b

---------

Co-authored-by: Claude Fable 5 <[email protected]>
2026-07-24 03:59:27 +01:00
..