fabricjs / fabric.js

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser
http://fabricjs.com
Other
29.03k stars 3.51k forks source link

[Bug]:f abric: Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas #10136

Open vaynevayne opened 1 month ago

vaynevayne commented 1 month ago

CheckList

Version

6.0.2

In What environments are you experiencing the problem?

No response

Node Version (if applicable)

None

Link To Reproduction

https://stackblitz.com/edit/vitejs-vite-sujben?file=src%2FReactFabric%2Fstore%2Findex.ts,src%2FReactFabric%2FbaseFabric%2FBaseFabric.ts,src%2FReactFabric%2Fcomponents%2FStoreUpdater%2Findex.tsx,src%2FReactFabric%2Fcontainer%2FFabric%2Findex.tsx

Steps To Reproduce

  1. yarn run dev

Expected Behavior

no error

Actual Behavior

error in console

Error Message & Stack Trace

react-dom_client.js?v=7d540ee2:16670 Uncaught c: fabric: Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?
    at wn.createLowerCanvas (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:890:47)
    at new de (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:884:21)
    at new wn (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:3490:5)
    at An.initElements (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:3546:21)
    at new _fe (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:938:86)
    at new _Sn (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:3529:5)
    at new An (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/fabric.js?v=a9b44b02:3838:5)
    at https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/src/ReactFabric/container/Fabric/index.tsx:38:27
    at commitHookEffectListMount (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/react-dom_client.js?v=7d540ee2:16915:34)
    at invokePassiveEffectMountInDEV (https://vitejsvitesujben-v1mp--5173--24eaa195.local-credentialless.webcontainer.io/node_modules/.vite/deps/react-dom_client.js?v=7d540ee2:18324:19)
(anonymous) @   index.tsx:32
Show 17 more frames
vaynevayne commented 1 month ago

My removal problem disappeared. Does strict mode not support?

asturur commented 1 month ago

Are you using React in strict mode? Hooks will run twice be sure to dispose it properly. Imho strict mode does not make sense, i wish there was a way to disable it for portions of the app