Giter VIP home page Giter VIP logo

Comments (6)

zenblender avatar zenblender commented on August 22, 2024

Hey @michalochman just wondering if you had a chance to look at this. I've not been able to upgrade to 1.0.0 and I think it is because of issues similar to this one. Thanks!

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024

Hi @zenblender, I had a brief look, but it was not obvious why it is happening. I have yet to dedicate more time to it, but since the example is contrived I didn't make it a priority.

Is this also happening for you in realistic scenarios?

from react-pixi-fiber.

zenblender avatar zenblender commented on August 22, 2024

I'm not totally sure @michalochman. I was actually trying to replicate a real issue I'm having with 1.0.0 beta from my full application (a game), simplified to demonstrate just that problem. In doing so, I ran across this scenario. I typically don't use state in my app, and instead use Redux and useSelector to drive the rendering of components. Whether or not the codesandbox demonstrates the exact issue I'm having, or is the only issue I'm having, it does seem like there's a problem considering it throws an error sometimes and the stable version doesn't throw any errors. Thanks!

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024

@zenblender I found that in your example we're sometimes dealing with PIXI.DisplayObjects that are destroyed, you can easily confirm it by checking containerRef.current?._destroyed in your example.

However, the root issue is not a race condition in react-pixi-fiber, but rather in your containerRefFn that you pass to <Container ref={containerRefFn} />.

That function receives null when the container is unmounted, yet your code ignores this fact right at the start of the ref callback:

export const Animation: FC = () => {
  const containerRef = useRef<PIXI.Container>()
  const containerRefFn = useCallback((container) => {
    if (!container) {
      return
    }
    containerRef.current = container
  }, [])

  // ...

  return <Container ref={containerRefFn} />
}

then later your code is still using containerRef.current even though it should not as it is already destroyed and unmounted.

Essentially, it should rather look like this:

export const Animation: FC = () => {
  const containerRef = useRef<PIXI.Container>()
  const containerRefFn = useCallback((container) => {
    containerRef.current = container
  }, [])

  // ...

  return <Container ref={containerRefFn} />
}

And then, since your not doing anything else in your callback ref, why won't event simplify it more by just passing containerRef directly as ref in <Container ref={containerRef} />?

from react-pixi-fiber.

zenblender avatar zenblender commented on August 22, 2024

Thanks for taking a thorough look. I see what you're saying. I was curious as to why the stable version doesn't throw any errors, but I see that in any case, there's an issue with the logic on my end.

I will try to find time for another attempt to identify issues preventing me from upgrading to 1.0.0. Until then, I am blocked from doing some dependency upgrades.

Thanks again for your time!

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024

I am not 100% certain but, this might be related to changes to react-reconciler or even react, not necessarily to changes to react-pixi-fiber. I would check if it was not time consuming to upgrade all the dependencies of current "stable" branch.

from react-pixi-fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.