Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current canvas out of sync after page reload #322

Open
gagern opened this issue Feb 19, 2023 · 0 comments
Open

current canvas out of sync after page reload #322

gagern opened this issue Feb 19, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@gagern
Copy link

gagern commented Feb 19, 2023

While debugging some other issue, I've encountered an exception in CanvasManagerModel.processCommand caused by this.currentCanvas being undefined.

Steps to reproduce:

  1. Start new notebook.
  2. Enter and run cell from ipycanvas import Canvas, hold_canvas
  3. Enter and run cell canvas = Canvas(width=100, height=100)
  4. Enter and run cell canvas.fill_rect(10, 10, 20, 20)
  5. Re-load browser window
  6. Optional: Enable pause on exception in developer tools
  7. Re-execute the last cell

Expected behavior:
Command executed cleanly, or a reasonably understandable exception raised in Python code and surfaced in the UI.

Actual behavior:
Error thrown: Cannot read properties of undefined (reading 'fillRect')

Hypothesis:

I believe this is most likely due to a mismatch of state. The Python _CanvasManager._current_canvas refers to the last used canvas, but on page reload the JavaScript CanvasManagerModel gets re-created and there is no machinery in place (as far as I can tell) to sync the current canvas between the two.

Potential solutions:

  • Have the CanvasManagerModel widget constructor signal its Python counterpart to invalidate its _current_canvas_ state. That way the next draw operation would sync state again.
  • Use some IPyWidgets machinery to sync the current canvas state from Python to JavaScript upon widget recreation.

I don't know enough about IPyWidgets to judge which of these approaches to prefer, or how the latter would look in more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants