saket

    saket

    9 months ago
    can compose-web export html that can be hosted directly?
    hfhbd

    hfhbd

    9 months ago
    Sure, not html, but JS. Compose for Web "just" uses plain Kotlin/JS, which creates a normal js executable (or library, if wanted).
    saket

    saket

    9 months ago
    would you know why html is unsupported? I was wondering if I could generate static htmls
    c

    Casey Brooks

    9 months ago
    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
    hfhbd

    hfhbd

    9 months ago
    Static HTML does not support dynamic changes (does not matter if Compose or React etc).
    saket

    saket

    9 months ago
    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

    9 months ago
    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
    saket

    saket

    9 months ago
    I think I understand the challenges now. thanks for explaining!
    hfhbd

    hfhbd

    9 months ago
    You can always take a snapshot of the current DOM and print it to a html file.
    saket

    saket

    9 months ago
    ooh, is that something that can be automated without opening a browser?
    c

    Casey Brooks

    9 months ago
    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
    saket

    saket

    9 months ago
    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

    9 months ago
    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

    9 months ago
    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.
    saket

    saket

    9 months ago
    jake is it time for mosaic-web? 😄
    j

    jw

    9 months ago
    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.
    saket

    saket

    9 months ago
    :blob-joy:
    hfhbd

    hfhbd

    9 months ago
    What about Compose Web Crane? 😄
    David Herman

    David Herman

    9 months ago
    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.
    saket

    saket

    9 months ago
    very interesting, I'll check it out. thanks david!