-
-
Notifications
You must be signed in to change notification settings - Fork 562
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
refactor: avoid extra rerender #2530
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
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.
Thanks for the suggestion.
We can't remove rerender
in useAtomValue, but you are right about the extra rerender (without commits), which isn't desirable.
I'm still working on store2, which will come with a big change, so please be patient.
That said, I think the optimization like what you suggest might be possible and meanwhile what you can help is to create a test case. Thanks for understanding.
@@ -94,7 +94,6 @@ export function useAtomValue<Value>(atom: Atom<Value>, options?: Options) { | |||
} | |||
rerender() | |||
}) | |||
rerender() |
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 required. I wonder if we could make a contrived test to cover it.
(I thought there was a rejected PR or something to refer, but can't find it now.)
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.
yeah, maybe we should add more test. but the rerender should be optimized.
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.
Did you have a real problem in your usage? If you have, memoization might mitigate the issue for the meantime.
Please create a new test case in |
@dai-shi Could you clarify if store2 is intended to fix the underlying cause requiring a secondary render, or have I misunderstood? From your last comment about the test case, it seems this might still be an open question. Thx! |
No, I only mentioned store2 because this PR made changes only to store2. |
Summary
useAtomValue called rerender inside useEffect, which led to an additional render, and this PR optimized that performance issue.
Check List
yarn run prettier
for formatting code and docs