Code Monkey home page Code Monkey logo

Comments (6)

tsayen avatar tsayen commented on May 22, 2024

Looks like you're filtering out the node you want to render. Make sure your filter matches that node.

from dom-to-image.

kirilledelman avatar kirilledelman commented on May 22, 2024

It doesn't matter what I'm actually trying to filter out - returning false from filter in any case results in node being undefined later in Promise chain. Maybe I misunderstand how the library is designed - but what I'm trying to do is give it a container with mixed dom objects in it, and filter function would return true or false for those I want included in resulting svg/foreignobject sandwich, and skip all the others.

I "fixed" it by changing this line:
From:
if (filter && !filter(node)) return Promise.resolve();
To:
if (filter && !filter(node)) return Promise.resolve(document.createElement( 'b' ));

Now there's no exception, and it ends up rendering empty/invisible <b/> instead. But it seems to be a deeper problem here - promise.resolve requires node to be defined later.

from dom-to-image.

tsayen avatar tsayen commented on May 22, 2024

Take a look at this test to see how filter should be used. When calling toSvg, you should provide the node you want to render. If your filter does not return true for the node you've provided as first argument, then you'll get this error. Perhaps this situation should be handled better. But if you give right arguments (and make sure that root node passes the filter), your problem should be fixed

from dom-to-image.

kirilledelman avatar kirilledelman commented on May 22, 2024

Now it makes sense! My filter should've included the container node as well as the things I'm filtering in / out.

Thank you for clearing this up.

from dom-to-image.

tsayen avatar tsayen commented on May 22, 2024

welcome :)

from dom-to-image.

tsayen avatar tsayen commented on May 22, 2024

FYI, starting from 2.1.0 this issue is handled better, the filter is no longer applied to the root node.

from dom-to-image.

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.