-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix(renterd): first file download no bucket error #853
fix(renterd): first file download no bucket error #853
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
4 Skipped Deployments
|
🦋 Changeset detectedLatest commit: 2bb17b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
2d9acb0
to
0f8b3ab
Compare
089cf88
to
a4690a8
Compare
0f8b3ab
to
d9c5154
Compare
a4690a8
to
4dd4474
Compare
d9c5154
to
1b892c0
Compare
4dd4474
to
d463b3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange issue where buckets.data is still undefined in the closure even though the data has been fetched. Adding useCallback does the trick, oddly even just console logging buckets.data above downloadFiles fixes the issue.
I've been mulling this over a bit because it is an interesting issue! On its face, it could appear to treat a symptom and not the cause. That's what I initially thought, but after thinking a bit, here's what I believe is going on:
When you define a function like downloadFiles
, it captures the state of buckets.data
at that moment. React doesn’t create a new function reference on subsequent renders unless explicitly instructed to (as with useCallback
), which is why you're seeing a stale reference. The closure retains the value of buckets.data
as it was when the function was first defined, without updating automatically.
The reason console.log
has the correct value is that it forces the runtime to evaluate the current value of buckets.data
at the time the log statement is executed. So console.log() is the current render and downloadFiles
is likely the first render.
All that said, I believe this is exactly the right answer to the problem. It's probably more of a use case for useCallback
than most other common uses.
1b892c0
to
06dc7dc
Compare
d463b3a
to
3308af9
Compare
@telestrial it has to be something with a stale closure but when
The behaviour you describe should be when you do a useCallback with empty deps |
Single test failing due to: SiaFoundation/renterd#1747 |
3308af9
to
2bb17b5
Compare
Notes