-
Notifications
You must be signed in to change notification settings - Fork 30
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
Project Stats: Project Stats numbers (Classifications Today / Classifications Total) don't show on initial Next.js page fetch #6190
Comments
If it helps, classification stats aren’t fetched server-side. They’re fetched in the browser, after you’ve been logged in. |
UpdateI'm filing this investigation under low priority for now, as the original volunteer has informed us that they couldn't replicate the problem at the moment. I'll still keep this issue open until we know for sure what's been happening. Also, of interest, the volunteer also added something else that may either be related to this issue, or is tangential to it:
|
It might also be worth noting that user project classification counts are cached in session storage, to prevent them being lost when you go to Talk. |
@shaunanoordin I can reproduce this bug on the Zooniverse site:
The project user snapshot, which includes personal stats, is saved to session storage, to preserve it when you visit Talk, or your inbox, or recents, or collections. Session storage isn't shared across tabs. You could maybe change that to use local storage, which is shared across tabs. I'm not sure what the other side effects of that might be. For example, if you have two tabs, each on a different project, then the user snapshots for each of those tabs will be different and you wouldn't want the snapshot from project A to be loaded into the Classify page for project B (see #5134 and #5964.) |
I’m not 100% sure this is relevant, but each tab has its own, independent Panoptes session. See #4892 and zooniverse/panoptes-javascript-client#207. So, in theory, the new tab should log you in, with your secure Panoptes cookie, then request your classification count from the API. I think there might be a bug in the code that makes that request, which is in the user store. TBH, making network requests from a MobX store isn’t a recommended pattern so that code probably needs to be replaced. EDIT: after looking at the The next few comments are me trying to figure out where Skip forward to this comment, #6190 (comment), if you want to get straight to an explanation of the bug. It's to do with closures and stale variable scopes being captured. |
Here's the action that fetches your personal stats, when the React app mounts in the browser. If front-end-monorepo/packages/app-project/stores/User/UserPersonalization/UserPersonalization.js Lines 75 to 83 in 094daf5
|
I just refeshed my browser tab from one hour ago. Project stats have changed, but today's 4 classifications are missing from the overall total. The correct numbers should be; 4 classifications today, 50 classifications overall. I think what's going here is the bug that I described in #5134 (comment), where session storage loads stale classification counts. The 4 classifications that I made today were all made in a different tab, so they haven't been added to the total count cached in browser storage in this tab. If |
The Screen.Recording.2024-08-02.at.23.19.51.movScreen.Recording.2024-08-02.at.23.21.21.mov |
If I load my stats offscreen, When front-end-monorepo/packages/lib-react-components/src/AnimatedNumber/AnimatedNumber.js Line 80 in 094daf5
|
NB. that code also means that project stats are always rendered as 0 during SSR, even though they've been set. Here are the Node console logs from that same page, running locally.
counts: { today: 0, total: 0 }
Stat: test-classify-your-stats-today-count Classifications today 0
{ animated: false, value: 0 }
Stat: test-classify-your-stats-total-count Classifications total 0
{ animated: false, value: 0 }
Stat: undefined Volunteers 6190
{ animated: false, value: 6190 }
Stat: undefined Classifications 810216
{ animated: false, value: 810216 }
Stat: undefined Subjects 71804
{ animated: false, value: 71804 }
Stat: undefined Completed subjects 28715
{ animated: false, value: 28715 } |
Now that I know how to reliably reproduce this bug, here's a screenshot showing the To reproduce this bug:
Those steps reliably reproduce the bug for me in desktop Firefox. Mobile Safari seems to be unaffected. https://www.zooniverse.org/projects/fulsdavid/the-daily-minor-planet/classify/workflow/22354 |
I think I see a bug. The effect hook here captures the The linter should really be warning about missing front-end-monorepo/packages/lib-react-components/src/AnimatedNumber/AnimatedNumber.js Line 65 in 094daf5
|
I've opened #6192 to fix the I’ve also added a check so that it won’t animate from 0 to 0, then set |
@shaunanoordin this isn't particularly exhaustive testing, but I'm seeing stats show up correctly in dev mode, with the changes in #6192. Screen recording from Firefox: Screen.Recording.2024-08-03.at.17.30.49.mov |
Here’s an explanation of the bug.
So the component will always show 0, if it loads offscreen and For a more technical explanation, I recommend MDN’s explanation of lexical scoping in closures. Each time the |
Here's a story that reproduces the bug. On the main branch, this story always shows 0. I've included it in #6192 so that you can reproduce the bug and check the fix. I think the bug was introduced in #5974, or possibly #5947. Neither of those PRs included export const DeferredAnimation = () => {
const [value, setValue] = useState(0)
setTimeout(() => setValue(700000000), 2000)
return (
<Box pad={{ vertical: '120vh' }}>
// this will always display 0, even if value changes.
<AnimatedNumber duration={4000} value={value} />
</Box>
)
} production-release: Screen.Recording.2024-08-04.at.17.04.55.movPR #6192: Screen.Recording.2024-08-04.at.17.06.02.mov |
@shaunanoordin this might not be a low priority bug after all, given that volunteer classification counts are always displayed as 0 when they load from Zooniverse APIs. They display fine if they load from session storage, which is why refreshing the page is a workaround. |
For anyone who's made it this far, congratulations, and the title of this issue is wrong. The bug has nothing to to do with Next.js. |
I've posted a link to Talk that reproduces this bug every time you click it: |
Here's a quick screen recording in Chrome, where I click that link three times and get the wrong counts each time. Weirdly, the daily stats sometimes show up, sometimes show as 0. Total counts are always 0. Screen.Recording.2024-08-06.at.18.50.11.mov |
Inconsistent UI Bug?
Package:
app-project
and/orlib-react-components
Confirmed as of commit:
Also see: #5974 (previous fix for AnimatedNumbers), #5971 (similar issue)
Possibly related Talk issue: https://www.zooniverse.org/talk/17/3402644 ?
In certain cases when the Next.JS server first fetches a page, it's possible for the Project Stats ("Classifications Today" and "Classifications Total" count on the Classify page) to not display accurate numbers, despite fetching the correct data.
Replicating this issue is a faff, but can be done on localhost:
yarn dev
)Screenshot: Project Stats show 0 Classifications Today and 0 Classifications Total, but the bar chart indicates otherwise.
Extended Testing
Asides from the issue seemingly stemming from the "initial Next.JS page fetch", additional testing shows that the Project Stats otherwise works fine.
While logged in, I can make classifications, and both the Classifications Today and Total counts update as expected. (About 5 classifications per test)
Dev Notes
Thoughts 1: I don't have enough expertise on the Next.JS infrastructure to understand why/how the fetch process would be a problem. Is it a hydration thing?
Even if it is, I can't tell if it's anything user-facing (i.e. if it affects the non-dev servers), and how I'd confirm/check that.
Thoughts 2: could it be possible that in certain scenarios, the animation of the
<AnimatedNumbers>
used in the project stats is interrupted, causing the numbers to "freeze" at 0 (for small counts) or appear to "lag" (for larger counts)?I'm starting to think if it's worth removing AnimatedNumbers altogether, if it's a potential cause of problems.
Thoughts 3: this may issue or may not be related to the Talk post that initiated this investigation, since that volunteer said that despite refreshing their page, the lag still persisted.
But then again:
Status
Unknown priority.Impact level unclear, but some volunteers are understandably upset when this occurs. Replicability/consistency of the issue is dubious since it relies on some Next.JS infrastructure shenanigans that I can only consistently replicate on my localhost.UPDATE (1 Aug): now set to low priority.
The text was updated successfully, but these errors were encountered: