Late img source completion overwrites the image from a newer src

Open
#1,610 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
frontend, web-dev

Research direction

Start by tracing load_image and how pending_images subscribers are registered and applied when a NetHandler completes; reproduce the A→B sequence in the issue with a queued NetProvider. Check how any change handles shared requests and A→B→A before settling on a fix. Done means late A completion leaves B displayed; verify by painting and checking the pixel at (50, 50).

Written by the indexing model from the issue text.

Description

A-Images A-Net C-Bug

Reproduced on unpatched Blitz main 81b48968474614b28364a452af6d4d0ecedcf6a1 (2026-11-16), Windows x64, with the upstream Cargo.lock and nightly-2026-11-14. Our downstream integration is pinned to 0.3.0-beta.4, but the observations below are from a separate checkout of main.

After an <img> changes from A to B, B can finish and be displayed correctly, then a late completion of A replaces it even though the current src still names B.

Reproduction
<style>body { margin: 0 } img { width: 100px; height: 100px }</style>
<img id="pic" src="a.png">

Use a NetProvider that queues requests and their real NetHandler objects, rather than completing them immediately:

  1. Parse/resolve the document; keep A pending.
  2. Set #pic's src to b.png through DocumentMutator::set_attribute, then resolve.
  3. Complete B with a valid 1×1 opaque-blue PNG, resolve and paint.
  4. Complete A with a valid 1×1 opaque-red PNG, resolve and paint again.

With anyrender_vello_cpu::VelloCpuImageRenderer, the pixel at (50, 50) in a 100×100 output is:

after B:      [0, 0, 255, 255]
after late A: [255, 0, 0, 255]

Expected: the pixel remains blue after B has become the current image. The stale A completion should not replace it. This report does not require immediately clearing an already displayed image when src changes; the current/pending request distinction is described by HTML's image update algorithm.

The probe passes encoded PNG bytes through the actual handlers and paints the document; it does not inject a fabricated image into the DOM cache. In main, load_image registers the new URL, but the old URL's pending_images subscriber can still contain this node. Its late completion consequently reaches the same node.

I checked #1221 (unused image-cache eviction) and #1587 (external SVG images); neither appears to address this stale <img> completion.

Local implementation sketch

I am not very familiar with Rust, so these snippets are provided only as reference sketches from our local integration, not as an upstream-ready fix.

Our beta.4 integration removes the node's previous ordinary-image subscriptions before registering the new source:

for waiting in self.doc.pending_images.values_mut() {
    waiting.retain(|(id, kind)| {
        *id != target_id || !matches!(kind, ImageType::Image)
    });
}

This is only the subscription-cleanup portion of the local patch. It deliberately leaves other nodes subscribed to the same URL and does not cancel their shared fetch. I have omitted our separate display-clearing code because it should not be treated as a proposal for browser current/pending-image behavior.

An upstream fix may instead validate request/source identity when applying a completion. This excerpt has not been validated as a complete main-branch fix, including A→B→A, shared requests, SVG images and cancellation; the verified failure here is the two-source out-of-order completion above.

Dominant language
Rust
Stars
4.5k
Forks
281
Avg merge
6h 6m
Merged PRs (30d)
184

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DioxusLabs/blitz

All issues in DioxusLabs/blitz

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.