next.js
90090ba4 - Include HMR refresh hash in `"use cache"` cache keys (#75474)

Commit
1 year ago
Include HMR refresh hash in `"use cache"` cache keys (#75474) Today, when editing server components that use `"use cache"` functions, only updates to the uncached parts of the component will be reflected in the rendered result after the HMR refresh was applied. Any cached functions/components will show the same content as before the edit. This is problematic when a function with a `"use cache"` directive is edited. In this case, the edits won't be applied, and stale content is shown in the browser, until the dev server is restarted. With this PR, we are now including an HMR refresh hash in the cache key for all `"use cache"` functions. This ensures that those functions are revalidated when a server component is edited, which avoids showing stale content. However, while the `"use cache"` functions are revalidated during the HMR refresh, we will still restore any fetches inside of `"use cache"` from the [server components HMR cache](https://nextjs.org/docs/app/api-reference/config/next-config-js/serverComponentsHmrCache) (unless their input changed because of the edit). For Webpack, a real content hash is used, which means that if an edit is reverted to a prior edit, the previously cached data will be retrieved from the cache. For Turbopack, the HMR hash is currently just an incrementing counter, which may be improved in a follow-up PR. closes NAR-65
Author
Parents
Loading