You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GoJS状态持久化故障:切换楼层后无法创建新图

Troubleshooting GoJS Floorplan State Leak When Switching Floors

Let me walk through how to fix this lingering state issue with your Floorplan component using GoJS. It sounds like your fp.clear() call isn’t fully wiping the underlying GoJS diagram state, leaving old data in the JSON that’s breaking new map creation—and since this worked before, we can focus on pinpointing what changed or was missed in your cleanup flow.

Common Causes & Step-by-Step Fixes

1. Ensure clear() resets the GoJS Model, not just the diagram view

GoJS stores all graph data in its Model (usually go.GraphLinksModel or go.TreeModel). If your clear() method only removes nodes/links from the visual diagram but doesn’t reset the model, old data will stay in the JSON.

Update your clear() implementation to fully reset the model:

class Floorplan {
  private diagram: go.Diagram;

  clear(): void {
    // Wipe visual elements first
    this.diagram.clear();
    // Reset the model to a brand new empty instance
    this.diagram.model = new go.GraphLinksModel(); // Use your model type here
    // Clear any local cached state in your Floorplan class too
    this.currentFloorData = null; // If you store floor-specific data
  }
}

2. Eliminate lingering references to old model data

Even after resetting the model, if your code holds onto references to old node/link data or model objects, GoJS might retain them accidentally. Make sure:

  • You’re not storing references to model.nodeDataArray or model.linkDataArray in parent components or your Floorplan class
  • When loading new floor data, you’re passing a completely fresh object (not modifying an old, reused data structure)

3. Reset custom templates/layouts if needed

If your Floorplan uses custom node templates, layouts, or event listeners, switching floors might require resetting these to defaults. Temporary overrides for the previous floor could be causing conflicts:

clear(): void {
  this.diagram.clear();
  this.diagram.model = new go.GraphLinksModel();
  // Reset to your default node template
  this.diagram.nodeTemplate = this.getBaseNodeTemplate();
  // Reset layout to its default configuration
  this.diagram.layout = new go.GridLayout(); // Or your standard layout
}

4. Debug the model state before loading new data

To confirm if old data is actually stuck in the model, add a debug log right before loading the new floor:

// Right before initializing new floor content
console.log("Pre-reset model data:", this.diagram.model.toJson());

If this logs old floor data, double-check that fp.clear() is being called before loading new data—sometimes event handlers can fail silently or run out of order.

5. Check for recent GoJS version changes

Since this worked previously and broke recently, did you update GoJS? New versions might have breaking changes to model reset or diagram clearing behavior. Try rolling back to the last working version temporarily to rule out a library update issue.


If none of these resolve the problem, sharing a snippet of how your Floorplan class implements clear() and how you load new floor data would help narrow things down further.

内容的提问来源于stack exchange,提问作者Shreya Shahi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:54:32