Skip to content

SceneDataTransformer promotes annotations: undefined to [] #1612

Description

@gtk-grafana

What happens

SceneDataTransformer.transform() always returns an array for annotations, even when the source had none:

// packages/scenes/src/querying/SceneDataTransformer.ts:348
return { ...data, series, annotations };

annotations is initialised to [] and only receives frames tagged
meta.dataTopic === DataTopic.Annotations, so a panel with no annotations goes from
annotations: undefined (what SceneQueryRunner emits _combineDataLayers only assigns when
_layerAnnotations.length > 0) to annotations: [].

Why it matters

Consumers guard on presence, not length. In Grafana:

  • TimeSeriesPanel.tsx: {data.annotations && <ExemplarsPlugin … />}
  • CandlestickPanel.tsx: same guard

Both now mount ExemplarsPlugin on every panel that has any transformation, with nothing to draw.
ExemplarsPlugin renders EventsCanvas, which registers a uPlot draw hook that bumps React
state on every draw — so pan, zoom and cursor redraws each cost an extra render pass per panel.

This affects any panel with user transformations today.

Suggested fix

annotations: annotations.length > 0 || data.annotations !== undefined ? annotations : undefined,

The data.annotations !== undefined clause is needed: the shorter
annotations.length ? annotations : data.annotations resurrects annotations that an
annotations-topic transformation deliberately removed. This form keeps "transformed to nothing" as
[] and returns undefined only for "never had any".

transform() is the only promotion site: SceneQueryRunner._combineDataLayers already guards.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions