fix(goview): preserve wrapper geometry when unwrapping

This commit is contained in:
clawdbot 2026-01-28 10:19:49 +08:00
parent 903b0da44a
commit a10a5eb661

View File

@ -63,22 +63,36 @@ export interface GoViewProjectLike {
} }
function unwrapComponent(c: GoViewComponentLike): GoViewComponentLike { function unwrapComponent(c: GoViewComponentLike): GoViewComponentLike {
// Prefer nested component shapes but keep outer fields as fallback. // Prefer nested component shapes but keep outer geometry/id as fallback.
// Some exports wrap components multiple times like: // Some exports wrap components multiple times like:
// { id, attr, component: { component: { chartConfig, option } } } // { id, attr, component: { component: { chartConfig, option } } }
// We unwrap iteratively to avoid recursion pitfalls. // We unwrap iteratively to avoid recursion pitfalls.
//
// Important: do NOT let `undefined` values from inner layers overwrite outer values.
// Some goView exports include wrapper objects where `id/attr` only exist on the outer layer.
let out: GoViewComponentLike = c; let out: GoViewComponentLike = c;
let depth = 0; let depth = 0;
while (out.component && depth < 6) { while (out.component && depth < 6) {
const outer = out;
const inner = out.component; const inner = out.component;
out = { out = {
// Prefer outer for geometry/id, but prefer inner for identity/option when present. // Outer (wrapper) often contains the stable identity/geometry.
...out, id: outer.id ?? inner.id,
...inner, attr: outer.attr ?? inner.attr,
status: outer.status ?? inner.status,
// Inner tends to carry the real widget identity/config.
key: inner.key ?? outer.key,
componentKey: inner.componentKey ?? outer.componentKey,
chartConfig: inner.chartConfig ?? outer.chartConfig,
option: inner.option ?? outer.option,
// keep unwrapping if there are more layers // keep unwrapping if there are more layers
component: inner.component, component: inner.component,
}; };
depth++; depth++;
} }