You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check DOM to find an orphaned canvas element, despite the p5 instance controlling it has been removed.
Snippet:
constsketch=newp5(p=>{p.setup=()=>{p.createCanvas(200,200)console.log('Setup called.')}})console.log(sketch._setupDone,sketch.canvas)console.log(document.querySelector("canvas"))sketch.remove()// added timeout to allow canvas to be appended after the sketch is removedsetTimeout(()=>console.log(document.querySelector("canvas")),1000)
Essentially, when remove is called on p5 instance, it only checks if there is already an existing canvas. If there is, remove it from the DOM. But in the case where the canvas element hasn't been created yet, it simply skips the canvas removal down the line. I am not too familiar with the rendering pipeline, but there could be a flag on pInst that skips further initialization of the DOM element once remove has been called.
It was problematic for me when using p5 with react, when there are rapid initializing and removal of p5 instances where the canvas isn't created in time to be removed from the DOM.
Most appropriate sub-area of p5.js?
p5.js version
1.7.0
Web browser and version
Chrome 114.0.5735.198
Operating System
OS 12.5.1
Steps to reproduce this
Steps:
_setupDone
.canvas
element, despite the p5 instance controlling it has been removed.Snippet:
Essentially, when
remove
is called on p5 instance, it only checks if there is already an existingcanvas
. If there is, remove it from the DOM. But in the case where thecanvas
element hasn't been created yet, it simply skips the canvas removal down the line. I am not too familiar with the rendering pipeline, but there could be a flag onpInst
that skips further initialization of the DOM element onceremove
has been called.It was problematic for me when using p5 with react, when there are rapid initializing and removal of p5 instances where the
canvas
isn't created in time to be removed from the DOM.A codepen replicating the issue:
https://codepen.io/DonaldZhu/pen/LYXMmeJ
The text was updated successfully, but these errors were encountered: