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

Events that return app-db unchanged seem to cause the event history to lag #268

Closed
stumitchell opened this issue Jun 9, 2020 · 5 comments

Comments

@stumitchell
Copy link

stumitchell commented Jun 9, 2020

We created a situation where the Event Tab was showing trace for the "Last event", not the "current event". There was a one-event lag.

An event handler written with an implied do seems to be the cause. Eg:

(re-frame/reg-event-db
 :event
 (fn-traced [db _]
   (let [a 10                               ;; <-- implied do with two forms  (see db below)
         b (+ a 20)]
     (+ a b))
   db)))
@jtlocsei
Copy link

This might be unrelated, but could it be that you didn't yet have a subscription that uses the data that's updated in the db by the event? It seems like the refresh of re-frame-10x display is triggered by data flow in a subscription. I had was seeing a one-event-lag and it was fixed when I added the subscription. Jacek Schae talks about the issue briefly at the end of Video 8 in his free re-frame course https://www.jacekschae.com/learn-re-frame-free (no affiliation)

@superstructor
Copy link
Contributor

@MawiraIke Have a look at this please.

@MawiraIke
Copy link
Contributor

I can reproduce this issue in the latest re-frame-10x version (1.2.7) although it's somehow different now. Using the todos app, there is a delay in showing the trace for the latest event, i.e

(re-frame/reg-event-db
 :event
 (fn-traced [db _]
   (let [a 10                               ;; <-- implied do with two forms  (see db below)
         b (+ a 20)]
     (+ a b))
   db)))

although the delay ends after clicking any part of the window. Afterwards, the event tab updates to show the most recent trace.

@superstructor superstructor removed this from the v1.3.0 milestone Jun 7, 2022
@superstructor superstructor added this to the v1.5.1 milestone Jul 5, 2022
kimo-k added a commit that referenced this issue Jul 28, 2023
@kimo-k
Copy link
Contributor

kimo-k commented Jul 28, 2023

Hey @stumitchell, interesting case. I don't think this is caused by the implicit do, though.
Rather, this behavior arises when the new app-db is identical to the old one.

This doesn't work:

(reg-event-db :bad-event (fn [db _] db))

While this does:

(reg-event-db :good-event (fn [db _] (assoc db ::gensym (gensym))))

We accumulate trace at various sites, but only once do we express a quiescent trace. Reagent's render queue should invoke this in its final loop as it handles a reset of the app-db. The problem is, there is no reset. Nothing is scheduled, no quiescence.

Without quiescence, there is no match until the next epoch begins. In other words, 10x batches the event, thinking there are more soon to come.

I think this is a complete picture, but I'm still not sure what to do about it. I made a test branch, which makes all events return a new app-db. This may be intrusive for the user, though, and it seems inelegant.

@kimo-k
Copy link
Contributor

kimo-k commented Aug 3, 2023

I found an obvious solution based on the above analysis. An unchanged :db effect can be considered a new moment of quiescence, despite reagent taking no action. It's straightforward to trace this moment.

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

No branches or pull requests

5 participants