Skip to content

v0.20.0

Latest
Compare
Choose a tag to compare
@bitspittle bitspittle released this 29 Nov 16:52

This release is nearly identical to 0.19.3 (with minor changes discussed below) but enables support for Kotlin 2.1.0.

kobweb = "0.20.0"
kotlin = "2.1.0"

Important

Planning to upgrade? Review instructions in the README.


Changes

  • Refactored code behind the scenes resulting in a Compose optimization that reduces site output size by a modest 2-3%
  • Canvas widgets now detect if their lambda block changes upon subsequent recompositions.
    • See notes.

Notes

Canvas lambdas

When I first wrote the canvas widget, I basically expected the render callback passed into it itself to never change over time.

For example, refer to this clock rendering demo. Obviously, each time the render call happens, you'll get a new result (as it is based on the current time), but the callback logic itself is unchanging and self contained.

However, if you wrote a lambda that, for example, captured some values, then that lambda will be recreated each time the method is recomposed. Here, this lambda will be regenerated for each time a new cursor position is passed into the parent function:

fun CanvasWithCursor(cursorX: Int, cursorY: Int) {
   val cursor: CanvasImageSource = remember { initializeCursor() }

   Canvas2d(/*... params ...*/) {
      // canvas lambda captures cursorX and cursorY
      ctx.drawImage(cursor, cursorX.toDouble(), cursorY.toDouble())
   }
}

Previously, the Canvas2d internally remembered the first lambda that was passed in and ignored all subsequent changes.

This is not an issue that perhaps 99.9% of Kobweb users would ever run into -- especially given that this bug has been present for almost three years at this point and was just recently reported -- but I didn't know how else to explain this feature without describing it in this much detail!


Thanks

Thanks to @DennisTsar for doing the early legwork on investigating 2.1.0, including a way to get past a roadblock that would have otherwise significantly delayed the release, as well as for identifying the refactoring that would cut our site size down.


Full Changelog: v0.19.3...v0.20.0