https://kotlinlang.org logo
#compose-web
Title
# compose-web
s

saket

12/03/2021, 8:04 PM
can compose-web export html that can be hosted directly?
h

hfhbd

12/03/2021, 8:08 PM
Sure, not html, but JS. Compose for Web "just" uses plain Kotlin/JS, which creates a normal js executable (or library, if wanted).
s

saket

12/03/2021, 8:13 PM
would you know why html is unsupported? I was wondering if I could generate static htmls
c

Casey Brooks

12/03/2021, 8:16 PM
Compose itself is explicitly designed for rendering UI (or other tree structures) over time. All of its APIs are designed for optimizing trees that get updated over time, as a response to user inputs, for example. So Compose web doesn't really make sense to render to static HTML files, becaue they, by definition, do not change over time. Have you looked into kotlinx-html instead, which is designed for rendering static HTML? https://github.com/Kotlin/kotlinx.html
👍 1
h

hfhbd

12/03/2021, 8:23 PM
Static HTML does not support dynamic changes (does not matter if Compose or React etc).
s

saket

12/03/2021, 8:28 PM
yep, I've seen kotlinx.html but I wanted to leverage Compose UI.
Compose itself is explicitly designed for rendering UI (or other tree structures) over time.
right, but can a snapshot not be taken at a certain time?
c

Casey Brooks

12/03/2021, 8:34 PM
Compose web runs in the browser, while something that regenerates static HTML files would necessarily not run in the browser. It is in fact an entirely different thing, a static site generator (SSG). SSGs are more concerned with data and files than they are the HTML itself, and in a compose sense, it would need to be a completely new target (which is not a trivial thing to make.) In the past, I had written a Java SSG, Orchid, and recently have actually started toying with the idea of using Compose to re-implement it. An HTML site can absolutely be modeled as a tree, and the data that populates that site changes over time, which would make it a candidate for Compose. I definitely don't have any concrete plans to execute on that, but would be a good project for someone else who had time and a use-case for actually building it
s

saket

12/03/2021, 8:40 PM
I think I understand the challenges now. thanks for explaining!
h

hfhbd

12/03/2021, 8:48 PM
You can always take a snapshot of the current DOM and print it to a html file.
s

saket

12/03/2021, 8:51 PM
ooh, is that something that can be automated without opening a browser?
c

Casey Brooks

12/03/2021, 9:00 PM
Theres probably tools out there for that, but my guess would be that they would all be tied to NPM, which is always a challenge to get mixed with the Kotlin/Gradle build tooling. But honestly, if you're not using Compose Web for its over time, recomposition features, then it's just a fancy HTML DSL which is exactly what kotlinx-html is, and that will be a lot easier to work with in that automated way
s

saket

12/03/2021, 9:05 PM
that's a fair point. I really like compose ui's layouts like Box, Row, Column, etc., and wanted to reuse them for building html layouts.
c

Casey Brooks

12/03/2021, 9:16 PM
I believe those widgets were deprecated with the 1.0.0 release https://github.com/JetBrains/compose-jb/tree/master/tutorials/Web#module-composewebwidgets-deprecated. Looking at the implementation, they look like they're just using CSS classes/styles to emulate some of those layout behaviors. I'm not sure exactly what styling those widgets used, but FlexBox and CSS Grid are really great tools for layouts in modern HTML pages.
j

jw

12/03/2021, 9:24 PM
It can but it's not easy. I tried to do this to get isomorphic rendering working. Basically you run the composition once and produce the static HTML.
s

saket

12/03/2021, 9:26 PM
jake is it time for mosaic-web? 😄
j

jw

12/03/2021, 9:28 PM
Haha could be. But no I'd name it something like Compose Web for Desktop for maximum confusion and to lean in the poor naming trend.
😄 3
s

saket

12/03/2021, 9:31 PM
blob joy
h

hfhbd

12/04/2021, 12:03 PM
What about Compose Web Crane? 😄
👌 2
d

David Herman

12/15/2021, 4:58 AM
Hey, sorry, just saw this thread. @saket you may want to check out my project https://github.com/varabyte/kobweb. Part of it is a binary called
kobweb
and
kobweb export
runs Chrome and exports static html.
s

saket

12/15/2021, 6:52 PM
very interesting, I'll check it out. thanks david!
✌️ 1
9 Views