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

[question] Why is the scheduler dependency required? #106

Closed
romgrk opened this issue May 11, 2023 · 5 comments
Closed

[question] Why is the scheduler dependency required? #106

romgrk opened this issue May 11, 2023 · 5 comments

Comments

@romgrk
Copy link

romgrk commented May 11, 2023

I was wondering if there was a way to remove it from the peer dependencies. Thanks.

@dai-shi
Copy link
Owner

dai-shi commented May 11, 2023

Because it is used in the code:

} from 'scheduler';

You might be interested in reading the discussion in #100.

@romgrk
Copy link
Author

romgrk commented May 12, 2023

I've read the code, but I don't understand why wrapping the listener callbacks with runWithNormalPriority is required. If you could point me to resources to understand the issue better I'd be super happy to understand more about this.
I've also read the linked discussion, but I couldn't understand the link between the scheduler and that discussion :|

@dai-shi
Copy link
Owner

dai-shi commented May 12, 2023

If you need to dive into it, you want to follow resources linked in https://github.com/dai-shi/will-this-react-global-state-work-in-concurrent-rendering.
Some links might be outdated.

In reality, if you don't care much about the subtle behavior, you could implement much simpler version of useContextSelector.

@romgrk
Copy link
Author

romgrk commented May 12, 2023

you could implement much simpler version

Yeah I figured, I have a very minimal implementation here: https://gist.github.com/romgrk/a3dc5d3de5c011e0925b2f2aee14ee98 (if you have any comments, I'd be interested to hear)

if you don't care much about the subtle behavior

Actually I do care about correctness, if you have any comments to make on the issues that could arise from not having the scheduler wrapper I'd be happy to hear. Otherwise, feel free to close this issue, and thanks for the replies.

@dai-shi
Copy link
Owner

dai-shi commented May 12, 2023

One small note is that useEffect can technically be fired with a big delay, so the store state can be changed before you subscribe to the store.

Other than that, it should be "level 1".
It will probably fail with level 2 and 3.
To be level 2, you can just use useSyncExternalStore.
To be level 3, it's basically impossible, and my hack is to use scheduler and some others.

See reactwg/react-18#70 for levels.

@dai-shi dai-shi closed this as completed May 12, 2023
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

No branches or pull requests

2 participants