Skip to content

finding(plugin-dashboard): DashboardRenderer's self-contained branch carries a DatasetWidget fork that cannot be reached #4620

Description

@yinlianghui

Observation-class finding, noticed while implementing #4614 (mirroring this exact fork onto DashboardGridLayout). Dormant code, no user-visible symptom today — filed so the next person to mirror this shape does not copy the dead limb. Duplicate-searched (keyword + DashboardRenderer path): nothing open covers it.

The observation

DashboardRenderer.tsx decides the self-contained (card-less) rendering with:

const isSelfContained = widget.type === 'metric' && !datasetBound;   // :782

and then, inside the isSelfContained arm of renderedNode, forks on datasetBound again:

{datasetBound                                                        // :820-822
  ? < div … >< DatasetWidget widget={effectiveWidget} dataSource={dataSource} / >< /div >
  : < SchemaRenderer schema={componentSchema} … / >}

isSelfContained already requires !datasetBound, so the datasetBound arm at :821 is unreachable. The reachable fork is the one in the Card branch (:849-851).

Why it is harmless today, and why it is still worth recording

Nothing renders wrongly — the unreachable arm simply never runs, and the reachable fork is correct. The cost is to readers: :777-781's comment explains that a dataset-bound metric must take the Card wrapper precisely so DatasetWidget gets title + border chrome, which is the same fact that makes :821 dead. The shape reads as "both branches handle dataset-bound widgets" when only one can.

It most likely became dead rather than being born dead: isSelfContained gaining its && !datasetBound clause is what stranded the arm that was written when the condition was just widget.type === 'metric'.

Where it already cost something

PR #4619 (#4614) mirrors this fork onto DashboardGridLayout. Deciding whether to copy the second arm took a reachability argument that the sibling's shape actively suggests against; that PR mirrors only the reachable mechanics and states why in a code comment. Anyone mirroring this to a third surface pays the same toll.

Suggested disposition (not prescriptive)

Delete the unreachable arm at :820-822, leaving the self-contained branch rendering SchemaRenderer unconditionally — with a one-line comment naming the invariant (isSelfContained implies !datasetBound) so it does not get re-added. A test is not obviously needed for removing code that cannot execute; the existing dataset-bound-metric coverage already pins that such a widget takes the Card path.

Not fixed in #4619: out of that card's scope, which is DashboardGridLayout's missing dataset path.


Generated by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions