Closed SukkaW closed 1 year ago
- Part of my decision on dropping useMemo is, as we know, how useMemo potentially resets state. Based on my observation, this doesn't seem to be the case for the production behavior, but more of the development behavior (related to react-refresh). So my concern still stands, as it affects the DX.
The new React Doc has explained when useMemo
will throw away cache in detail: https://react.dev/reference/react/useMemo#caveats
And that's exactly why useMemo
($$cache
) and useRef
($$ref
) should be separated.
React expects useRef
to hold the client-side only value (DOM Node, third-party libraries' instance like new VideoPlayer()
, etc.), so refs will only be reset after components are unmounted.
React also expects useMemo
for performance optimization, and React will throw away the cache when needed.
The PR makes the $$cache
(and new $$ref
) using the correct hook to meet React's expectations.
- Minor thing is that this only solves RSC's concern. But that's just "minor".
Solving RSC compatibility is just a bonus as React's expectations have been met.
@lxsmnsyc Kindly request your attention with a friendly ping. I applied the fix to your requested changes 2 weeks ago. I would appreciate it if you could review it at your convenience and provide valuable feedback.
@SukkaW Sorry I've been kinda busy recently. I'll give it a read tomorrow.
Okay looks good. I'll release this some time this week.
The PR does 2 things:
useRef
touseMemo
for cache$$ref
to merging refsThis re-enables RSC support after 0.6.0.