Skip to content
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

form-1 components, reg-sub-raw subscriptions and clear-subscription-cache! infinite render loop #442

Closed
bwalex opened this issue Jan 5, 2018 · 2 comments

Comments

@bwalex
Copy link

bwalex commented Jan 5, 2018

I'm using re-frame 0.10.2. Following what was discussed in #218, I have form-1 components using subscriptions. In particular, they are subscriptions to a reg-sub-raw sub.

I'm also using hot-reload using figwheel, where my reload handler is:

(defn mount-root []
  (re-frame/clear-subscription-cache!)
  (reagent/render [views/main-panel]
                  (.getElementById js/document "app")))

(defn on-js-reload []
  (mount-root))

When the page is loaded for the first time, everything's fine - render gets called once or twice, depending on what exactly the subscription does to the atom, but it stops after that and everything's ok.

However, when the hot-reload path gets triggered, it ends up in an infinite render loop; the render causes a new subscription to be created, the new subscription changes the value deref'd in the component, and that again causes a re-render with a new subscription being created.

If I comment out the clear-subscription-cache! call, things work as intended. That makes some sense based on the comment in #218 saying that it works because of the subscription cache (and sub dedup).

I'm not sure it matters ( I don't think it does) but in the reg-sub-raw-created subscription I'm creating a new reagent.core/atom instead of using the re-frame app-db. The subscription handler is a wrapper around the apollo graphql client, which implements its own cache, so using the app-db wouldn't really be productive here.

If I had to guess, what's happening is that the render method of the already-mounted component (as it's just reloading) gets called the second the subscription gets called, before it gets a chance to update the subscription cache. That render itself also causes a new subscription to be created, and, since the cache hasn't been updated yet, it just goes around in an infinite loop.

@bwalex bwalex changed the title form-1 components, reg-sub-raw subscriptions and clear-subscription-cache! render loop form-1 components, reg-sub-raw subscriptions and clear-subscription-cache! infinite render loop Jan 5, 2018
@danielcompton
Copy link
Contributor

Can you post a project that reproduces this, and also try updating to the latest beta? There were some changes in #428 but that isn't in 0.10.2.

@bwalex
Copy link
Author

bwalex commented Jan 8, 2018

0.10.3-beta1 indeed seems to fix the issue.

@bwalex bwalex closed this as completed Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants