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

readAtomState is called many times redundantly before atoms are mounted #2333

Closed
wants to merge 4 commits into from

Conversation

edkimmel
Copy link

@edkimmel edkimmel commented Jan 9, 2024

Related Issues or Discussions

#2334

Summary

This PR is here to showcase the issue with a potential fix, not to be merged.

Test case without unmounted cache
Jotai store call counts
-----------------------
| readAtomState | 45
Test case with unmounted cache
Jotai store call counts
-----------------------
| readAtomState | 24

Check List

  • yarn run prettier for formatting code and docs

Copy link

vercel bot commented Jan 9, 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 Jan 16, 2024 10:21pm

@edkimmel edkimmel changed the title Test case showcasing optimization readAtomState is called many times redundantly before atoms are mounted Jan 9, 2024
Copy link

codesandbox-ci bot commented Jan 9, 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.

Latest deployment of this branch, based on commit 9a687e8:

Sandbox Source
React Configuration
React TypeScript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration
Next.js with custom Babel config Configuration
React with custom Babel config Configuration

@@ -772,6 +802,8 @@ export const createStore = () => {
l({ type: 'restore', flushed: flushed as Set<AnyAtom> }),
)
},
dev_print_call_counts: printCounts,
dev_clear_call_counts: resetCounts,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary for our core library? I think making a wrapper in user side should make more sense

store.dev_clear_call_counts?.()
}
it('Avoid redundant readAtomState while unmount', () => {
console.debug('Test case without unmounted cache')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console?

store.dev_print_call_counts?.()
store.dev_clear_call_counts?.()
}
it('Avoid redundant readAtomState while unmount', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this test case we didn't expect anything. just run the code? I think we should add some counter to make sure behavior is stable

@dai-shi
Copy link
Member

dai-shi commented Jan 12, 2024

As I understand, this is not something to be merged. Let's convert it to draft.

@dai-shi dai-shi marked this pull request as draft January 12, 2024 01:31
@dai-shi
Copy link
Member

dai-shi commented Feb 9, 2024

#2334 (reply in thread)

We would like to learn the problems and the possible solutions, outside the core. I'm interested in seeing it to move forward, but closing this.

@dai-shi dai-shi closed this Feb 9, 2024
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.

3 participants