Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Looking at the code this made me realise that the WILL_MOUNT and DID_MOUNT are two and the same. We just want the effect to execute and the only way that's possible is just to rely on not switching to UPDATE.
This solution is derived from the twitter conversation on twitter about concurrent React. We can't rely on any other things in the if-clause this MAY cause a potential second fetch due to the process being interrupted before we can actually set the ref.current to UPDATE. I think this is something that is acceptable and is maybe more an issue with the concept of concurrent than anything else. The second operation dispatch will normally hit the cache anyway and cause an instant return.
I was initially thinking about making the clause
But this would be subject to the mistake of relying on a ref set during render (outside of an effect again). I can't reproduce the issue itself, that's the only problem I'm actually having.
I've tested this code by using
unstable_createRoot
in our first example, this results in nothing visually different from the previous approach. An article I found said to tryStrictMode
since this invokes every render twice but this also does not seem to produce the issue.In all honesty we trigger a side-effect in render now and maybe that's something we'd try to avoid with concurrent react. I know that it isn't the ideal thing but we'd ensure compatibility.
I hope this all makes sense.
Attempts to fix: #342
Source: https://frontarm.com/daishi-kato/use-ref-in-concurrent-mode/