Skip to content

Commit 7d111f4

Browse files
authored
fix: prevent failing navigator when instances are inconsistent (#4303)
Users somehow make instances tree inconsistent. For example deleting instances does not delete id from parent children. I still have not idea how to reproduce this but we need to stop failing users with broken state. Here just logged into console instead of throwing error.
1 parent 0f39f7e commit 7d111f4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator-tree.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ const $flatTree = computed(
106106
) => {
107107
const instance = instances.get(instanceId);
108108
if (instance === undefined) {
109-
throw Error("Unknown instance");
109+
// log instead of failing navigator tree
110+
console.error(`Unknown instance ${instanceId}`);
111+
return;
110112
}
111113
const propValues = propValuesByInstanceSelector.get(
112114
JSON.stringify(selector)
@@ -149,7 +151,7 @@ const $flatTree = computed(
149151
const child = instance.children[index];
150152
if (child.type === "id") {
151153
const isLastChild = index === instance.children.length - 1;
152-
lastItem = traverse(
154+
const lastDescendentItem = traverse(
153155
child.value,
154156
[
155157
child.value,
@@ -165,6 +167,9 @@ const $flatTree = computed(
165167
level + 2,
166168
index
167169
);
170+
if (lastDescendentItem) {
171+
lastItem = lastDescendentItem;
172+
}
168173
}
169174
}
170175
});
@@ -174,7 +179,7 @@ const $flatTree = computed(
174179
const child = instance.children[index];
175180
if (child.type === "id") {
176181
const isLastChild = index === instance.children.length - 1;
177-
lastItem = traverse(
182+
const lastDescendentItem = traverse(
178183
child.value,
179184
[child.value, ...selector],
180185
isHidden,
@@ -183,6 +188,9 @@ const $flatTree = computed(
183188
level + 1,
184189
index
185190
);
191+
if (lastDescendentItem) {
192+
lastItem = lastDescendentItem;
193+
}
186194
}
187195
}
188196
}

0 commit comments

Comments
 (0)