Stack Exchange
Another supplier is already registered with the key: DefaultChildStack while using Decompose and Koin
What is expected
on process death and orientation change, the component instance be retained and state preserved
What I've tried
In a compose multiplatform project shared directory
class DefaultRootComponent(componentContext: ComponentContext) : RootComponent,
    ComponentContext by componentContext, KoinComponent {

    ...

    override val childStack: Value<ChildStack<*, RootComponent.Child>>
        get() = childStack(
            source = navigation,
            initialConfiguration = Config.HomeScreen,
            handleBackButton = true,
            childFactory = ::createChild
        )
    ...
}

in MainActivity.kt
class MainActivity : AppCompatActivity() {
    @OptIn(ExperimentalDecomposeApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        WindowCompat.setDecorFitsSystemWindows(window, false)

        val root = retainedComponent { componentContext ->
            DefaultRootComponent(componentContext)
        }

        setContent {
            val systemUiController = rememberSystemUiController()
            val useDarkIcons = !isSystemInDarkTheme()

            DisposableEffect(systemUiController, useDarkIcons) {
                systemUiController.setStatusBarColor(
                    color = Color.Transparent, darkIcons = useDarkIcons
                )

                onDispose { }
            }

            MainView(
                root = root,
                useDarkTheme = isSystemInDarkTheme(),
                dynamicColor = true,
            )
        }
    }
}

Koin logs just before the crash
|- 'ui.homescreen.HomeScreenComponent' ...
| >> parameters DefinitionParameters[com.arkivanov.decompose.DefaultComponentContext@164207, (kotlin.String) -> kotlin.Unit] 
| << parameters
|- 'ui.homescreen.HomeScreenComponent' in 20.7406 ms

android runtime crash logs
FATAL EXCEPTION: main
Process: com.ayitinya.hostelogo, PID: 6134
java.lang.IllegalStateException: Another supplier is already registered with the key: DefaultChildStack
at com.arkivanov.essenty.statekeeper.DefaultStateKeeperDispatcher.register(DefaultStateKeeperDispatcher.kt:44)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt.children(ChildrenFactory.kt:93)
at com.arkivanov.decompose.router.children.ChildrenFactoryKt.children$default(ChildrenFactory.kt:61)
at com.arkivanov.decompose.router.stack.ChildStackFactoryKt.childStack(ChildStackFactory.kt:91)
at com.arkivanov.decompose.router.stack.ChildStackFactoryKt.childStack(ChildStackFactory.kt:40)
at navigation.DefaultRootComponent.getChildStack(DefaultRootComponent.kt:106)
...


I think the issue is because your childStack property has a getter, so it registers a new instance of ChildStack on every access. You should just assign ChildStack to the property.

Works like a charm. Would be grateful if you good give a quick explainer on how that changes things.
thanks a lot @ArkadiiIvanov

Sure! The childStack function is an extension function on ComponentContext. When called, it attaches the Child Stack to the ComponentContext. Calling the method multiple times with the same key argument (or with the default key if not specified) throws an error, because another Child Stack already exists.

that's understood, thank you @ArkadiiIvanov
