Skip to content
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

Closed
wants to merge 2 commits into from
Closed

refactor: avoid extra rerender #2530

wants to merge 2 commits into from

Conversation

hjiog
Copy link

@hjiog hjiog commented Apr 29, 2024

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

Copy link

vercel bot commented Apr 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 9:35am

Copy link

codesandbox-ci bot commented Apr 29, 2024

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.

Copy link
Member

@dai-shi dai-shi left a 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()
Copy link
Member

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.)

Copy link
Author

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.

Copy link
Member

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.

@dai-shi
Copy link
Member

dai-shi commented May 15, 2024

Please create a new test case in tests/react/optimization.test.tsx.
We can't guarantee if it will be solved.

@dai-shi dai-shi closed this May 15, 2024
@gurkerl83
Copy link

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.

@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!

@dai-shi
Copy link
Member

dai-shi commented May 15, 2024

if store2 is intended to fix the underlying cause requiring a secondary render

No, I only mentioned store2 because this PR made changes only to store2.
This behavior/problem isn't specific to store2 or store. It's working as expected.

@hjiog hjiog mentioned this pull request May 17, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants