From 1d42b380c25fe1bbd8396344a6eeb02054b959bd Mon Sep 17 00:00:00 2001 From: Princesseuh <3019731+Princesseuh@users.noreply.github.com> Date: Thu, 29 Feb 2024 19:09:59 +0100 Subject: [PATCH] fix(audits): Don't warn about loading on data URIs --- .changeset/warm-buttons-agree.md | 5 +++++ .../astro/src/runtime/client/dev-toolbar/apps/audit/perf.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/warm-buttons-agree.md diff --git a/.changeset/warm-buttons-agree.md b/.changeset/warm-buttons-agree.md new file mode 100644 index 000000000000..9186f02828a2 --- /dev/null +++ b/.changeset/warm-buttons-agree.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes dev toolbar warning about using the proper loading attributes on images using `data:` URIs diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/perf.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/perf.ts index 197553a25fc7..4b67fcbf5575 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/perf.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/perf.ts @@ -38,6 +38,9 @@ export const perf: AuditRuleWithSelector[] = [ // Ignore elements that are above the fold, they should be loaded eagerly if (htmlElement.offsetTop < window.innerHeight) return false; + // Ignore elements using `data:` URI, the `loading` attribute doesn't do anything for these + if (htmlElement.src.startsWith('data:')) return false; + return true; }, }, @@ -53,6 +56,9 @@ export const perf: AuditRuleWithSelector[] = [ // Ignore elements that are below the fold, they should be loaded lazily if (htmlElement.offsetTop > window.innerHeight) return false; + // Ignore elements using `data:` URI, the `loading` attribute doesn't do anything for these + if (htmlElement.src.startsWith('data:')) return false; + return true; }, },