Skip to content

ui: Img caller src attribute overrides getter-backed src on initial render #250

Description

@linkdata

Summary

Img.JawsRender emits caller-supplied attributes before its canonical getter-derived src. HTML parsing keeps the first duplicate attribute, so a supported template.HTMLAttr parameter controls the initial image instead of the documented getter.

This silently violates the Img contract until a later JawsUpdate replaces the DOM attribute.

Public reproduction

err := rw.Img(
	"getter.png",
	template.HTMLAttr(`src="caller.png"`),
)

Current markup is equivalent to:

<img id="Jid.1" src="caller.png" src="getter.png">

The browser retains src="caller.png"; expected is getter.png.

This is supported API use: Img and NewImg document that src comes from the getter, while the ui parameter contract accepts raw template.HTMLAttr values and does not reserve src.

Root cause

lib/ui/img.go appends elem.ApplyParams(params) and getter attributes before appending the canonical srcAttr. Browsers retain the first duplicate attribute.

Proposed fix

Emit the canonical getter-derived src before caller and getter-provided attributes. This follows the canonical-attribute precedence already used for option values after #218.

Acceptance criteria

  • Rendering an Img with a duplicate caller src emits the getter value first.
  • A duplicate src returned through an initial-attribute hook also appears after the canonical getter value.
  • Existing non-src params and getter attributes remain present.
  • Existing src escaping and JawsUpdate behavior remain unchanged.
  • Add a regression test covering browser-relevant duplicate-attribute ordering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggoPull requests that update go codeseverity:low

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions