next.js
e16f6fb2 - [Segment Cache] Always upsert on prefetch completion (#91488)

Commit
4 days ago
[Segment Cache] Always upsert on prefetch completion (#91488) **Previous:** 1. https://github.com/vercel/next.js/pull/91487 **Current:** 2. https://github.com/vercel/next.js/pull/91488 **Up next:** 3. https://github.com/vercel/next.js/pull/89297 --- When a prefetch response includes vary params, the segment cache rekeys entries to a more generic path based on which params the segment actually depends on. Previously, the rekeying only happened when vary params were provided. Now that vary params are tracked for more response types (and eventually will always be tracked), entries are rekeyed in more cases than before. This exposed a potential race condition: the scheduler would capture a vary path at scheduling time and upsert the entry at that path when the fetch completed. But the fetch functions themselves rekey entries to a different (more generic) path upon fulfillment. The deferred upsert could then move the entry back to the less generic path, undoing the rekeying. To fix this, move the upsert logic inline into the fetch functions that fulfill entries, rather than deferring it to an external callback. This removes the race condition, simplifies the model, and reduces implementation complexity. The previous structure existed to avoid the rekeying cost when vary params weren't available, but rekeying is inexpensive and not worth the added indirection. The upsert function itself already handles concurrent writes by comparing fetch strategies and checking whether the new entry provides more complete data than any existing entry. So it's safe to always call it inline — whichever entry wins will be the most complete one.
Author
Parents
Loading