react-packages icon indicating copy to clipboard operation
react-packages copied to clipboard

Stringify params for useSubscribe to avoid stopping the subscription when object reference changes

Open denihs opened this issue 5 months ago • 0 comments

This issue was reported in our Discord.

This is a video showing the issue:

https://github.com/user-attachments/assets/7490bcb1-dc34-4c39-a2a3-f84f14338156

If you check the part of the code where we call useSubscribe,, the params remain the same.

However, the cleanup of the useEffect is still triggered because we change the object reference after unmounting the page.

To solve this, we're now stringifying the params. This could cause an issue in different scenarios if the object is too big, but in this case, we are stringifying the parameters for a subscription, so it's unlikely this object will cause any issue.

Here is the result after this change:

https://github.com/user-attachments/assets/9130e02b-85b8-474b-9863-1a24bc2138bd

image

So everything now works as expected.

PS: My example is slightly different from the one done by the issue reporter. In my example, I changed the parameter in the URL to validate if the subscription with the older parameter would be dropped.

denihs avatar Sep 06 '24 16:09 denihs