Giter VIP home page Giter VIP logo

Comments (7)

josevalim avatar josevalim commented on July 30, 2024

animate already keeps a frame for you, so I wonder if the issue is being caused by rendering the same frame twice. Try this instead:

button = Kino.Control.button("Click") |> Kino.render()
items = [[a: "a", b: "b"], [a: "c",b: "d"]]

Kino.animate(button, 0, fn _event, counter ->
  new_counter = counter + 1
  current = Enum.at(items, counter)

  inputs = [
    example_a: Kino.Input.text("Example a: ", default: "#{current[:a]}"),
    example_b: Kino.Input.text("Example b: ", default: "#{current[:b]}")
  ]
  form = Kino.Control.form(inputs, submit: "Send")
  {:cont, form, new_counter}
end)

from kino.

clayscode avatar clayscode commented on July 30, 2024

animate already keeps a frame for you, so I wonder if the issue is being caused by rendering the same frame twice. Try this instead:

button = Kino.Control.button("Click") |> Kino.render()
items = [[a: "a", b: "b"], [a: "c",b: "d"]]

Kino.animate(button, 0, fn _event, counter ->
  new_counter = counter + 1
  current = Enum.at(items, counter)

  inputs = [
    example_a: Kino.Input.text("Example a: ", default: "#{current[:a]}"),
    example_b: Kino.Input.text("Example b: ", default: "#{current[:b]}")
  ]
  form = Kino.Control.form(inputs, submit: "Send")
  {:cont, form, new_counter}
end)

Still have the same issue with this code

Edit: Just to confirm it's not an issue with my browser, I switched from Firefox to Chrome, but still run into the same problem.

from kino.

jannikbecher avatar jannikbecher commented on July 30, 2024

I think there is a race condition happening in

kino/lib/kino/frame.ex

Lines 172 to 177 in f961f8d

def handle_call({:render, term, destination}, _from, state) do
output = Kino.Render.to_livebook(term)
put_update(destination, state.ref, [output], :replace)
state = update_outputs(state, destination, fn _ -> [output] end)
{:reply, :ok, state}
end

When putting an inspect after output

 def handle_call({:render, term, destination}, _from, state) do 
   output = Kino.Render.to_livebook(term) |> IO.inspect()
   put_update(destination, state.ref, [output], :replace) 
   state = update_outputs(state, destination, fn _ -> [output] end) 
   {:reply, :ok, state} 
 end 

it magically works :-D
Couldn't figure out the details yet.

Here is a simple way to reproduce the error:

frame = Kino.Frame.new()
Kino.Frame.render(frame, Kino.Input.text("Test"))

from kino.

clayscode avatar clayscode commented on July 30, 2024
button = Kino.Control.button("Click") |> Kino.render()
items = [[a: "a", b: "b"], [a: "c",b: "d"]]

Kino.animate(button, 0, fn _event, counter ->
  new_counter = counter + 1
  current = Enum.at(items, counter)

  inputs = [
    example_a: Kino.Input.text("Example a: ", default: "#{current[:a]}"),
    example_b: Kino.Input.text("Example b: ", default: "#{current[:b]}")
  ]
  form = Kino.Control.form(inputs, submit: "Send")
  {:cont, form, new_counter}
end)

In the latest Livebook nightly build, this example doesn't even work - the whole session crashes 😅

from kino.

clayscode avatar clayscode commented on July 30, 2024

I think there is a race condition happening in

kino/lib/kino/frame.ex

Lines 172 to 177 in f961f8d

def handle_call({:render, term, destination}, _from, state) do
output = Kino.Render.to_livebook(term)
put_update(destination, state.ref, [output], :replace)
state = update_outputs(state, destination, fn _ -> [output] end)
{:reply, :ok, state}
end

When putting an inspect after output

 def handle_call({:render, term, destination}, _from, state) do 
   output = Kino.Render.to_livebook(term) |> IO.inspect()
   put_update(destination, state.ref, [output], :replace) 
   state = update_outputs(state, destination, fn _ -> [output] end) 
   {:reply, :ok, state} 
 end 

it magically works :-D Couldn't figure out the details yet.

Here is a simple way to reproduce the error:

frame = Kino.Frame.new()
Kino.Frame.render(frame, Kino.Input.text("Test"))

I can't replicate my issue with this code - this seems to render correctly. I checked out the .10 branch of both Livebook and Kino and changed it to output = Kino.Render.to_livebook(term) |> IO.inspect() but that doesn't seem to resolve the issue with Kino.animate

from kino.

jannikbecher avatar jannikbecher commented on July 30, 2024

@clayscode I pushed a fix to livebook main. Not sure if its the correct way to tackle the issue, but it works on my side.
Lets see what @jonatanklosko thinks :)

from kino.

clayscode avatar clayscode commented on July 30, 2024

@jannikbecher your PR seems to fix my issue, awesome!

from kino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.