arkivanov / Decompose

Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing (navigation) and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.)
https://arkivanov.github.io/Decompose
Apache License 2.0
2.25k stars 85 forks source link

Same arguments result in duplicate HashCode in Component Configurations #733

Closed yeldar-nurpeissov closed 4 months ago

yeldar-nurpeissov commented 4 months ago

I have two components with config classes that have identical properties, like ID. Navigating from the first to the second component with the same hash-coded arguments causes an error: java.lang.IllegalArgumentException: Key kotlin.Pair_173 was used multiple times.

For example:

class SongDetailComponent {

    sealed interface Config {
        data class Detail(val id: String): Config
    }
}

class SingerDetailComponent {

    sealed interface Config {
        data class Detail(val id: String): Config
    }
}

If both song and singer have id = "1", navigating to the song screen works, but navigating to the singer screen results in the error.

The configs don't have to be in the same component to trigger this error.

IMHO, hashString() generates a hash from arguments.

Screenshot 2024-07-08 074601

Children Composable

Screenshot 2024-07-08 074632

Here is a sample code that produces the error.

Version: 3.2.0-alpha01

arkivanov commented 4 months ago

The hashString function also takes into account qualifiedName of the configuration class. This is a bug introduced in the recent version 3.2.0-alpha01 with DecomposeExperimentFlags.duplicateConfigurationsEnabled flag enabled. I will fix it, thanks!

arkivanov commented 4 months ago

Should be fixed in version 3.2.0-alpha02.