Giter VIP home page Giter VIP logo

Comments (5)

MatthewHerbst avatar MatthewHerbst commented on August 20, 2024

Hey, thanks for reporting in! Since the error is "uncaught" that indicates nothing is handling/catching it, which is definitely not great! We have a canvas as part of our examples and that seems to work, but it's very possible we need to do more to ensure everything has loaded.

Would it be possible for you to share a reproducible example on Codesandbox or some other tool so that I can debug this properly?

from react-to-print.

brycenaddison avatar brycenaddison commented on August 20, 2024

@MatthewHerbst Looks like it has something to do with delayed/asynchronous loading of canvases: https://codesandbox.io/p/sandbox/react-to-print-uncaught-error-83fksn

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on August 20, 2024

Thanks for the link! Will look to get a fix in this weekend!

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on August 20, 2024

Finally got a chance to play with this more. Seems that you resolve the onBeforeGetContent promise before the setState in LineChart completes. You're also not waiting for the setLoadCharts call to complete. Regardless, the reason this crashes with canvas elements in particular is that we have to do some special handling of canvas elements. Unlike all other elements, instead of loading the canvas elements from our internal clone of the content, we instead read them directly off the content. This is because cloneNode doesn't properly copy canvas elements which is explicitly called out.

Anyways, you can easily solve this in your code by properly waiting for the setLoadCharts call and ensuring the LineChart state effects have actually happened (or, just remove the useEffect+useState and render them directly...)

I will be adding a check in with a log message that will ensure we don't hard crash here, and will hopefully help folks determine the issue faster.

Thanks again for reporting this, very interesting and got me into the weeds on some core HTML functions (cloneNode vs importNode)

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on August 20, 2024

Here is a forked version of your sandbox showing how to do it: https://codesandbox.io/p/sandbox/react-to-print-uncaught-error-forked-7l7rpk?file=%2Fsrc%2FApp.tsx%3A11%2C11

from react-to-print.

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.