https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • d

    Daniele B

    09/18/2020, 6:41 PM
    I have a multiplatform project, with a shared module. When I run “assemble” on the js project, I get this error:
    Execution failed for task ':shared:jsPackageJson'.
    > NPM Dependencies already resolved and installed
    at org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager.requireConfiguringState$kotlin_gradle_plugin(KotlinNpmResolutionManager.kt:122)
    at org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask.getCompilationResolver(KotlinPackageJsonTask.kt:26)
    at org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask.getPackageJson(KotlinPackageJsonTask.kt:50)
    any idea?
    t
    a
    • 3
    • 15
  • d

    Daniele B

    09/19/2020, 11:35 AM
    anyone knows how to get the
    PATH_VALUE
    value inside route() in Kotlin/React ?
    browserRouter {
        switch {
            route("/country/*") {
                getCountry(PATH_VALUE.split("/")[2])
                ...
            }
    	...
        }
    }
    h
    • 2
    • 2
  • b

    Big Chungus

    09/20/2020, 3:29 PM
    Was nodejs require removed from stdlib in 1.4? Can't find it anymore
    t
    b
    g
    • 4
    • 26
  • d

    Daniele B

    09/20/2020, 11:45 PM
    Is there anything I can do to reduce the size of the built .js file for a Kotlin/React project? For a relatively simple project the js file is 2.7 MB. I am using the gradle
    build
    command, which I guess it’s already doing DCE (Dead Code Elimination).
    t
    b
    n
    • 4
    • 23
  • j

    Josh Feinberg

    09/21/2020, 1:48 AM
    maybe im misunderstanding how this should work, but if i create a new object, it should not try to restore the state, right?
    a
    • 2
    • 8
  • d

    Daniele B

    09/21/2020, 1:42 PM
    I am using styled.StyleSheet for CSS on Kotlin. And I would like to specify a value in percentage.
    width = 50.percent
    this doesn’t seem to be recognized what is the way to set a percentage value in Kotlin / CSS ?
    b
    b
    • 3
    • 3
  • d

    Daniele B

    09/21/2020, 6:04 PM
    Is it possible to have a callback (or something equivalent) in Kotlin/React to detect changes of the browser width? for example in case the browser window is resized
    b
    • 2
    • 2
  • d

    Daniele B

    09/21/2020, 11:48 PM
    I would like to build two components in Kotlin/React:
    MyElementsList
    and
    MyElement
    MyElementsList(content = {
        MyElement(label = "a", value = "1")
        MyElement(label = "b", value = "2")
        MYElement(label = "c", value = "3")
    })
    what should be the definition of MyElementsList’s
    content
    parameter to be able to pass a block of components ? currently this is what I wrote, but it doesn’t seem to work:
    fun RBuilder.ElementsList(content: (ReactElement) -> Unit) = child(ElementsList) {
        attrs {
            this.content = content
        }
    }
    
    external interface ElementsListProps : RProps {
        var content : (ReactElement) -> Unit
    }
    
    val ElementsList = functionalComponent<ElementsListProps> { props ->
        div {
            props.content
        }
    }
    it compiles, but it just shows
    <div></div>
    with no content the
    MyElement
    components are shown correctly if they are not enclosed in the
    MyElementsList
    component, so it looks like the issue is in the
    MyElementsList
    component
    b
    • 2
    • 12
  • a

    adk

    09/22/2020, 9:09 AM
    New to kotlin js here. Trying to get a usable set of externals for a node library web-request. What strategies are people using for creating externals? Using
    generateExternals = true
    from gradle doesn't give any opportunity to tweak the generated files, yet they all seem to need tweaking?
    b
    b
    v
    • 4
    • 10
  • d

    Daniele B

    09/22/2020, 12:50 PM
    If instead of using
    routeLink
    , I want to change the url when I am clicking on a
    td
    element, what code should I use?
    s
    d
    • 3
    • 6
  • d

    Daniele B

    09/22/2020, 3:02 PM
    I would like to change the background color of a TR element onMouseOver
    tr {
    	attrs {
                onMouseOver = { HOW DO I CHANGE BG COLOR? }
    	}
    }
    I guess I need to use the
    onMouseOver
    attribute. But how do I change the background color programmatically?
    b
    • 2
    • 2
  • d

    Daniele B

    09/23/2020, 2:51 PM
    What would people here say about the performance of Kotlin/React? In my case, on desktop it feels ok, but on mobile it feels a bit too slow. I am using the standard compiler, as I have issues compiling with the IR compiler. The filesize is about 2.8MB, which is not very little. I read that with IR compiler the performance is supposed to improve. What is your current feeling about Kotlin/React? Are you using it for production projects? Are you waiting for better performance?
    b
    j
    h
    • 4
    • 41
  • o

    Ondrej Zavodny

    09/23/2020, 8:15 PM
    HI! Today I was trying to use TailwindCSS in my KotlinJS project and I can't find a way to do it. Can anyone help please? I didn't find anything in the documentation on how to link external CSS/PostCSS to my project. One thing I tried is posted on StackOverflow https://stackoverflow.com/questions/64029151/how-to-add-tailwindcss-to-kotlinjs. I will update the question if someone helps.. Thanks!
    b
    t
    • 3
    • 7
  • p

    peekandpoke

    09/24/2020, 6:59 AM
    Hi there! I am switching a KotlinJS project to Kotlin 1.4.10. Everything is fine except that the Webpack-dev-server auto-reload does no longer work. Loading the page initially works. I am also running
    gradle -t assemble
    for continuous building. But as soon as I change some code I get this error:
    Failed to compile.
    
    (webpack)-dev-server/client?<http://localhost:8888>
    Module build failed (from /PROJECT/build/js/node_modules/source-map-loader/dist/cjs.js):
    Error: ENOENT: no such file or directory, open '/PROJECT/build/js/node_modules/webpack-dev-server/client/index.js'
    I checked what is going on and indeed there is no webpack-dev-server present in build/js/node_modules folder. I should also mention that I have multiple JS modules in my project. So maybe they all write to the build/js/node_modules directory and interfere with each other, as they have different configurations. But even when only building a single module the problem stays the same. I then tried to be sneaky and added this to one of the build.gradle files
    testImplementation npm("webpack-dev-server", "3.11.0")
    Which in fact solves the issue with reload in so far, that the error does no longer show up and that in build/js/node_modules there truely is the webpack-dev-server dependency. But now the problem is: The page is reloading on code changes -> Good -> BUT: the changes are not picked up -> BAD Does anyone have an idea what to look for or some workaround? Thank you for reading 🙂
    👍 1
    i
    • 2
    • 6
  • c

    Christian Jensen

    09/24/2020, 8:25 AM
    Hi. Android dev trying out multiplatform for our company. Got sharing to iOS working, and now working on Js part. Can I from Android Studio generate javascript from our shared library or do I need IntelliJ IDEA to do that?
    a
    t
    v
    • 4
    • 5
  • a

    adk

    09/24/2020, 3:35 PM
    I'd like to write some tests for my kotlin/js code in typescript, so that I can verify that I can call my lib that way I expect. I can create a whole new gradle subproject for this, but wondering if there is a simpler way to do it, where the typescript test source tree sits alongside my kotlin test source tree. How are other people approaching this?
    h
    • 2
    • 3
  • d

    Daniele B

    09/24/2020, 6:41 PM
    I have been playing with
    Kotlin/React
    for a few days and I found it interesting. I was very amazed by the chance of creating HTML/CSS using Kotlin DSL rather than plain HTML/CSS. It is very powerful, as the the HTML and CSS are created automatically in an optimized way, without having to organize CSS classes yourself. However I was disappointed by the
    performance
    and by the
    js filesize
    . I am working on a multiplatform project, with a shared ViewModel, which on Android is plugged into a JetpackCompose UI and on iOS into SwiftUI. I am looking for the best way to use my declarativeUI-ready ViewModel on web too, via
    StateFlow
    . My basic requirements for a web framework are these 5: • collect a StateFlow emitted by the KMP shared ViewModel • create HTML components using Kotlin DSL • use a decent variety of already made web components • react to ViewModel state changes quickly • compile to a small JS filesize I just came across two interesting web frameworks written in Kotlin: `Fritz2`: https://www.fritz2.dev/ `KVision`: https://kvision.gitbook.io/ I would be very interesting to hear the experiences of people here, and how they compare them in terms of performance and filesize to React/Kotlin:
    r
    a
    j
    • 4
    • 44
  • d

    Devil Ster 1

    09/25/2020, 7:52 AM
    Hi all! I have a question ) I want to try gh-pages with Kotlin React. With regular REactJs - it is very simple and clear. But not with Kotlin, Troubles begin from first minute. I need modify package.json and i need to add custom node tasks and gradle task to run node task... Is there any clear documentation or articles how to do it? Thx
    b
    • 2
    • 2
  • d

    Daniele B

    09/25/2020, 10:41 AM
    I just opened an issue to ask for an improvement of the JS filesize when Ktor is used as a simple Http Client: https://youtrack.jetbrains.com/issue/KT-42189 Please Upvote.
    👍 4
    a
    r
    +2
    • 5
    • 12
  • d

    Daniele B

    09/25/2020, 10:56 PM
    I would like to display data in a chart in a Kotlin/React project. Any suggestion? I found out about this graphs library: https://react-charts.js.org/ Can I easily use it in Kotlin/React?
    a
    • 2
    • 6
  • t

    turansky

    09/27/2020, 10:41 AM
    How I can activate
    @JsExport
    for legacy mode in Kotlin 1.4?
    b
    • 2
    • 3
  • c

    Christian Dräger

    09/27/2020, 3:53 PM
    hey, i am currently experimenting with a react app written in kotlinjs. i’m wondering how to use npm dependencies that are extending react functionality and how this plays together when using the kotlin-react wrapper provided by jetbrains. for instance i want to use this lib https://fkhadra.github.io/react-toastify/introduction i use a lot in react projects without kotlin and can confirm it works great and out of the box. the lib is completely written in typescript. so i would expect dukat to generate externals propperly when adding
    implementation(npm(name = "react-toastify", version = "6.0.8", generateExternals = true))
    to my build gradle. and it actually does but i am wondering how to use the generated externals. The libraries documentation says <ToastContainer …props /> has to be added to the apps JSX code. in my generated externals i found a
    useToastContainer
    function in the generated externals (see screenshot). no extension function to RBuilder or something that looks like i can just use it straight away questions: is there a naming convention that dukat uses to place the public functions of a dependency like prefixing the file that includes the api of a library with ‘use….’ ? if not, where are the public functions of library placed that has a dukat generated kotlin wrapper? do i need to write an extension function to RBuilder like `fun RBuilder.toastContainer() = useToastContainer()`to use it with kotlin react wrapper?
    useToastContainer
    wants
    ToastContainerProps
    which is an interface regarding to the generated externals i couldn’t find an implementation of that interface. I would assume an implementation with default values like the original lib has. so im wondering how to use this or do i have to implement it myself (would be extremely unhandy since it has a lot of props) ? what experiences do you have using libraries that extend react in kotlinjs?
    j
    • 2
    • 10
  • a

    altavir

    09/29/2020, 8:58 AM
    I've finally made a plotly.kt build with IR (we won't support legacy mode after 0.3.0 release. The bundle including plotly-core itself is about 1 MB. I think it was at least twice that size before
    🎉 1
    🔥 7
    t
    b
    • 3
    • 11
  • g

    gaetan

    09/29/2020, 4:01 PM
    Will the new version of DCE allow to remove some portion of code depending on a boolean value? It could be interesting to have some debug/logging code but with no performance or code size impact in production. @bashor?
    ➕ 1
    t
    b
    • 3
    • 9
  • a

    adk

    09/29/2020, 4:03 PM
    Trying out the typescript definition generation from the IR compiler. It seems that there is a fair bit of code that doesn't seem all that useful, like the
    component1()
    methods used in destructuring - which I can't see being used in typescript or javascript. Are we likely to see cleaner typescript definitions from multiplatform kotlin libs as this shapes up towards GA status? Or am I perhaps just missing something?
    ➕ 2
    t
    • 2
    • 7
  • a

    ankushg

    09/29/2020, 4:57 PM
    Does DCE honor
    @JsExport
    annotations, or do we still need to manually pass in a list through
    keep
    ?
    t
    a
    • 3
    • 6
  • s

    spierce7

    09/30/2020, 4:18 AM
    Is there a way to pass arguments to a kotlin nodejs application?
    d
    v
    • 3
    • 3
  • b

    BearDev

    09/30/2020, 11:00 AM
    For node.js kotlin/js project created with Intellij, is there some documentation on how to create an executable .js file that I can run outside the IDE environment? I have
    binaries.executable()
    set in the build.gradle, but I cannot find the generated production .js file(s) in the build directory.
    v
    • 2
    • 2
  • a

    Alexander Weickmann

    09/30/2020, 3:29 PM
    Can the copy function of data classes be used in KotlinJS? I get "Uncaught TypeError: copy is not a function"
    t
    • 2
    • 17
  • a

    adk

    10/01/2020, 2:11 PM
    Anyone had any success with using typescript's await to call a function implemented in Kotlin/JS?
    c
    r
    a
    • 4
    • 21
Powered by Linen
Title
a

adk

10/01/2020, 2:11 PM
Anyone had any success with using typescript's await to call a function implemented in Kotlin/JS?
c

Casey Brooks

10/01/2020, 2:14 PM
I believe
await
in JS/TS is just syntactic sugar over a Promise, so you should be ableto return a
Promise<T>
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-promise/) from Kotlin to be able to
await
it from TS. You likely can’t
await
a
suspend
Kotlin function
a

adk

10/01/2020, 2:15 PM
Thanks for the quick response 🙂 yes, I'm attempting to do just that
the problem seems to be that the .d.ts definitions generated by the IR compiler have my functions returning kotlin.js.Promise, which TypeScript has no sugar for
r

Robert Jaros

10/01/2020, 2:23 PM
it's a bug: https://youtrack.jetbrains.com/issue/KT-41096
a

adk

10/01/2020, 2:24 PM
ha - thanks 🙂
My little experiment with kotlin and typescript seems to be running into a few of those!
Any known workaround for this, other than hand-rolling (or editing) my own .d.ts files?
c

Casey Brooks

10/01/2020, 4:29 PM
What happens if you convert it to a
dynamic
type instead of
Promise
?
a

adk

10/02/2020, 2:48 PM
actually, that works - good suggestion! 🙂
🎉 1
Unfortunately, the object that comes back is mangled beyond use by other bugs - but the promise is unwrapped!
If I have an unexported kotlin class that implements an exported interface, the class name and property names are mangled by the IR and cannot be addressed via the names exported to my .d.ts file.
The class cannot be exported because of a bug that prevents
@JsExport
and
@Serializable
on the same class.
Implementing the exported interface seemed like an elegant workaround, but I guess I will have to try having two classes - one serializable and the other exported, then copying the data between them.
a

ankushg

10/02/2020, 11:41 PM
@adk Could you maybe use @JsName in the class to work around that and prevent mangling on the class?
a

adk

10/07/2020, 10:53 AM
@ankushg Unfortunately that's not allowed. You can't use JsName in a non-exported class and you can't export a serialisable class.
So, it turns out that the IR compiler generates all JS code with underscores prefixing member names. Properties of exported classes have properties added to the prototype to map between the JS variable and the declared/exported member name, but if you export an interface, but not its implementation class, then that mapping does not occur.
Falling back to `JsExport`ing one class, while having a Serializable copy of the class for internal use works.
a

ankushg

10/07/2020, 5:23 PM
Interesting -- would love to see an example. JsExport + Serialization issues are one of our biggest blocker for trying out IR
a

adk

10/08/2020, 7:59 AM
Unfortunately I can't make the code public, but the approach is very straightforward. Simply copy/paste your data class and replace
@JsExport
with
@Serializable
.
For context, I am doing this as part of a spike to investigate whether Kotlin multiplatform with TypeScript via the IR compiler can be of use to us. There have been quite a few hoops to jump through to get it working - this little hack being only the latest of them.
Having only one place to maintain your domain model for different clients of your API is quite a powerful feature, but you have to be pretty determined to get it working - and willing to sacrifice a bit of elegance in your code. The remaining step in my spike is to work out to what extent I can encapsulate the ugliness to produce an API that both typescript and JVM developers will be happy to consume. I suspect we may choose to wait a bit before any actual adoption.
View count: 3