-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Zombie child, yet again #302
Comments
Thanks for the repro.
This, I'm not sure why though. |
Yup! It seemed related to that and as you pointed out in your codebox, using But I still have one question though. What would be the downsides of moving the subscription from the useEffect to directly in the hook call? (Ex.: index.tsx) |
As for the scenario when using react-redux. It seems that they are already using it. In the subscription file (Subscription.js) they are using |
That would be a side effect in render, which is never recommended in react. |
Thanks for your answer. It makes sense. As for the scenario when using react-redux. It seems that they are already using it. In the subscription file (Subscription.js) they are using Maybe we should add the functionality to allow passing a batching method when creating a store, this way, it should prevent the zombie-child issue and also improve performance as it will call all listeners of that store inside one batch (if that is done outside the react event, like setTimeout). And having it optional, it will not add any breaking changes. What's your opinion on this? |
Ah, nice finding. I thought I saw this before, but I was searching |
We could try using batchedUpdates, but it'd be not easy to make bundles for react-dom and react-native. I wonder if v4 #160 will solve this issue eventually... Oh, But, then, the DX is not very good, isn't it? The workaround in #286 seems easier to me. |
After giving further thoughts, I think that having a What do you think? Do you see any value in implementing a |
Yeah, that's what I meant by "DX is not very good". I don't think it's worth the effort, at this point. But let us keep this in mind. For now, it would be best for us to add a small section about the workaround in readme.md. Would you or anyone like to work on it? cc @martonlanga @Tirzono . (I will close this issue a bit later.) |
@dai-shi let me know if this is ok or if I should change anything. |
* feat(docs): add an example for setting the state outside event (#302) * fix gramar issues * Point more details URL to the issue instead of the tweet * Simplify example Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> * Update readme.md * Update readme.md Co-authored-by: Cristian Ratoi <cristian.ratoi@everymatrix.com> Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
one question @dai-shi didn't @JeremyRH find a way to do this without batchedupdates? i remember he told me we can now remove it. the trouble is mostly that we're using two reconcilers: react-dom and r3f. our middleware currently looks like this: import { Renderer } from 'react-three-fiber'
import { unstable_batchedUpdates } from 'react-dom'
const batched = (config: StateCreator<BuerliState>) => (
set: SetState<BuerliState>,
get: GetState<BuerliState>,
api: any,
) => config(args => unstable_batchedUpdates(() => Renderer.batchedUpdates(() => set(args))), get, api) if there is any way to avoid this we would be very happy ... btw react automatically batches in blocking and concurrent mode, has anyone tested if the problem persists? |
To fix this in non-concurrent mode without batchedupdates, you need to ensure a parent's |
well, this looks to me the easiest and the cleanest. I'm interested if #160 fixes this issue from the ground. Otherwise, the current solution would be good in total.
My assumption is this doesn't work very well performance-wise even in legacy mode. |
just switching to blocking would also take care of it right? that would be a good solution if it did. |
AFAIU, you would need |
it says here that both blocking and cm autobatch https://reactjs.org/docs/concurrent-mode-adoption.html#feature-comparison
|
Oh, you mean Blocking Mode which is the one between CM and LM. I missed that part of your comment.
This, I'm not sure. Hopefully, they batch multiple setStates called in async but in a short period? |
Last I tested, using |
Should this issue be reopened? I've been trying to figure out where the More reading: |
I feel like this is not a real issue from the library perspective. React may behave differently in the future as we discussed. A new middleware to modify set might be an option if there's a certain demand. btw, react doesn't seem to have Blocking Mode any longer. |
Could someone help me understand the following. In the readme, there is this example: What I can't understand is why Consider the following example: Here, the callback is a function that the api wrapper will call when an ajax request is complete. Yet it is declared in location B, not somewhere outside. In my particular example, what part exactly should I wrap with |
The readme doesn't recommend having In your case, if |
Thanks. How do I distinguish a non-react callback from a react-callback? Not sure I have a clear understanding of this term's meaning. |
react callbacks are like |
Almost clear! The last bit that's confusing is this: I suppose so based on their example, could you confirm please? function handleClick() {
fetchSomething().then(() => {
// React 17 and earlier does NOT batch these because
// they run *after* the event in a callback, not *during* it
setCount(c => c + 1); // Causes a re-render
setFlag(f => !f); // Causes a re-render
});
} ... and why I keep asking for clarifications here is that I eventually would like to understand what positions exactly it is safe to call the bath wrapper function considering the is |
yes. |
your link address "index.tsx" has been 404, |
see pmndrs/zustand#302 unfortunately, batching doesn't fix this because the error isn't when rendering, it's when checking the store's comparers
There still seems to be the issue of zombie child. It requires some special criteria to reproduce:
Note, that the same scenario is not reproducible while using redux with hooks.
Repo to reproduce: https://github.com/ratoi-crysty/zustand-zombie-child
The text was updated successfully, but these errors were encountered: