craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

actions.add node bug

Open neove opened this issue 2 years ago • 4 comments

I try to add a UserComponent Node to editor by actions.add then when i select this component to show the edit panel by actions.selectNode, there console an error : image

i try to analysis this error and here is what i find out: the context is null when the code run: image who can help me...

neove avatar Mar 14 '22 11:03 neove

Your user component seems to not be a child of <Editor />. Please make sure that (what I assume to be) your toolbar that contains the UserComponent is also a child of Editor

For example:

+<Editor>
   <Toolbar>
+      <ElementThatCallsActionsAdd />
   </Toolbar>
  <Frame>
    <YourFrameContent />
  </Frame>
</Editor>

ankri avatar Mar 14 '22 14:03 ankri

after a few hours, I finally finger out why when i call actions.add to add a component manully, my related component is not wrapped by NodeProvider, therefor, when i call usenode hooks in the related component, i have an error. so ,i need to wrap my related component by NodeProvider manully like this: image

neove avatar Mar 15 '22 01:03 neove

But in the source code of utils/createNode, the related component is wrapped by NodeProvider image so this is may be a bug of actions.add

neove avatar Mar 15 '22 01:03 neove

Can you please paste the full code for this image and the code where you use the this component. And your code where you use <Editor />.

Please look at my suggestion again an confirm that you creating related.settings only in descendants of <Editor />

ankri avatar Mar 15 '22 06:03 ankri