From 41ee210c8e0d29225185ad05aa6227ef01923cda Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Thu, 16 Apr 2020 23:45:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20#87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 2 +- assets/bond.js | 7 ++++--- assets/client.js | 11 ++++------- assets/editor.html | 2 +- assets/editor.js | 7 ++++++- src/webserver/Dynamic.jl | 14 ++++++++------ src/webserver/WebServer.jl | 11 ++++++----- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Project.toml b/Project.toml index 68282d0131..c1e640b6c2 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "Pluto" uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781" license = "MIT" authors = ["Fons van der Plas ", "MikoĊ‚aj Bochenski "] -version = "0.7.3" +version = "0.7.4" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/assets/bond.js b/assets/bond.js index e695fc7128..1e8906c63c 100644 --- a/assets/bond.js +++ b/assets/bond.js @@ -1,14 +1,15 @@ observablehq.Library() function makeBond(bondNode) { + if(bondNode.getRootNode() != document){ + return + } bondNode.generator.next().value.then(val => { - console.log("New val: "+val) window.refreshAllCompletionPromise() window.client.sendreceive("bond_set", { sym: bondNode.getAttribute("def"), val: val, }).then(u => { - // TODO: wait for all cells to finish running, maybe make this an event }) window.allCellsCompletedPromise.then(_ => { makeBond(bondNode) @@ -25,7 +26,7 @@ document.addEventListener("celloutputchanged", (e) => { const bondNodes = cellNode.querySelectorAll("bond") bondNodes.forEach(bondNode => { - bondNode.generator = observablehq.Generators.input(bondNode.firstChild) + bondNode.generator = observablehq.Generators.input(bondNode.firstElementChild) window.allCellsCompletedPromise.then(_ => { makeBond(bondNode) }) diff --git a/assets/client.js b/assets/client.js index ccfb30d794..fccac71685 100644 --- a/assets/client.js +++ b/assets/client.js @@ -36,17 +36,10 @@ class PlutoConnection { }) }, 1000) } - - psocket = null getUniqueShortID() { return crypto.getRandomValues(new Uint32Array(1))[0].toString(36) } - clientID = this.getUniqueShortID() - - sentRequests = {} - - MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi" send(messageType, body, cellUUID = undefined, createPromise=false) { const requestID = this.getUniqueShortID() @@ -187,6 +180,10 @@ class PlutoConnection { this.onDisconnect = onDisconnect this.currentlyConnected = false + this.psocket = null + this.MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi" + this.clientID = this.getUniqueShortID() + this.sentRequests = {} window.addEventListener("unload", e => { this.send("disconnect", {}) diff --git a/assets/editor.html b/assets/editor.html index c03acd26e3..757a3bc069 100644 --- a/assets/editor.html +++ b/assets/editor.html @@ -281,7 +281,7 @@ code { font-family: monospace; - font-size: .75rem; + font-size: .75em; } cell.error>code { diff --git a/assets/editor.js b/assets/editor.js index b7df05bdd2..f80f2e8a43 100644 --- a/assets/editor.js +++ b/assets/editor.js @@ -204,7 +204,12 @@ document.addEventListener("DOMContentLoaded", () => { document.head.appendChild(tag) } } else { - eval(scripts[i].innerHTML) + var result = Function(scripts[i].innerHTML).bind(outputNode)() + if(!scripts[i].previousElementSibling && !scripts[i].nextElementSibling){ + if(result && result.nodeType === Node.ELEMENT_NODE){ + scripts[i].parentElement.insertBefore(result, scripts[i]) + } + } } } } catch (err) { diff --git a/src/webserver/Dynamic.jl b/src/webserver/Dynamic.jl index 4ede1c3f74..33c1fae97b 100644 --- a/src/webserver/Dynamic.jl +++ b/src/webserver/Dynamic.jl @@ -243,12 +243,14 @@ responses[:bond_set] = (body, notebook::Notebook; initiator::Union{Initiator, Mi new_val = body["val"] putnotebookupdates!(notebook, UpdateMessage(:bond_update, body, notebook, nothing, initiator)) - function custom_deletion_hook(notebook::Notebook, to_delete_vars::Set{Symbol}, to_reimport::Set{Expr}; to_run::Array{Cell, 1}) - push!(to_delete_vars, bound_sym) # also delete the bound symbol - WorkspaceManager.delete_vars(notebook, to_delete_vars, to_reimport) - WorkspaceManager.eval_in_workspace(notebook, :($bound_sym = $new_val)) + if !isempty(where_assigned(notebook, Set{Symbol}([bound_sym]))) + function custom_deletion_hook(notebook::Notebook, to_delete_vars::Set{Symbol}, to_reimport::Set{Expr}; to_run::Array{Cell, 1}) + push!(to_delete_vars, bound_sym) # also delete the bound symbol + WorkspaceManager.delete_vars(notebook, to_delete_vars, to_reimport) + WorkspaceManager.eval_in_workspace(notebook, :($bound_sym = $new_val)) + end + to_reeval = where_referenced(notebook, Set{Symbol}([bound_sym])) + run_reactive_async!(notebook, to_reeval; deletion_hook=custom_deletion_hook) end - to_reeval = where_referenced(notebook, Set{Symbol}([bound_sym])) - run_reactive_async!(notebook, to_reeval; deletion_hook=custom_deletion_hook) end \ No newline at end of file diff --git a/src/webserver/WebServer.jl b/src/webserver/WebServer.jl index 15dbd0630a..e72c4a0367 100644 --- a/src/webserver/WebServer.jl +++ b/src/webserver/WebServer.jl @@ -74,12 +74,14 @@ function flushclient(client::Client) write(client.stream, serialize_message(next_to_send)) else @info "Client $(client.id) stream closed." + put!(flushtoken, token) return false end end catch ex bt = stacktrace(catch_backtrace()) @warn "Failed to write to WebSocket of $(client.id) " exception=(ex,bt) + put!(flushtoken, token) return false end put!(flushtoken, token) @@ -109,7 +111,6 @@ end responses = Dict{Symbol,Function}() const MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi" # riddle me this, Julius -const MSG_DELIM_BYTES = codeunits(MSG_DELIM) |> Vector{UInt8} """Start a Pluto server _synchronously_ (i.e. blocking call) on `http://localhost:[port]/`. @@ -131,11 +132,11 @@ function run(port = 1234, launchbrowser = false) try parentbody = let # For some reason, long (>256*512 bytes) WS messages get split up - `readavailable` only gives the first 256*512 - data = UInt8[] - while !endswith(data, MSG_DELIM_BYTES) - push!(data, readavailable(clientstream)...) + data = "" + while !endswith(data, MSG_DELIM) + data = data * String(readavailable(clientstream)) end - JSON.parse(String(view(data, 1:(lastindex(data)-length(MSG_DELIM_BYTES))))) + JSON.parse(SubString(data, 1:(lastindex(data)-length(MSG_DELIM)))) end process_ws_message(parentbody, clientstream) catch ex