Skip to content

[BUG] Workflow lines fail to render after fromJSON() when meta.size equals wrapperStyle dimensions #1070

Description

@kerwin612

🙋 SDK Version

@flowgram.ai/free-layout-core: 0.1.8

📌 Layout

Free layout

💻 Environment

  • Operation System: Linux 5.15 (WSL)
  • Node.js: (Please fill in your version)
  • Other: flowgram.ai repository

📝 Question Description

Bug Summary

When loading initial data using fromJSON(), lines connecting nodes fail to render if the node's meta.size and wrapperStyle have the same width/height values. This bug only occurs during initial data loading; drag-and-drop and manual connections work correctly.

Steps to Reproduce

  1. Create a custom node with meta.size and wrapperStyle having the same width/height values:
meta: {
  size: {
    width: 80,
    height: 80,
  },
  wrapperStyle: {
    width: '80px',
    height: '80px',
    // ... other styles
  },
}
  1. Load initial data with nodes connected by edges:
{
  "nodes": [
    { "id": "start", "type": "custom-start", "meta": { "position": { "x": 40, "y": 0 } } },
    { "id": "variable", "type": "custom-variable", "meta": { "position": { "x": 220, "y": 0 } } },
    { "id": "end", "type": "custom-end", "meta": { "position": { "x": 400, "y": 0 } } }
  ],
  "edges": [
    { "sourceNodeID": "start", "targetNodeID": "variable" },
    { "sourceNodeID": "variable", "targetNodeID": "end" }
  ]
}
  1. Call document.fromJSON(initialData) to load the data
  2. Observe that the lines connecting the nodes are not rendered

Workarounds (Not Recommended)

The bug can be temporarily avoided by:

  1. Removing meta.size from the node definition, OR
  2. Removing wrapperStyle.width/height from the node definition, OR
  3. Making the width/height values different between meta.size and wrapperStyle

Temporary Workaround (Not Recommended)

The following workaround works but is not a proper solution:

// In workflow-line-render-data.ts update method
public update(): void {
  this.syncContributions();
  // const oldVersion = this.data.version;
  this.updatePosition();
  // const newVersion = this.data.version;
  // if (oldVersion === newVersion) {
  //   return;  // Early return prevents update
  // }
  // this.data.version = newVersion;
  this.currentLine?.update({
    fromPos: this.data.position.from,
    toPos: this.data.position.to,
  });
}
// In workflow-document.ts fromJSON method
setTimeout(() => {
  this.linesManager.forceUpdate();
}, 100);

Additional Notes

  • This bug only affects initial data loading via fromJSON()
  • Drag-and-drop and manual connections work correctly because the DOM is already rendered when lines are created
  • The issue is related to the timing of DOM rendering vs. line position calculation

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions