question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not destroy children which are not created by react

See original GitHub issue

Description

Currently, a code to remove a component from a tree looks like this:

  if ((_child$children = child.children) !== null && _child$children !== void 0 && _child$children.length) {

    _toConsumableArray(child.children).forEach(function (c) {
      _removeChild(child, c);
    });
  }

  parent.removeChild(child);
  child.destroy();

It makes an issue with pixi components, which manages children on its own. See issue: https://github.com/pixijs/spine/issues/389

Pixi spine makes children on its own and destroy them in destroy method. Because of it, there is no way to manage component like this in react-pixi, because react-pixi will call destroy for each child and call destroy on the spine component.

I think, there should be a way to manage situation like this.

Steps to reproduce

  1. Make component like this:
export const SpineComponent = PixiComponent<{ data: ISkeletonData }, OrigSpine>('Spine', {
    create: (props) => {
        const s = new Spine(props.data);

        s.state.setAnimation(0, 'idle_1', true);

        return s;
    },
    didMount: (instance, parent) => {
    },
    willUnmount: (instance, parent) => {
    },
    applyProps: (instance, oldProps, newProps) => {
        return true;
    },
});
  1. Use the component
  2. Destroy component from the tree

Additional info

"pixi.js": "6.0.4",
"pixi-spine": "^3.0.3",
"react": "^17.0.2",
"@inlet/react-pixi": "^6.5.2",
"react-dom": "^17.0.2",

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
adskocommented, Jun 14, 2021

@inlet It makes sense to group it in object.

0reactions
inletcommented, Jun 14, 2021

Hopefully this fix helps you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues removing specific children in react js - Stack Overflow
When I try to remove a child changing the state it sets an older state... So instead of deleting 1 item it removes...
Read more >
Reconciliation - React
When tearing down a tree, old DOM nodes are destroyed. Component instances receive componentWillUnmount() . When building up a new tree, new DOM...
Read more >
Portals - React
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. ......
Read more >
Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
Read more >
React.Component
We strongly recommend against creating your own base component classes. ... Note that returning false does not prevent child components from re-rendering ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found