Fix console replaying and `React.cache` usage in `"use cache"` functions (#75520)
Console logs in server components are replayed in the browser. For
example, when you run `console.log('foo')`, the log will be replayed in
the browser as `[Server] foo`. When the component is inside of a `"use
cache"` scope, it's replayed as `[Cache] foo`.
However, when logging directly in the function body of a `"use cache"`
function, we are currently not replaying the log in the browser.
The reason for that is that the function is called outside of React's
rendering, before handing the result promise over to React for
serialization. Since the function is called without React's request
storage, no console chunks are emitted.
We can work around this by invoking the function lazily when React calls
`.then()` on the promise. This ensures that the function is run inside
of React's request storage and console chunks can be emitted.
In addition, this also unlocks that `React.cache` can be used in a `"use
cache"` function to dedupe other function calls.
closes NAR-83