JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.58k stars 1.13k forks source link

ERROR: onReuse is only expected on attached node #3977

Closed mahramane closed 3 months ago

mahramane commented 8 months ago

Describe the bug Hi I use a LazyColumn in a TabRow with 3 Tab and Load a list from server and show it in LazyColumn . also i reload data when tab change. When I change tab more than 4 or 5 times i get the following error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: onReuse is only expected on attached node
        at androidx.compose.ui.node.LayoutNode.onReuse(LayoutNode.kt:1326)
        at androidx.compose.runtime.ComposerImpl$useNode$2.invoke(Composer.kt:1638)
        at androidx.compose.runtime.ComposerImpl$useNode$2.invoke(Composer.kt:1637)
        at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818)
        at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:849)
        at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:625)
        at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:537)
        at androidx.compose.runtime.BroadcastFrameClock$FrameAwaiter.resume(BroadcastFrameClock.kt:42)
        at androidx.compose.runtime.BroadcastFrameClock.sendFrame(BroadcastFrameClock.kt:71)
        at androidx.compose.ui.ComposeScene.render(ComposeScene.skiko.kt:543)
        at androidx.compose.ui.awt.ComposeBridge$skikoView$1$onRender$1.invoke(ComposeBridge.desktop.kt:178)
        at androidx.compose.ui.awt.ComposeBridge$skikoView$1$onRender$1.invoke(ComposeBridge.desktop.kt:177)
        at androidx.compose.ui.awt.ComposeBridge.catchExceptions(ComposeBridge.desktop.kt:150)
        at androidx.compose.ui.awt.ComposeBridge.access$catchExceptions(ComposeBridge.desktop.kt:64)
        at androidx.compose.ui.awt.ComposeBridge$skikoView$1.onRender(ComposeBridge.desktop.kt:177)
        at org.jetbrains.skiko.SkiaLayer.update$skiko(SkiaLayer.awt.kt:548)
        at org.jetbrains.skiko.redrawer.AWTRedrawer.update(AWTRedrawer.kt:54)
        at org.jetbrains.skiko.redrawer.Direct3DRedrawer$frameDispatcher$1.invokeSuspend(Direct3DRedrawer.kt:49)
        at org.jetbrains.skiko.redrawer.Direct3DRedrawer$frameDispatcher$1.invoke(Direct3DRedrawer.kt)
        at org.jetbrains.skiko.redrawer.Direct3DRedrawer$frameDispatcher$1.invoke(Direct3DRedrawer.kt)
        at org.jetbrains.skiko.FrameDispatcher$job$1.invokeSuspend(FrameDispatcher.kt:33)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:789)
        at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:740)
        at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:734)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:759)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
        Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.awt.ComposeBridge$coroutineExceptionHandler$1@52349d1d, androidx.compose.runtime.BroadcastFrameClock@78eee1ce, StandaloneCoroutine{Cancelling}@fd0ecb1, FlushCoroutineDispatcher@422af020]

I get it only in jvm (windows).

Affected platforms Select one of the platforms below:

Versions

mazunin-v-jb commented 8 months ago

Hello! Thank you for submitting the issue. Could you please provide the minimal reproducer?

RoustamManookian commented 7 months ago

Hi, I have exactly the same case. I have HorizontalPager with LazyColumn that updates the content data by fetching the data from Room. In the beginning, everything starts OK, but after swiping a few times it crashes with this Exception

FATAL EXCEPTION: main Process: com.manookian.scs, PID: 16348 java.lang.IllegalArgumentException: onReuse is only expected on attached node at androidx.compose.ui.node.LayoutNode.onReuse(LayoutNode.kt:1326) at androidx.compose.runtime.ComposerImpl$useNode$2.invoke(Composer.kt:1637) at androidx.compose.runtime.ComposerImpl$useNode$2.invoke(Composer.kt:1636) at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818) at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:849) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:625) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:537) at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:41) at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109) at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41) at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1319) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1329) at android.view.Choreographer.doCallbacks(Choreographer.java:930) at android.view.Choreographer.doFrame(Choreographer.java:854) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1303) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8810) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@833f024, androidx.compose.ui.platform.MotionDurationScaleImpl@120678d, StandaloneCoroutine{Cancelling}@e673d42, AndroidUiDispatcher@9ab6153]

RoustamManookian commented 7 months ago

I noticed that when I swipe slowly everything works fine, but when I swipe quicker it crashes. It seems that when it's not finishing the first fetch you swipe and it's starting a new fetch happens the crash.

mazunin-v-jb commented 6 months ago

Hello @RoustamManookian! The same question for you: could you please provide a reproducible example for that? And could you also provide info about your setup (versions, OS, etc.)? Or they're the same as @mahramane has?

David-Buyer commented 4 months ago

Hello, i have the same issue with ScalingLazyColumn on Wear OS. in My Galaxy Watch 4 device. It happens randomly ( but often ) while scrolling process effectively.

Versions

Did you find a solution it about ?

RoustamManookian commented 4 months ago

@mazunin-v-jb My issue was that I was making a DB fetch in DisposableEffect of the element composable. I fixed it by collecting all the data for all elements in the viewModel and providing the corresponding data to each element to it's contsructor.

okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.