Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/devtools/component-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class ComponentTree {
constructor() {
this.tree = {};
this.components = new Map();
this.enabled = process.env.NODE_ENV === 'development';
}

addComponent(name, instance, parent = null) {
if (!this.enabled) return;

const id = `${name}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
const componentData = {
name,
instance,
parent,
id,
refs: instance.$refs || {},
options: instance.$options || {}
};

this.components.set(id, componentData);

if (!parent) {
this.tree[id] = { name, children: [] };
} else {
// Parent er children e add korbo
const parentData = this.components.get(parent);
if (parentData) {
if (!parentData.children) parentData.children = [];
parentData.children.push(componentData);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Redundant Tree Object Causes Inconsistent Data Model

The this.tree object is populated for root components but remains unused throughout the ComponentTree class. The actual component hierarchy, including root and child relationships, is managed and traversed via the this.components Map, making this.tree redundant and creating an inconsistent data model.

Fix in CursorΒ Fix in Web


console.log(`βž• Component added: ${name}`, { id, parent });
return id;
}

removeComponent(id) {
if (!this.enabled) return;

const component = this.components.get(id);
if (component) {
this.components.delete(id);
console.log(`βž– Component removed: ${component.name}`, { id });
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incomplete Component Removal Causes Tree Inconsistency

The removeComponent method only deletes components from the components Map. It doesn't remove root components from this.tree or child components from their parent's children array. This leaves stale references, causing an inconsistent tree state, potential memory leaks, and incorrect tree visualization.

Fix in CursorΒ Fix in Web


logTree() {
if (!this.enabled) return;

console.group('🌳 Component Tree');
this.components.forEach((comp, id) => {
if (!comp.parent) {
this._logComponent(comp, 0);
}
});
console.groupEnd();
}

_logComponent(component, depth = 0) {
const indent = ' '.repeat(depth);
console.log(`${indent}${component.name} (${component.id})`);

if (component.children) {
component.children.forEach(child => {
this._logComponent(child, depth + 1);
});
}
}
}

export default new ComponentTree();