Open benkay opened 1 week ago
So there's a few paths forward here, and I'll probably do all of them:
Composition
(which likely implies 1). If you are hosting Molecule beneath Compose UI to drive the UI, we can make our composition a child of it.CoroutineDispatcher
is available as a key in the context, but if not perhaps we just hard fail?
The issue is demonstrated by the below code, which reproduces the issue without actually depending on Molecule. The original problem manifested as images loaded by Coil not fading in correctly - Coil's
CrossfadePainter
functions in much the same way as the Painter in this code.The cause seems to be
launch
within the global write observer doesn't actually dispatch, and apply notifications are sent immediately instead of in the next event loopinvalidateTick
state write is happening within the draw phase. This is where my Compose internals knowledge gets a bit fuzzy, but I'm guessing Snapshot.sendApplyNotifications() needs to happen after read SnapshotStateObserver.observeReads finishes for any updates to the read state to actually cause a change notification.The answer here seems to be "never use the immediate dispatcher", but it's very easy to do so without knowing at the moment. e.g.
viewModelScope.launchMolecule(..)
will use the immediate dispatcher unless otherwise specified.Perhaps Molecule could detect this and do the right thing?