Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Issue with HMR (Fast Refresh) in NextJS #15

Open
ivan-dalmet opened this issue Jul 29, 2022 · 5 comments
Open

Issue with HMR (Fast Refresh) in NextJS #15

ivan-dalmet opened this issue Jul 29, 2022 · 5 comments

Comments

@ivan-dalmet
Copy link

ivan-dalmet commented Jul 29, 2022

Hi,
I just tried the hooks on a very simple project with NextJS. In development, I get an error on HMR (Fast Refresh), because (I think) the connection is closed and open too fast.

image

Did you already had this issue? Do you know a workaround?

If not, I will be able to provide you a code sandbox 😊

@NickTaykey
Copy link

I also have this issue did you find a solution?

@NickTaykey
Copy link

I found a potential solution to this issue. The hook useChannel should not be used in components which are supposed to be re-rendered multiple times because of state updates in parent components (this was what was causing my code to raise this error). So what I did was to declare useChannel in the closest parent component to the one where it was before. In this way the hook wasn't run multiple times because of "parent state" updates. Moreover, pay attention to the operation you do on a channel object because with asynchronous code you risk to make multiple operations on the same channel overlap and this can be another reason why this error is raised.

@ivan-dalmet
Copy link
Author

@NickTaykey I didn't found a solution and your solution is OK for a quick fix I think. I currently not using Ably on a production application so I will not investigate more but I think that the Ably team should if they want more Next users to use Ably 😊

@thisisjofrank
Copy link
Contributor

I have just merged a PR which I believe will fix this issue. This was related to us detatching unmounted components, that has been exacerbated by react 18's new debug mode, where it runs useEffect twice.
Please try out the latest version and verify if you can.
Thank you!

@sync-by-unito
Copy link

sync-by-unito bot commented Jul 24, 2023

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3756

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants