@@ -55,7 +55,6 @@ import com.bumptech.glide.integration.ktx.Status
55
55
import com.bumptech.glide.integration.ktx.flowResolvable
56
56
import com.bumptech.glide.internalModel
57
57
import com.bumptech.glide.load.DataSource
58
- import com.bumptech.glide.util.Preconditions
59
58
import kotlinx.coroutines.CoroutineScope
60
59
import kotlinx.coroutines.Dispatchers
61
60
import kotlinx.coroutines.Job
@@ -395,18 +394,25 @@ internal class GlideNode : DrawModifierNode, LayoutModifierNode, SemanticsModifi
395
394
396
395
@OptIn(ExperimentGlideFlows ::class , InternalGlideApi ::class , ExperimentalComposeUiApi ::class )
397
396
private fun launchRequest (requestBuilder : RequestBuilder <Drawable >) =
398
- // Launch via sideEffect because onAttach is called before onNewRequest and onNewRequest is not
399
- // always called. That means in onAttach if we launch the request, we might restart an old
400
- // request only to have it immediately replaced by a new request, causing jank. Or if we don't
401
- // launch the new requests in onAttach, then onNewRequest might not be called and we won't show
402
- // the old image.
403
- // sideEffect is called after all changes in the tree, so we can always queue a new request, but
397
+ // Launch via sideEffect because onAttach is called before onNewRequest and onNewRequest is not
398
+ // always called. That means in onAttach if we launch the request, we might restart an old
399
+ // request only to have it immediately replaced by a new request, causing jank. Or if we don't
400
+ // launch the new requests in onAttach, then onNewRequest might not be called and we won't show
401
+ // the old image.
402
+ // sideEffect is called after all changes in the tree, so we can always queue a new request, but
404
403
// drop any for old requests by comparing requests builders.
405
404
sideEffect {
405
+ // The request changed while our sideEffect was queued, which should also have triggered
406
+ // another sideEffect. Wait for that one instead.
406
407
if (this .requestBuilder != requestBuilder) {
407
408
return @sideEffect
408
409
}
409
- Preconditions .checkArgument(currentJob == null )
410
+ // We've raced with another sideEffect, our previous check means that the request hasn't
411
+ // changed and this check means we're already loading that image, so we have nothing useful to
412
+ // to do.
413
+ if (currentJob != null ) {
414
+ return @sideEffect
415
+ }
410
416
currentJob = (coroutineScope + Dispatchers .Main .immediate).launch {
411
417
placeholder = null
412
418
placeholderPositionAndSize = null
0 commit comments