Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scopes are broken in 4.1.0-Beta03 #2106

Open
Nek-12 opened this issue Jan 3, 2025 · 4 comments
Open

Scopes are broken in 4.1.0-Beta03 #2106

Nek-12 opened this issue Jan 3, 2025 · 4 comments
Labels
regression 💥 status:accepted accepted to be developed status:wait_feedback Need more details or follow-up
Milestone

Comments

@Nek-12
Copy link

Nek-12 commented Jan 3, 2025

Your changes to scope resolution break them in 4.1.0-Beta03, 4.1.0-Beta01 working fine.

This code no longer functions:

internal fun destinationComponent(
    destination: Destination?,
    context: ComponentContext
): DestinationComponent = object : ComponentContext by context, DestinationComponent {
    override val scope = getKoin().getOrCreateScope(
        scopeId = destination?.getScopeId() ?: "RootComponent",
        qualifier = qualifier<DestinationScope>(),
        source = context as? DestinationScope
    )
    override val coroutineScope = coroutineScope()

    init {
        scope.declare(instance = coroutineScope, allowOverride = false)
        context.typed<DestinationScope>()?.let { scope.linkTo(it.scope) }
        doOnDestroy { scope.close() }
    }

    override fun equals(other: Any?): Boolean {
        if (other !is DestinationComponent) return false
        return scope.id == other.scope.id
    }

    override fun hashCode(): Int = scope.hashCode()
}

Coroutine scope is not properly added to the koin scope in the example above. Additionally, scope seems to not be properly preserved during recompositions.

@arnaudgiuliani arnaudgiuliani added this to the 4.0.2 milestone Jan 8, 2025
@arnaudgiuliani
Copy link
Member

Spotted. Fixing it with #2111

@arnaudgiuliani
Copy link
Member

@Nek-12 could you help and give a try on 4.0.2-RC1?

@arnaudgiuliani
Copy link
Member

Publishing 4.1.0-Beta4. You are welcome to open design suggestion in https://github.com/InsertKoinIO/KFIP/ if you see any interesting update to help the project 👍

@arnaudgiuliani
Copy link
Member

@Nek-12 can you test 4.1.0-Beta5. this brings latest changes & fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression 💥 status:accepted accepted to be developed status:wait_feedback Need more details or follow-up
Projects
None yet
Development

No branches or pull requests

2 participants