From b92d35f1026f3e99abb888d1a845bdda4efdc327 Mon Sep 17 00:00:00 2001 From: Ming-jun Lu <40516784+mingjunlu@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:22:05 +0800 Subject: [PATCH] Fix an issue where audit fails to initialize when encountered `` inside `` (#10163) * Fix an issue where audit fails to initialize when encountered `` inside `` * Add changeset --- .changeset/spotty-cobras-warn.md | 5 +++++ .../astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/spotty-cobras-warn.md diff --git a/.changeset/spotty-cobras-warn.md b/.changeset/spotty-cobras-warn.md new file mode 100644 index 0000000000..26fc9e537d --- /dev/null +++ b/.changeset/spotty-cobras-warn.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where audit fails to initialize when encountered `` inside `` diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts index 3bd296589f..45b94b31f6 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts @@ -338,8 +338,8 @@ export const a11y: AuditRuleWithSelector[] = [ selector: a11y_required_content.join(','), match(element: HTMLElement) { // innerText is used to ignore hidden text - const innerText = element.innerText.trim(); - if (innerText !== '') return false; + const innerText = element.innerText?.trim(); + if (innerText && innerText !== '') return false; // Check for aria-label const ariaLabel = element.getAttribute('aria-label')?.trim();