Giter VIP home page Giter VIP logo

Comments (7)

StephenHaney avatar StephenHaney commented on June 9, 2024 1

I think it's expected behavior of react error boundaries that they won't catch errors in async code – my understanding is that the error needs to happen in the React tree's render stack to catch it.

Here's a repro (I deleted random info in the GLB file to simulate a bad network request)
https://codesandbox.io/p/sandbox/dazzling-lederberg-8dhfcv

You'll see that even though there's an error boundary, the error thrown by useGLTF is causing the entire app to crash.

Seems odd that I'd be the first person to find this so I could definitely be missing something... although you might only notice
if you're paying careful attention within large amounts of traffic.

from react-three-fiber.

CodyJasonBennett avatar CodyJasonBennett commented on June 9, 2024 1

Okay, we're probably not catching errors thrown from promises. We don't intend for this tricky behavior to be possible.

from react-three-fiber.

StephenHaney avatar StephenHaney commented on June 9, 2024

Here is my workaround code for now in case it is helpful for folks.

Note: this isn't idiomatic React and probably causes other problems in some situations.

export const BambooBox = () => {
  try {
    const { nodes, materials } = useGLTF(path);

    return (
        <mesh
          geometry={nodes.Cylinder.geometry}
          material={materials.Bamboo}
        />
    );
  } catch (err) {
    return <Fallback />;
  }
};

from react-three-fiber.

CodyJasonBennett avatar CodyJasonBennett commented on June 9, 2024

I'd need to see an example, but this sounds like a React bug which should be taken upstream. You can harden your workaround by continuing to throw a promise if passed to err so Suspense works as expected.

from react-three-fiber.

StephenHaney avatar StephenHaney commented on June 9, 2024

The way it happened in the wild was a valid URL but a network error on Poki (so not a 404 but not the full file returned either) happening once every thousand users or so.

from react-three-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.