SimonDanisch / Bonito.jl

Serving JS to the browser
MIT License
204 stars 29 forks source link

Error in `ensure_connection(...)` #245

Open frankier opened 1 month ago

frankier commented 1 month ago

When we try a websocket write, ensure_connection(...) is called, which calls setup_connection() without an argument

https://github.com/SimonDanisch/Bonito.jl/blob/1a6083e84a660cc50e25bcd13349e3106cffcc7f/js_dependencies/Websocket.js#L22

However it looks like the config argument is actually required

https://github.com/SimonDanisch/Bonito.jl/blob/1a6083e84a660cc50e25bcd13349e3106cffcc7f/js_dependencies/Websocket.js#L159

frankier commented 2 days ago

Okay I managed to trigger this like so:

using HTTP
using Bonito: App
using Bonito.DOM
using Makie
#using WGLMakie

function main()
    # start a blocking server
    HTTP.listen() do http::HTTP.Stream
        HTTP.setstatus(http, 200)
        HTTP.startwrite(http)
        if http.message.target == "/fragment"
            app = App() do
                DOM.div("hi!")
            end
            io = IOBuffer()
            show(io, "text/html", app)
            body = take!(io)
            write(http, body)
        else
            write(http, "<html><body>")
            write(http, "<script src=\"https://unpkg.com/htmx.org@2.0.2\"></script>")
            write(http, "<h1>fragment insertion</h1>")
            write(http, "<button hx-get=\"/fragment\" hx-target=\"#results\">Click Me</button>")
            write(http, "<div id=\"results\"></div>")
            write(http, "</body></html>")
        end
    end
end

if abspath(PROGRAM_FILE) == @__FILE__
    main()
end

Related: https://github.com/MakieOrg/Makie.jl/pull/4343#issuecomment-2342745300