Coder Social home page Coder Social logo

Comments (2)

bcakmakoglu avatar bcakmakoglu commented on June 27, 2024

Thanks for the report.
Alas, because of the way the v-models (elements, nodes and edges) are setup at the moment I expect that this issue will persist for the remainder of VueFlow 1.

I will address this problem with the next major update - for now you can use onPaneReady if you need to add some nodes after the initial ones, though be aware that fit-view-on-init will not play nicely with this and won't consider nodes that have been added after that. You can always call fitView yourself though, so that's not a big problem :)

A little bit of background on why this happens:
Currently when elements are passed to VueFlow they are "transformed" from Node -> GraphNode / Edge -> GraphEdge, adding some additional pieces of info to these elements that are necessary for VueFlow to work correctly.

To allow for direct mutation of these objects like node.position.x = 100 without having to pass a new array of elements, the transformed elements are pushed into your model ref.
So basically what happens is this

  1. You pass VueFlow your elements ref
  2. The elements get transformed
  3. Transformed elements overwrite your elements ref value
    To avoid having infinite loops happening while this is done, a pausable watcher is used that waits until your elements ref is overwritten to continue watching for changes.
    When you do elements.value.push(...) during onMounted it ends up happening during the pause of this watcher so the new element is never noticed and consumed by VueFlow :/

What does work is onMounted(() => setTimeout(() => {}, 0)) but obviously this isn't a great pattern to use.

In the next major version I'll see that this binding is solved differently since the current implementation has been giving me headaches for too long but re-doing it would be a breaking change since the whole "transformation" needs to stop and be replaced with an internal map that contains these additional pieces of information that VueFlow needs.

Anyway - sorry that I can't give you a better solution at this point in time.
I'll keep this issue open though.

from vue-flow.

DavidPfl avatar DavidPfl commented on June 27, 2024

@bcakmakoglu Thanks a lot for the detailed explanation and the workarounds.

from vue-flow.

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.