reactjs / reactjs/react.dev

[Suggestion]: Clarification on react.cache Usage in Server Requests

未關閉
#6,671 0 則留言 22 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type: documentation
主要語言
JavaScript
星號
11.8k
分支
7.9k
平均合併
1 天 11 小時
30 天內合併 PR
11

描述

Summary

The use of the term "each server request" in the react.cache API documentation is ambiguous, potentially leading to confusion between React Server Components (RSC) and Server-Side Rendering (SSR). This ambiguity may result in a lower understanding of how react.cache operates and when cache expiration occurs.

Page

https://react.dev/reference/react/cache#caveats

Details

Hi, React Team,

image

While reading through the documentation, I came across the phrase "each server request" and found myself pausing to consider its implications. The term seems to encompass a broad range of server interactions, yet I believe it might be more beneficial to specify "each RSC server request" to distinguish it clearly from general SSR scenarios.

Many of us in the React community, especially those less familiar with server-side mechanisms like RSC, might inadvertently equate "server requests" with the typical requests sent to an SSR server. This could lead to some confusion about when and how cache expiration happens, particularly since react.cache is designed to work within the RSC server context, where each request is akin to a single rendering instance.

It's clear that react.cache plays a crucial role within the RSC environment, akin to how Next.js operates with its external server handling traditional SSR requests and an internal server dedicated to RSC rendering. This dual-server setup made me realize that react.cache is essentially functioning within this confined RSC server space. Given this setup, the concept of cache expiration becomes less conventional, akin to a closure in JavaScript where variables are bound to the function scope and are discarded once the execution context ends.

This analogy to closures might resonate well with developers, highlighting how react.cache retains data within the scope of a single RSC request and discards it afterward, similar to how a closure behaves. This perspective could add a layer of understanding to the documentation, making the concept more relatable and easier to grasp, especially for those familiar with the nuances of JavaScript closures.

I understand the importance of keeping the documentation agnostic to specific implementations like Next.js. However, as React continues to evolve and possibly embrace framework-based tools more closely, clarifying these nuances could prove invaluable, not just for Next.js developers but for all of us looking to harness the full potential of RSC and similar technologies.

It's with this in mind that I suggest a slight revision or an additional note in the documentation to help demystify the workings of react.cache within the RSC context. Such an update could greatly aid in alleviating any confusion and ensure a smoother development experience for the community.

Thank you for considering my input. I deeply appreciate the hard work and dedication that goes into maintaining the React documentation, and I'm eager to contribute in any way I can.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

開啟連結的 react.dev 頁面上的 react.cache 文件並檢視 Caveats 區段,特別是片語「each server request」。確認文件如何區分 RSC 與 SSR,以及如何描述快取到期,然後釐清措辭或新增簡短註記,但不要將其與特定框架綁定。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, react
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。