raquo / Waypoint

Efficient router for Laminar UI Library
MIT License
92 stars 11 forks source link

SplitRender.signal should be a lazy val, not def #18

Open raquo opened 3 months ago

raquo commented 3 months ago

Example problem from Discord:

    def compPage = compilePage
    val splitter = SplitRender[ToolPage, ToolPageComponents](pageSignal)
        .collectStatic(CompilePage)(compPage)
        div(className := "bottom-grid",
            div(Container,
                div(ContainerTitle,
                    h2("Compiler Input"),
                    child <-- splitter.signal.map(_.submitButton),
                ),
                child <-- splitter.signal.map(_.editor),
            ),
            child <-- splitter.signal.map(_.results),
        )

Because splitter.signal is used three times, and it's a def in Waypoint, that creates three new signals, each of which evaluates compPage by-name separately, resulting in three evaluations per pageSignal event instead of one. This breaks the general shared-execution expectation that is core to Airstream.

Fix will be included in the next release.

Workaround for such cases is to save splitter.signal into a val instead of just splitter.