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

Compose Multiplatform support for Web (Wasm) #440

Open
nowiwr01w opened this issue Dec 4, 2023 · 13 comments
Open

Compose Multiplatform support for Web (Wasm) #440

nowiwr01w opened this issue Dec 4, 2023 · 13 comments
Labels
API coverage Request for missing APIs

Comments

@nowiwr01w
Copy link

@nbransby Hello, can you share your thoughts about wasm support?
As I can see, it's relevant for some people (including me)
#426

@nowiwr01w nowiwr01w added the API coverage Request for missing APIs label Dec 4, 2023
@nbransby
Copy link
Member

nbransby commented Dec 5, 2023

Unless Google adds official support for WASM to Firebase the only way to get it working would be to bind the calls from wasm to the Firebase JS SDK like we do now for traditional JS targets. Im afraid I don't know enough about wasm to comment on how to do this but I can see something similar has been attempted for rust: https://github.com/jquesada2016/firebase-wasm-rs

@Thaerith
Copy link

Have you tried to copy/paste the kotlin/js implementation to the wasm ?
it is a very naive way to do but packages and the way it works are the same...

maybe could you create a branch where you copy/paste and I can fix the issues ?

@DanielWeidensdoerfer
Copy link

Also interested in WASM integration. Currently using js version of firebase in wasm target. Copying the kotlin js implementation to wasm js should work. Some features of kotlin js are not available/different in wasm, so some tweaks could be necessary.

@Shanezor12
Copy link

Also interested in seeing this happen

@nowiwr01w
Copy link
Author

Any updates?(

@Thaerith
Copy link

I have copy/pasted js variant to wasmJs one but I cannot push my branch... 🙄

@nbransby
Copy link
Member

you need to create a fork and push to that and create your pr from there

@Thaerith
Copy link

Thaerith commented May 19, 2024

if some of you can build and deploy locally to try -- some classes are missing, trying to replace them

#511

@Ic-ks
Copy link

Ic-ks commented May 19, 2024

@Thaerith I had a short look onto your PR and I am surprised that the compiler for the wasmJS target does not enforce you to use the JsAny types (like JsString, JsBoolean and so on). These types should be used for everything which is passed to, or returned from the JavaScript code. That's one of the main differences between the pure js target and the wasm target: https://kotlinlang.org/docs/wasm-js-interop.html#kotlin-wasm-and-kotlin-js-interoperability-differences
I think the copy paste approach is not the best way regarding the maintenance. Maybe it is smarter to create a browser-common configuration with its own sourceset which can be used by the wasmJs target and by the js target. I saw this approach in the popular multiplatform-settings project: https://github.com/russhwolf/multiplatform-settings/
Here the relevant commit: russhwolf/multiplatform-settings@d1c7d9e

@Thaerith
Copy link

You're right, the copy/paste approach cannot work. I pushed to fast, sorry.

I am trying to convert to wasm api (using JsArray...). For most of methods it can work but there is tricky parts (usualy with '.toJSon' extensions) where I'm not sure what to use (using external interfaces seems OK but the extension has to be converted to simple method).

I will check your solution 👌

@Ic-ks
Copy link

Ic-ks commented May 19, 2024

I followed your copy paste suggestion by myself. But only for the app, auth and common module: Ic-ks@3933cea
At the end I was able to get an anonymous firebase user with a test wasmJs app. But there is a lot more to do if the code should be shared between both targets. I can try to support you :)
For the external interfaceit is possible to extend it from JsAny. For FirebaseOptions you can create and use an instance of this class (I found this code in the kotlin slack channel):

@kotlin.js.JsName("Object")
external class JsObject : JsAny {
    operator fun get(key: JsString): JsAny?
    operator fun set(key: JsString, value: JsAny?)
}

fun json(vararg params: Pair<String, Any?>): JsObject {
    return JsObject().apply {
        params.forEach {
            val key = it.first.toJsString()
            when (val value = it.second) {
                is String -> set(key, value.toJsString())
                is Boolean -> set(key, value.toJsBoolean())
                is Int -> set(key, value.toJsNumber())
                is JsObject -> set(key, value)
                is JsString -> set(key, value)
                is JsBoolean -> set(key, value)
                is JsNumber -> set(key, value)
                is JsArray<*> -> set(key, value)
                else -> error("Unsupported type ${it::class}")
            }
        }
    }
}

@Hamamas
Copy link

Hamamas commented Jun 2, 2024

Hi any update

@nbransby nbransby mentioned this issue Jun 3, 2024
@nowiwr01w
Copy link
Author

@Ic-ks @Thaerith Can you guys share a branch if you have something? We can try together

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

No branches or pull requests

7 participants