zed-industries/zed · error

shared scroll anchor references a non native display map, bu

Error message

shared scroll anchor references a non native display map, but the snapshot has no companion

What it means

The same shared-anchor invariant, hit from native_anchor: converting the stored ScrollAnchor to one pointing at the provided snapshot's native multibuffer requires the snapshot's companion when the anchor was written by the other (non-native) side of a split diff. The expect fires when the recorded display_map_id names a non-native map but the given snapshot carries no companion multibuffer — the two sides' display maps are no longer paired, making the lossy translation impossible.

Source

Thrown at crates/editor/src/scroll.rs:242

        }
        offset
    }

    /// Get a ScrollAnchor whose `anchor` field is guaranteed to point into the multibuffer for the provided snapshot.
    ///
    /// For normal editors, this just retrieves the internal ScrollAnchor and is lossless. When the editor is part of a split diff,
    /// we may need to translate the anchor to point to the "native" multibuffer first. That translation is lossy,
    /// so this method should be used sparingly---if you just need a scroll position or display point, call the appropriate helper method instead,
    /// since they can losslessly handle the case where the ScrollAnchor was last set from the other side.
    pub fn native_anchor(&self, snapshot: &DisplaySnapshot, cx: &App) -> ScrollAnchor {
        let shared = self.anchor.read(cx);

        let mut result = if let Some(display_map_id) = shared.display_map_id
            && display_map_id != snapshot.display_map_id
        {
            let companion_snapshot = snapshot
                .companion_snapshot()
                .expect("shared scroll anchor references a non native display map, but the snapshot has no companion");
            assert_eq!(
                companion_snapshot.display_map_id, display_map_id,
                "shared scroll anchor display map should match the companion used for native anchor conversion"
            );

            let mut display_point = shared
                .scroll_anchor
                .anchor
                .to_display_point(companion_snapshot);
            *display_point.column_mut() = 0;
            let buffer_point = snapshot.display_point_to_point(display_point, Bias::Left);
            let anchor = snapshot.buffer_snapshot().anchor_before(buffer_point);
            ScrollAnchor {
                anchor,
                offset: shared.scroll_anchor.offset,
            }
        } else {
            shared.scroll_anchor

View on GitHub (pinned to f4178619ac)

Solutions

  1. Return the raw anchor unchanged when the companion needed for translation is missing, documenting that the result may be approximate
  2. Invalidate/reset the SharedScrollAnchor whenever a diff side's display map is recreated without a companion
  3. Track companion availability alongside display_map_id so mismatches are detectable before translation
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/editor/src/scroll.rs:242 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/576f1c0a0fd98acb. Report an issue: GitHub.