Skip to content

Text widget: Anchor id is dropped by all non-heading variants (breaks #fragment scroll) #4623

Description

@dcrjodle

Summary

Text.Block(...).Anchor("foo") (and any non-heading Text variant with an anchor) renders no id on the DOM element, so document.getElementById("foo") returns null and anchor/#fragment scrolling silently does nothing.

Root cause

In src/frontend/src/widgets/primitives/TextBlockWidget.tsx, the anchor prop is passed to the variant component as id={anchor} (line ~238), but only the H1H6 variants actually destructure and apply id. All 14 other variants — Literal, Block, P, Inline, Blockquote, Monospaced, Lead, Muted, Danger, Warning, Success, Label, Strong, Display — have the signature ({ children, className, style }) => ... and never render the id.

So for non-heading variants the id is dropped on the floor.

Impact / repro

In Ivy-Tendril's Review → Changes tab (ChangesTabView.cs), each file diff is preceded by Text.Block("").Anchor(path) and the file tree calls client.Redirect($"#{path}") on select. Because the Block variant drops the id:

  1. Redirect("#<path>") → frontend extractAnchorIddocument.getElementById("<path>")null
  2. scrollIntoView is never called → clicking a file in the tree does not scroll to its diff.

(That code path predates the recent mobile-dropdown work; this is not a regression from PR #1294.)

Suggested fix

Make every variant honor the id it's already being given (the VariantMap type already declares id?: string). Either:

  • thread id into each variant's rendered element, or
  • wrap the rendered component in an anchor element that carries the id when anchor is set (headings already self-apply id, so avoid emitting a duplicate for those).

Affected file

  • src/frontend/src/widgets/primitives/TextBlockWidget.tsx

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions