Skip to content

Dev toolbar's audit still freezes lazy-loaded SVG animations in Safari #18700

Closed

Description

@marcalexiei

Astro Info

Astro                    v7.4.10
Node                     v26.13.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

Safari

Describe the Bug

Follow-up to #18620:
#18621 misses <img loading="lazy">. WebKit reports a decodedBodySize of 0 for it, so the audit fetches the image again and the animation still freezes.
In the repro the eager ring now completes; the lazy one stops partway.

What's the expected result?

The animation completes

Link to Minimal Reproducible Example

https://github.com/marcalexiei/astro-dev-toolbar-svg-animation-repro

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. added
    triage: in progress
    on Nov 11, 2026
  2. astro-factory commented on Nov 11, 2026

    @astro-factory
    Contributor

    Triage complete

    • Prepare the workspace: ready
    • Install dependencies: complete
    • Build the project: complete
    • Reproduce the issue: skipped (host specific)
    • Diagnose the cause: not needed (reproduction was skipped)
    • Verify the diagnosis: not needed (reproduction was skipped)
    • Attempt a fix: not needed (reproduction was skipped)
    • Publish the result: set triage: skipped

    • Reproduced: Skipped. The bug only happens in Safari/WebKit, and the triage sandbox has no WebKit browser that will run (and its Node.js is older than the version Astro requires)
    • Exploration: Partial. I read the code but couldn't test it in a browser
    • Unit Test: No. The behavior depends on how WebKit reports resource timing and handles the animation, so a Node unit test can't show it
    • Priority: P3: minor bug. It only happens in dev, only with the dev toolbar on, only in Safari, and only with CSS-animated SVGs in a lazy-loaded <img>. Turning off the toolbar or running a production build avoids it.

    The code the issue describes is on main. getImageSize() in packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/perf.ts reads decodedBodySize from the image's Performance resource entry. If that value is 0, or the image is not complete yet, it falls back to fetch()ing the image URL again. The reporter says WebKit reports 0 for loading="lazy" images, and their repro includes a page with no Astro in it (public/fetch.html) showing that fetching the URL of an SVG that's animating freezes the animation. Their description matches the code.

    I wasn't able to find a fix, but I identified some areas that may be relevant. The fix would be in getImageSize() and the perf-use-image-component rule in perf.ts. Some options:

    • When the size can't be read from Performance entries, skip the size check instead of fetching again.
    • Try encodedBodySize or transferSize before fetching.
    • Wait for lazy images to finish loading before measuring them.
    Full Triage Report

    Issue

    Title: Dev toolbar's audit still freezes lazy-loaded SVG animations in Safari

    Environment (from reporter)

    • Astro v7.4.10, Node v26.13.0, macOS (arm64), pnpm, static output, no adapter, no integrations
    • Browser: Safari only (the reporter also reproduced it with Playwright's WebKit). Works in Chromium.

    Description

    This follows up #18620. #18621 doesn't cover <img loading="lazy">. WebKit reports a decodedBodySize of 0 for these images, so the audit fetches the image again and the animation freezes. In the repro, the eager ring now finishes but the lazy one stops partway.

    Expected: the animation completes.
    Actual: the animated SVG in <img src="/ring.svg?lazy" loading="lazy"> stops partway in Safari under astro dev when the dev toolbar is on.

    Repro: https://github.com/marcalexiei/astro-dev-toolbar-svg-animation-repro

    Repro project

    • src/pages/index.astro: two <img> tags showing a CSS-animated ring.svg. One is eager; the other is ?lazy with loading="lazy", so the two are separate requests.
    • astro.config.mjs: the toolbar can be turned off with ASTRO_DEV_TOOLBAR=off.
    • public/fetch.html: has no Astro. It fetches /ring.svg 250 ms after load, and the <img> animation freezes in WebKit.
    • Works with the toolbar off, with build && preview, and in Chromium.

    Relevant code

    packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/perf.ts:

    async function getImageSize(image: HTMLImageElement): Promise<number> {
    	if (image.complete && image.currentSrc) {
    		const entries = performance.getEntriesByName(image.currentSrc, 'resource');
    		const size = (entries.at(-1) as PerformanceResourceTiming | undefined)?.decodedBodySize;
    		if (size) return size;
    	}
    	const imageData = await fetch(image.currentSrc || image.src).then((response) => response.blob());
    	return imageData.size;
    }

    The perf-use-image-component rule (selector img:not([data-image-component])) calls this for every local image that isn't a data URI. If decodedBodySize is 0, or the image hasn't finished loading, it fetches the image again, which freezes the SVG's CSS animation in WebKit.

    Reproduction attempts

    1. Cloned the repro and linked astro to /repo/packages/astro. Install succeeded.
    2. pnpm dev --background failed: Node.js v22.23.2 is not supported by Astro! Please upgrade Node.js to a supported version: ">=22.23.4".
    3. agent-browser isn't installed. The Playwright WebKit binary is there but won't start because system libraries are missing (gstreamer, gtk-4, pango, cairo, harfbuzz, …).

    Result

    Skipped. This depends on Safari/WebKit, which can't run in the sandbox. The report is detailed, matches the current code, and includes a WebKit demo with no Astro in it.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  3. added
    triage: skipped
    and removed
    triage: in progress
    on Nov 11, 2026
  4. matthewp commented on Nov 17, 2026

    @matthewp
    Contributor

    The fix is in getImageSize() in packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/perf.ts: the audit should never fetch an image the page is displaying. The fetch() fallback left by #18621 is the root cause. Any case that reaches it (a lazy image that isn't loaded yet, or WebKit reporting decodedBodySize as 0) freezes the animation, and for a lazy image it also forces a download the page deliberately put off.

    • If the image isn't loaded yet (!image.complete), wait for its load event before measuring. Don't fetch it.
    • Read the size from the image's resource timing entry: try decodedBodySize, then encodedBodySize, then transferSize.
    • If none of them gives a size, skip the size check for that image (don't report it) rather than fetching.
    • Remove the fetch() fallback entirely. This applies to both rules that use getImageSize() (perf-use-image-component and perf-use-videos).

    You can't run WebKit, but you can still check this in the existing Chromium e2e test (packages/astro/e2e/dev-toolbar-audits.test.ts). Record the network requests and assert that opening the Audit app makes no extra request for an eager image or a loading="lazy" image. Also check that a large image is still reported once it has loaded.

  5. added
    triage: needs triage
    and removed
    triage: skipped
    on Nov 17, 2026
  6. matthewp commented on Nov 17, 2026

    @matthewp
    Contributor

    Bot please triage again based on this new information.

  7. added
    triage: in progress
    and removed
    triage: needs triage
    on Nov 17, 2026
  8. astro-factory commented on Nov 17, 2026

    @astro-factory
    Contributor

    Triage complete

    • Prepare the workspace: ready
    • Install dependencies: complete
    • Build the project: complete
    • Reproduce the issue: confirmed
    • Diagnose the cause: high confidence
    • Verify the diagnosis: bug
    • Attempt a fix: verified
    • Publish the result: set triage: fix pending

    • Reproduced: Yes. The lazy ring freezes in WebKit (Playwright) with the toolbar on. The toolbar's audit also fetches a not-yet-loaded lazy image in Chromium.
    • Exploration: Yes. View branch
    • Unit Test: No. getImageSize() is a private, browser-only helper, so I added an e2e test instead: packages/astro/e2e/dev-toolbar-audits.test.ts ("does not fetch a lazy image to read its size").
    • Priority: P3: minor bug. It only happens in dev, with the toolbar on, in Safari, with CSS-animated SVGs in lazy <img> tags. Turning off the toolbar or using a production build avoids it.

    getImageSize() in packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/perf.ts falls back to fetch() in two cases. One is when the image's resource timing size is 0: WebKit reports decodedBodySize, encodedBodySize and transferSize all as 0 for a loading="lazy" <img>. The other is when the image isn't complete yet. Fetching the URL of an SVG that's animating freezes the animation in WebKit, and fetching an unloaded lazy image downloads it before the page needs it. The audit runs when the toolbar starts up, so this happens even if the Audit app is never opened.

    I found a potential fix for this issue. It needs human review.

    • The fetch() fallback is removed. The size comes from decodedBodySize || encodedBodySize || transferSize; if there's no size, the size check is skipped and the image isn't reported.
    • Eager images that are still loading are waited on.
    • This part differs from @matthewp's suggestion: an unloaded loading="lazy" image is skipped instead of waited on. The audit's lint() awaits each rule's match() one after another. I tried waiting for load, and a lazy image below the fold blocked the whole audit: no highlights appeared until the user scrolled to it.

    Try this fix

    You can test this fix right now without waiting for a release:

    # astro
    npm i https://pkg.pr.new/astro@4287faa

    If this fixes your issue, please leave a comment letting us know (for example
    "confirmed, this fixes it"). A pull request will then be opened to get it merged.

    Full Triage Report

    Issue

    Dev toolbar's audit still freezes lazy-loaded SVG animations in Safari (follow-up to #18620 / #18621)

    Reproduction

    Setup notes:

    • The sandbox runs Node 22.23.2, but bin/astro.mjs requires 22.23.4 or later. I started the dev server through the programmatic dev() API instead.
    • I installed Playwright Chromium, Chrome and WebKit, with their system dependencies.

    Steps:

    1. Clone the repro and link astro to the workspace build.
    2. Load / in WebKit, record every request for ring.svg and dump each image's resource timing entries.
    3. Screenshot both rings 3 s after load and count the orange pixels (a fully drawn ring is 6631).

    Results:

    Case Requests Lazy ring
    WebKit, toolbar on /ring.svg?lazy requested as image, then again as fetch (the audit) 4345 px (frozen)
    WebKit, toolbar off image requests only 6631 px
    • In WebKit, the lazy <img> resource entry is {decodedBodySize: 0, encodedBodySize: 0, transferSize: 0}. The eager one is 742/742/1042.
    • Chromium on /: both images are loaded with real sizes, and nothing is fetched again.
    • On an added /below-fold page (a lazy image under a 10000px spacer), the image isn't complete. The audit fetches it in both Chromium and WebKit, and that fetch is the only request for it.

    Diagnosis (confidence: high)

    getImageSize() (perf.ts, lines 6–19) is used by perf-use-image-component (20KB threshold) and perf-use-videos (100KB threshold). Before the fix:

    if (image.complete && image.currentSrc) {
    	const entries = performance.getEntriesByName(image.currentSrc, 'resource');
    	const size = (entries.at(-1) as PerformanceResourceTiming | undefined)?.decodedBodySize;
    	if (size) return size;
    }
    const imageData = await fetch(image.currentSrc || image.src).then((response) => response.blob());

    Whenever the size is 0 (WebKit lazy images) or the image isn't complete (unloaded lazy images), this falls back to fetch(). The audit runs during the Audit app's init() (apps/audit/index.ts, await run()), on page load.

    Verification

    Verdict: bug (confidence: high). #18621 set out to stop fetching displayed images again, but missed lazy images. There's no comment or test showing that case was considered. The maintainer also identified the fetch() fallback as the root cause.

    Fix

    • perf.ts: getImageSize() never fetches.
      • An eager image that isn't complete is waited on (load or error).
      • An unloaded loading="lazy" image returns 0.
      • Otherwise it returns decodedBodySize || encodedBodySize || transferSize || 0 from the latest resource entry.
      • A result of 0 is below both callers' thresholds, so the image is skipped and the call sites are unchanged.
    • New fixture e2e/fixtures/dev-toolbar/src/pages/audits-perf-lazy-image.astro: a large raw lazy image above the fold, and one below the fold.
    • New e2e test: opening the Audit app makes no fetch request for /the-future.jpg*, and exactly one perf-use-image-component highlight appears (for the loaded image above the fold). The existing test "does not fetch a loaded image again to read its size" still covers the eager case: the large image is still reported and not fetched.
    • Changeset .changeset/lazy-image-audit-fetch.md (astro: patch).

    Why lazy images aren't waited on: waiting for load on every incomplete image made the new test fail with 0 highlights. lint() awaits rule matches one after another, so a lazy image that never loads blocks every rule after it. The original code also stalled on this page: it fetched the image, matched it, and then createAuditProblem() waited for its load.

    Tradeoffs:

    • An unloaded lazy image isn't size-checked until the audit runs again. It re-runs on DOM mutations, not on image load.
    • WebKit reports zero sizes for lazy images, so Safari never shows perf-use-image-component for them.

    Verification:

    • WebKit, repro page: no fetches; both rings 6631/6631 px.
    • /below-fold in Chromium and WebKit: no requests.
    • dev-toolbar-audits.test.ts: 15/15 pass in Chrome Stable. The new test fails on the original code.
    • Biome is clean and the build has 0 errors.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  9. added
    - P3: minor bug
    pkg: astro
    triage: fix pending
    and removed
    triage: in progress
    on Nov 17, 2026
  10. matthewp commented on Nov 17, 2026

    @matthewp
    Contributor

    Bot, this fixes it

  11. added
    triage: fix verified
    and removed
    triage: fix pending
    on Nov 17, 2026
  12. astro-factory commented on Nov 17, 2026

    @astro-factory
    Contributor

    The fix has been verified! A pull request has been created: #18771

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

Metadata

Metadata

Assignees

Labels

- P3: minor bugpkg: astrotriage: fix verified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions