-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
reduce internal states in useBlocker #10657
Conversation
🦋 Changeset detectedLatest commit: c2e2ac1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@brophdawg11 i end up not adding the ref solution (mention remix-run/remix#6704) because, like was mentioning before, I was not sure that I liked the ref solution. I believe the Please can you check if the problems that made you open the first change continue to happen Cheers |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
55a11cb
to
c2e2ac1
Compare
@brophdawg11 did you got time to test if this is working? Cheers |
Thank you for the PR but I think we're going to remain with the current solution for now. The This blocker stuff has been a bit fragile (as expected and why it's |
Thanks for the reply. Yap make sense. I thought could be a something possible since Without the useId, the useEffect would be the only way to do it maintaining the purity. At the same time the idea of this component is to be impure (due to unique keys). We are just moving the impurity to the effect (like the documentation mention). For sure the render is not pure, but is the intention. Is "Pure" (not really) for the same instance. I'm trying to understand if for this use case the render impurity would make sense and not something that would be considered a violation. (like No matter what I think helped removing one of the setState that where around for the blocker :) Cheers |
|
I was mentioning that Indeed the change of it is done in a useEffect, but in terms of use does not make it pure since is not part of state or props xD |
This PR reduces the number of internal states used in
useBlocker
I believe this solution works and brings less useEffects interactions with internal state.
With StrictMode we will continue to have 2 ids. But we will never have an orphan blocker. The first ID will be added and removed making the code more deterministic.
For the normal mode (no strict mode) the id generation only works once and the effect makes always the same action (adding and removing on unmount).
I believe this simplifies the solution.