-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow useRelativeTime
to be auto-memoized
#8089
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Dec 17, 2024 11:11 AM (UTC) ✅ All Tests Passed -- expand for details
|
⚡️ Editor Performance ReportUpdated Tue, 17 Dec 2024 11:24:12 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thanks, Cody ✨.
Description
Follows up on #8034, as the
'use no memo'
directive is meant as a short term fix.The original issue is due to React Compiler working under the assumption that reactive values are in
useState
,useReducer
oruseSyncExternalStore
.Calling
Date.now()
during render is considered a side-effect, and also breaks in other scenarios, such as SSR Hydration (asDate.now()
will return different values during server render and when the browser hydrates).Since we already have a
useReducer
trick in place that is used to schedule re-renders on set intervals, the theory is that we can just move theDate.now()
value as state in that same reducer.The benefit of doing this is that it allows memoizing and reduce work during render, as the
useRelativeTime
hook might be called by its components more frequently than its intervals, but it won't do work unless thenow
state itself has updated.What to review
Does it make sense?
Testing
Existing tests should be sufficient.
Notes for release
Relative time stamps are optimized by React Compiler, reducing memory usage and allowing faster rerenders.