-
Notifications
You must be signed in to change notification settings - Fork 47k
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
How can I force update a class component in SyncLane? Can we permanently expose runWithPriority API? #28897
Comments
Hi @rickhanlonii , |
Same problem here. |
Can you see if that works? The tearing is expected if mobx isn't using |
@rickhanlonii mobx is using
when the external store updates, because
Also, I didn't want to use |
Also... 🙈 - This method is currently exposed (admittedly with a todo) in the experimental channel; https://github.com/facebook/react/blob/main/packages/react-dom/index.experimental.js#L17 |
More consideration on why I prefer
|
This sounds like it's really about batching and not scheduling behavior. Does wrapping it in Note: we're removing |
I think eventually what I want to achieve is "schedule class component updates in SyncLane" and "function component and class component get re-rendered together" If in a click event handler, it calls a setState for a class component, and calls setState (from useState hook) for a function component, then both class component and function component are scheduled in one microtask, and react renders them together However, when it comes to external store, in a non-event handler, function component still scheduled in SyncLane, but the class component is scheduled in DefaultLane. even if I use queueMicrotask + flushSync, I can't schedule the class component to be in the same microtask as function component |
Ah right -can you testd in the react canary? In the canary the default updates and sync updates are flushed together so they're batched. |
I tested react canary, it does batch default updates and sync updates, i.e. for above code example with option 1, that class component and function component are re-rendered together in a microtask, which is what I wanted to achieve. However, if I remove function component, that only class components are subscribed to the store update, then class components are updated in a task not microtask. this brings more uncertainty to the behaviour |
@rickhanlonii I just tested react 19 beta, and its behaviour is identical to what I saw in canary that default updates advance to microtask to be flushed with sync updates, however, if there is no sync updates (i.e. no |
In react 18 concurrency, sometime we want to specify a higher priority for UI update triggered by external store.
This can be done for function component by using
useSyncExternalStore
.However, I can't find any information on how to make class component's forceUpdate to be in SyncLane.
In react experimental version, I can use unstable_runWithPriority API to achieve this. Is there a more stable way to do it?
The text was updated successfully, but these errors were encountered: