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

CompositionLocal LocalDensity not present #204

Closed
xtexChooser opened this issue Jul 13, 2022 · 9 comments
Closed

CompositionLocal LocalDensity not present #204

xtexChooser opened this issue Jul 13, 2022 · 9 comments

Comments

@xtexChooser
Copy link
Contributor

xtexChooser commented Jul 13, 2022

When I was using this library in a Web project, I got this error: CompositionLocal LocalDensity not present.

Code:

@Composable
fun WebRouter() {
    HashRouter("/") {
        route("/") {
            Text("Hello World")
        }
    }
}

fun main() {
    renderComposable(rootElementId = "root") {
        Text("as")
        WebRouter()
    }
}

The exception threw in the Text in the router, the Text outside does not throw any exception.

Why is it happening? Thanks.

@xtexChooser
Copy link
Contributor Author

When I removed the WebRouter, the page rendered correctly.

@xtexChooser
Copy link
Contributor Author

xtexChooser commented Jul 13, 2022

However, when I move it out of the HashRouter, it does not works, too. But, if I call it directly in the renderComposable, it works.

The Text in

fun main() {
    renderComposableInBody {
        Text("TEST!")
        WebRouter()
    }
}

works, but below not:

@Composable
fun WebRouter() {
        Text("Test")
    HashRouter().route("/") {
        Routing()
    }
}

@hfhbd
Copy link
Owner

hfhbd commented Jul 13, 2022

Hey, could you provide a reproducer? I tried your first code:

@Composable
fun WebRouter() {
    HashRouter("/") {
        route("/") {
            Text("Hello World")
        }
    }
}

fun main() {
    renderComposable(rootElementId = "root") {
        Text("as")
        WebRouter()
    }
}

and it works fine.
untitled.zip

@xtexChooser
Copy link
Contributor Author

Yeah, I will later. Thanks.

@xtexChooser
Copy link
Contributor Author

@hfhbd I found the problem! It is caused by the Material 3.

This problem causes when using androidx.compose.material3.Text.

Add

@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
api(compose.material3)

then import androidx.compose.material3.Text. I think this is a problem of compose.

@hfhbd
Copy link
Owner

hfhbd commented Jul 13, 2022

Okay, so is it reproducible without routing? Otherwise could you still upload your reproducer to analyze the integration with routing?

@xtexChooser
Copy link
Contributor Author

emmm good problem, testing

@xtexChooser
Copy link
Contributor Author

Ok, I tested. It is JetBrains' job. androidx.compose.material3.Text does not work even without routing.

Really thanks.

@xtexChooser
Copy link
Contributor Author

Moved to JetBrains/compose-multiplatform#2186.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants