I just updated my project to Kotlin 1.8.0 and now ...
# javascript
j
I just updated my project to Kotlin 1.8.0 and now it can't deserialize a json array response: I have some simple code like this (Compose web):
Copy code
var cards by remember { mutableStateOf<List<Card>>(emptyList()) }
cards = http.get("/cards").body()
Which throws an error:
Copy code
TypeError: other.isEmpty_y1axqb_k$ is not a function
    equals Collections.kt:27
    equals_1 coreRuntime.kt:17
    equivalent_ika8t0_k$ SnapshotMutationPolicy.kt:90
    equivalent_f1gjis_k$ androidx-runtime.js:16246
    set_value_rnwamw_k$ Snapshot.kt:116
    CardPage$composable$lambda_4 CardPage.kt:108
    doResume_5yljmg_k$ CardPage.kt:36
    resumeWith_7onugl_k$ Standard.kt:55
    resumeWith_s3a3yh_k$ kotlin-kotlin-stdlib-js-ir.js:25366
    run_mw4iiu_k$ Continuation.kt:45
    lambda JsMicrotasksDispatcher.kt:11
CoroutineExceptionHandlerImpl.kt:11:12
    handleCoroutineExceptionImpl CoroutineExceptionHandlerImpl.kt:11
    handleCoroutineException CoroutineExceptionHandler.kt:33
    handleJobException_oc4gxk_k$ Builders.common.kt:196
    finalizeFinishingState JobSupport.kt:229
    tryMakeCompletingSlowPath JobSupport.kt:906
    tryMakeCompleting JobSupport.kt:863
    makeCompletingOnce_b13xy2_k$ JobSupport.kt:828
    resumeWith_s3a3yh_k$ AbstractCoroutine.kt:100
    resumeWith_7onugl_k$ Continuation.kt:54
    resumeWith_s3a3yh_k$ kotlin-kotlin-stdlib-js-ir.js:25366
    run_mw4iiu_k$ Continuation.kt:45
    lambda JsMicrotasksDispatcher.kt:11
More digging it seems to be a Ktor issue, filed here
m
Btw I'm not really familiar with compose for web, but one issue I do see: you are running the http call there in the compose function body. That means the http call will be made every single time the compose function is called (which can be quite a lot), that is almost certainly not what you want. I think you need to use LaunchedEffect to actually run the http call. The effect can run once, update the state, which would then trigger recomposition.
j
Yeah in my code it's in a LaunchedEffect, it's something with Ktor JS
👍 1
j
I experience a similar problem since i updated to kotlin 1.8.0. But with a coroutine. https://youtrack.jetbrains.com/issue/KT-56788
@Jacob Ferrero is your code public so that i can test if my described error case will produce the error in
Copy code
var cards by remember { mutableStateOf<List<Card>>(emptyList()) }
cards = http.get("/cards").body()
as well? Because i have the problem of reproducing the error outside of my codebase.
j
j
I found it already and i try to add my bug right now.
i just have to call http://localhost:4040/card/2 to get the error on your end?
I get the following error message in firefox:
Copy code
Uncaught TypeError: i.i3f is not a function
    a3f ListUtils.kt:238
    z3f Composition.kt:885
    l3g ListUtils.kt:238
    k3g Composition.kt:934
    c renderComposable.kt:96
    c renderComposable.kt:60
    c renderComposable.kt:60
    e CardPage.kt:26
    101 CardPage.kt:26
    Webpack 5
ListUtils.kt:238:33657
    a3f ListUtils.kt:238
    z3f Composition.kt:885
    l3g ListUtils.kt:238
    k3g Composition.kt:934
    c renderComposable.kt:96
    c renderComposable.kt:60
    c renderComposable.kt:60
    e CardPage.kt:26
    101 CardPage.kt:26
    Webpack 5
Which is in depended of ktor and happens on LaunchedEffect
@Jacob Ferrero can you confirm this on your end?
j
It would be /card/2/cards but card 2 would have to exist
I was seeing that when complied
j
how do i get a existing card?
The type error seams to be my issue it only happens in production and maybe causes also your list problem because it is related to ListUtils
j
You could just make that endpoint return a mock list of cards
j
Can i add a zip of your project to my issue as an example for the type error?
j
Yeah np
j
thank you