Feliz icon indicating copy to clipboard operation
Feliz copied to clipboard

React.useDeferred doesn't works with HMR

Open MangelMaxime opened this issue 2 years ago • 4 comments

Because of the usage of React.useCancellationToken() when an HMR call has been triggered the async call is never triggered again.

https://github.com/Zaid-Ajaj/Feliz/blob/52907b11f64c758282f2986f1aed0c91d46481b0/Feliz.UseDeferred/UseDeferred.fs#L62-L81

MangelMaxime avatar Sep 11 '22 20:09 MangelMaxime

Hi there @MangelMaxime,

Any chance you had a look at this issue to figure out what is wrong exactly with React.useCancellationToken()?

Zaid-Ajaj avatar Dec 25 '22 04:12 Zaid-Ajaj

I need to check again because I don't remember exactly.

But if I remember correctly the problem was that the token was marked as cancelled and never recreated/refreshed.

Workflow:

  1. App is loaded
  2. Component can fetch data from the server
  3. HMR happen which cause the token to be marked as cancelled
  4. Component try to fetch data again but failed because the token is marked as cancelled

MangelMaxime avatar Dec 26 '22 14:12 MangelMaxime

Do you think we need to pass a dependencies array to the cancelation token hook?

Zaid-Ajaj avatar Dec 26 '22 15:12 Zaid-Ajaj

I think I tried that and it didn't work any better. So in my code I disabled the cancellation support when compiling for DEBUG.

This need to be re-visited to see if I did something wrong at the time or not.

MangelMaxime avatar Dec 26 '22 19:12 MangelMaxime