Quick question: Are live literals generation used ...
# compose-web
m
Quick question: Are live literals generation used by Compose Web? I read about it and it seems that it is used for hot reload (and afaik compose web doesn't support it), and by default it isn't enabled if you are building a Android app for release, but it looks like Compose Web generates live literals even if you are using
jsBrowserProductionWebpack
I found out (after a LOT of trial and error) that you can disable live literals generation on the module by using
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
	kotlinOptions {
		// Live Literals seems to be only used for hot reloading in dev mode, but Compose Web doesn't support hot reload yet
		freeCompilerArgs += listOf(
			"-P",
			"plugin:androidx.compose.compiler.plugins.kotlin:liveLiterals=false",
			"-P",
			"plugin:androidx.compose.compiler.plugins.kotlin:liveLiteralsEnabled=false"
		)
	}
}
Which is easier than prepending all of the files in your module with
@file:NoLiveLiterals
(The reason why I wanted to disable live literals is because I added Compose to an old Kotlin/JS project I had, and I was getting frustrated with all the "Duplicate live literal key found" errors)
d
@Oleksandr Karpovich [JB] Can you please help with answer?
o
By default live literals are disabled for all targets. the error “Duplicate live literal key found” is expected to be thrown anyway, since the LiveLiteralTransformer tries to check itself. What compose version do you use? Perhaps, Compose Compiler plugin version overridden?
m
@Oleksandr Karpovich [JB] currently I'm using Kotlin 1.7.10 + Compose 1.2.0-alpha01-dev750 However, it wasn't every single piece of code that was causing the error , it was mostly methods that were pretty "long" in size. Here's an class that triggers the error: https://github.com/LorittaBot/Loritta/blob/main/web/spicy-morenitta/src/main/kotlin/SaveStuff.kt
Copy code
Caused by: java.lang.IllegalStateException: Duplicate live literal key found: String$fun-prepareSave$class-SaveStuff
Caused by element at: C:/Users/Leonardo/IdeaProjects/LorittaBot/DeviousLoritta/web/spicy-morenitta/src/jsMain/kotlin/SaveStuff.kt:41:22
If you encounter this error, please file a bug at <https://issuetracker.google.com/issues?q=componentid:610764>
Try adding the `@NoLiveLiterals` annotation around the surrounding code to avoid this exception.
Yes, I know, that class is a super weird mess, this code is from ~2019 so I may have done some... questionable decisions when making it (using jQuery lol) Keep in mind that technically the version on the repository is not "up to date" yet, since I haven't committed my local changes (updated the module from LEGACY to IR, updated the classes to work with the IR compiler, added Compose to the module, etc)
o
I see. If you wish to push a branch with updated repo (with KJS/IR, Compose, etc), then I we would try to investigate and learn what’s going on. An issue on github would help us too 🙂 https://github.com/JetBrains/compose-jb/issues
268 Views