can compose-web export html that can be hosted dir...
# compose-web
s
can compose-web export html that can be hosted directly?
h
Sure, not html, but JS. Compose for Web "just" uses plain Kotlin/JS, which creates a normal js executable (or library, if wanted).
s
would you know why html is unsupported? I was wondering if I could generate static htmls
c
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
Static HTML does not support dynamic changes (does not matter if Compose or React etc).
s
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
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
I think I understand the challenges now. thanks for explaining!
h
You can always take a snapshot of the current DOM and print it to a html file.
s
ooh, is that something that can be automated without opening a browser?
c
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
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
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
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
jake is it time for mosaic-web? 😄
j
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
blob joy
h
What about Compose Web Crane? 😄
👌 2
d
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
very interesting, I'll check it out. thanks david!
✌️ 1