hyperfiddle

braai engineer 2026-04-03T12:34:46.041409Z

Is there an elegant way to batch render N items where N is large without virtual scroll, so that pages of e.g. 20 items are transferred to client as soon as possible, ideally over lazy collections? E.g. given a nested tree of nodes, where some levels have N sub-nodes where N is large, this delays initial render while waiting for transfer to client, so I want to paginate it into batches of 10 so initial render is faster. I guess I can do (let [pages (partition-all 10 xs)] ...) and then (e/for [page pages] (e/for [item page] ...)) over the pages, or will this still wait for everything to be available instead of "rendering from the top" soon as available? This is different from virtual scroll, because I want all the nodes, I just want faster initial rendering of N results, without re-diffing as more results arrive. And I don't want to resort to virtual scroll because I find it's too easy for my dumbass to break it.

braai engineer 2026-04-03T12:52:42.893989Z

This renders but doesn't feel faster, like it's waiting for all the pages before it starts streaming and rendering on client, where child-pages is coll of [page-idx page], and page is list of ids:

(e/server
  (e/for-by first [[idx page] child-pages] ; identity slow here page large
    (e/client                             ; note e/client so page transfers
      (e/for-by identity [child-eid page]
        (Node child-eid opts)))))

braai engineer 2026-04-03T13:06:43.920469Z

I also tried (let [first-page remainder] (split-at 10 xs)] ...) and render the first page, and remainder, but Electric seems to wait for it all to be available. This seems to force the batching:

(case (e/server
        (e/for-by identity [child-eid first-page]
          (e/client                 ; note e/client so that first-page transfers
            (Node child-eid opts)))
        true)
  (e/server
    (e/for-by identity [child-eid remainder]
      (e/client                     ; note e/client so page transfers
        (Node child-eid opts)))))