Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(a11y): keep duplicate research errors passive (#5206)

LearningCircuitbc1f5d16147b
diff --git a/changelog.d/+single-live-research-error.bugfix.md b/changelog.d/+single-live-research-error.bugfix.md
new file mode 100644
index 0000000000..6c435d7339
--- /dev/null
+++ b/changelog.d/+single-live-research-error.bugfix.md
@@ -0,0 +1,3 @@
+Field-specific research submission errors now use a single live-region
+announcement while retaining passive visual copies beside the submit button
+and affected field, avoiding possible duplicate screen-reader announcements.
diff --git a/src/local_deep_research/web/static/js/components/research.js b/src/local_deep_research/web/static/js/components/research.js
index f5ed074584..497f34d4ce 100644
--- a/src/local_deep_research/web/static/js/components/research.js
+++ b/src/local_deep_research/web/static/js/components/research.js
@@ -2780,12 +2780,23 @@
*/
function showAlert(message, type = 'info') {
// Use centralized security utility for alerts with auto-hide functionality
- window.showSafeAlert('research-alert', message, type);
+ // Keep the live parent in the accessibility tree before its
+ // passive child is appended so assistive technology observes the
+ // content change inside an already-exposed alert region.
+ const alertContainer = document.getElementById('research-alert');
+ if (alertContainer) {
+ alertContainer.style.display = 'block';
+ }
+ window.showSafeAlert(
+ 'research-alert',
+ message,
+ type,
+ { announce: false }
+ );
// Mark the alert as submit-owned so clearSubmitAlerts() can
// remove it on the next attempt or when the user changes the
// implicated setting. Unrelated danger alerts (e.g. a settings
// page warning) are not tagged and therefore survive.
- const alertContainer = document.getElementById('research-alert');
if (alertContainer) {
const alertEl = alertContainer.querySelector('.alert');
if (alertEl) {
@@ -2833,8 +2844,9 @@
* #research-alert (which is the live ``role="alert"`` announcement).
* The child .alert element has its ``role``/``aria-atomic``
* attributes stripped, and the parent #research-error-alert has no
- * ``role``/``aria-live`` either, so the duplicate is completely
- * non-live and screen readers will not announce the error twice.
+ * ``role``/``aria-live`` either. Field-specific inline copies are also
+ * rendered without a live-region attribute because the top alert has
+ * already announced the same message.
*
* @param {string} message - The user-facing error text.
* @param {string|null} fieldName - Optional form field id to flag
@@ -2846,12 +2858,14 @@
// before the user clicks submit again).
const errorContainer = document.getElementById('research-error-alert');
if (errorContainer) {
- window.showSafeAlert('research-error-alert', message, 'error');
+ window.showSafeAlert(
+ 'research-error-alert',
+ message,
+ 'error',
+ { announce: false }
+ );
const alertEl = errorContainer.querySelector('.alert');
if (alertEl) {
- // Make the duplicate copy non-live to prevent double-announcement.
- alertEl.removeAttribute('role');
- alertEl.removeAttribute('aria-atomic');
// Mark as submit-owned so clearSubmitAlerts() can
// remove it on the next attempt or when the user
// changes the implicated setting. Unrelated alerts
@@ -2881,7 +2895,11 @@
const fieldEl = document.getElementById(fieldName);
if (fieldEl) {
try {
- researchValidator.showError(fieldEl, message);
+ researchValidator.showError(
+ fieldEl,
+ message,
+ { announce: false }
+ );
} catch (_e) { /* defensive: never let error UX break the form */ }
// If the field is in the (collapsed) Advanced Options
// panel, reveal it so the user can see both the alert and
diff --git a/src/local_deep_research/web/static/js/security/xss-protection.js b/src/local_deep_research/web/static/js/security/xss-protection.js
index 9643554efa..1b3bd90432 100644
--- a/src/local_deep_research/web/static/js/security/xss-protection.js
+++ b/src/local_deep_research/web/static/js/security/xss-protection.js
@@ -229,14 +229,19 @@ function safeSetTextContent(element, content) {
* Create a safe alert message element
* @param {string} message - The alert message (will be escaped)
* @param {string} type - Alert type (success, error, warning, info)
+ * @param {Object|null} [options] - Alert behavior options
+ * @param {boolean} [options.announce=true] - Whether to expose the element
+ * as an assertive live alert
* @returns {Element} - The created alert element
*/
-function createSafeAlertElement(message, type = 'info') {
+function createSafeAlertElement(message, type = 'info', options = {}) {
const alert = document.createElement('div');
const alertType = window.LdrAlertHelpers.mapAlertType(type);
alert.className = `alert alert-${alertType}`;
- alert.setAttribute('role', 'alert');
- alert.setAttribute('aria-atomic', 'true');
+ if (options?.announce !== false) {
+ alert.setAttribute('role', 'alert');
+ alert.setAttribute('aria-atomic', 'true');
+ }
// Create icon
const iconMap = {
@@ -438,8 +443,10 @@ function sanitizeUserInput(input, options = {}) {
* @param {string} containerId - ID of the alert container
* @param {string} message - Alert message (will be sanitized)
* @param {string} type - Alert type (success, error, warning, info)
+ * @param {Object|null} [options] - Alert behavior options passed to
+ * createSafeAlertElement
*/
- function showSafeAlert(containerId, message, type = 'info') {
+ function showSafeAlert(containerId, message, type = 'info', options = {}) {
const alertContainer = document.getElementById(containerId);
if (!alertContainer) return;
@@ -449,7 +456,7 @@ function sanitizeUserInput(input, options = {}) {
}
// Create alert using our secure method
- const alert = createSafeAlertElement(message, type);
+ const alert = createSafeAlertElement(message, type, options);
alertContainer.appendChild(alert);
alertContainer.style.display = 'block';
}
diff --git a/src/local_deep_research/web/static/js/utils/form-validation.js b/src/local_deep_research/web/static/js/utils/form-validation.js
index 95a4a7ed9e..e29f8a5fdd 100644
--- a/src/local_deep_research/web/static/js/utils/form-validation.js
+++ b/src/local_deep_research/web/static/js/utils/form-validation.js
@@ -83,6 +83,7 @@
element.classList.add('ldr-field-invalid');
element.setAttribute('aria-invalid', 'true');
if (errorElement) {
+ errorElement.setAttribute('aria-live', 'polite');
errorElement.textContent = errorMessage;
errorElement.style.display = 'block';
}
@@ -151,8 +152,11 @@
* Show error on a specific field
* @param {HTMLElement|string} field - Field element or selector
* @param {string} message - Error message to display
+ * @param {Object} [options] - Display options
+ * @param {boolean} [options.announce=true] - Whether the inline error
+ * should be exposed as a polite live-region update
*/
- showError(field, message) {
+ showError(field, message, { announce = true } = {}) {
const element = typeof field === 'string' ? document.querySelector(field) : field;
if (!element) return;
@@ -160,6 +164,13 @@
element.classList.add('ldr-field-invalid');
element.setAttribute('aria-invalid', 'true');
if (errorElement) {
+ // Set live-region behavior before changing the text so
+ // assistive technologies observe only the intended update.
+ if (announce) {
+ errorElement.setAttribute('aria-live', 'polite');
+ } else {
+ errorElement.removeAttribute('aria-live');
+ }
errorElement.textContent = message;
errorElement.style.display = 'block';
}
diff --git a/tests/js/components/research.test.js b/tests/js/components/research.test.js
index 0a28aa4f0d..83e6a8984a 100644
--- a/tests/js/components/research.test.js
+++ b/tests/js/components/research.test.js
@@ -366,14 +366,28 @@ describe('research form — egress-scope denial UX', () => {
expect(fieldErr.textContent).toBe('');
});
- it('ensures the anchored alert copy is completely non-live so screen readers do not announce the error twice', async () => {
+ it('keeps visual duplicates passive so only the top alert announces the error', async () => {
// The top #research-alert is the live ``role="alert"`` and scrolls
- // into view; the anchored #research-error-alert is a visual
- // duplicate only — announcing it twice would be noisy for AT users.
+ // into view; the anchored and inline field errors are visual
+ // duplicates only.
+ const topContainer = document.getElementById('research-alert');
+ const originalAppendChild = topContainer.appendChild.bind(topContainer);
+ let displayAtInsertion;
+ vi.spyOn(topContainer, 'appendChild').mockImplementation((child) => {
+ displayAtInsertion = topContainer.style.display;
+ return originalAppendChild(child);
+ });
+
stubEgressDenial('Search engine blocked by Egress Scope.');
submitForm();
await flush();
+ expect(displayAtInsertion).toBe('block');
+ expect(topContainer.getAttribute('role')).toBe('alert');
+ const topAlert = topContainer.querySelector('.alert');
+ expect(topAlert.getAttribute('role')).toBeNull();
+ expect(topAlert.getAttribute('aria-atomic')).toBeNull();
+
const anchored = document.getElementById('research-error-alert');
expect(anchored.getAttribute('role')).toBeNull();
expect(anchored.getAttribute('aria-live')).toBeNull();
@@ -382,6 +396,12 @@ describe('research form — egress-scope denial UX', () => {
expect(childAlert).not.toBeNull();
expect(childAlert.getAttribute('role')).toBeNull();
expect(childAlert.getAttribute('aria-atomic')).toBeNull();
+
+ const inlineError = document.getElementById(
+ 'policy_egress_scope-error'
+ );
+ expect(inlineError.textContent).toContain('Egress Scope');
+ expect(inlineError.getAttribute('aria-live')).toBeNull();
});
it('preserves an unrelated (non-egress) danger alert when clearEgressError is called', () => {
diff --git a/tests/js/security/xss-protection.test.js b/tests/js/security/xss-protection.test.js
index d15c5614ce..93c6c1bcc6 100644
--- a/tests/js/security/xss-protection.test.js
+++ b/tests/js/security/xss-protection.test.js
@@ -4,11 +4,13 @@
* Tests HTML escaping, sanitization, and safe DOM manipulation
* functions that protect against XSS attacks.
*/
+import '@js/utils/alert-helpers.js';
import '@js/security/xss-protection.js';
const { escapeHtml, escapeHtmlAttribute, sanitizeUserInput,
- safeSetInnerHTML, safeSetTextContent } = window;
+ safeSetInnerHTML, safeSetTextContent, createSafeAlertElement,
+ showSafeAlert } = window;
describe('escapeHtml', () => {
it('escapes ampersands', () => {
@@ -174,6 +176,54 @@ describe('safeSetTextContent', () => {
});
});
+describe('safe alert rendering', () => {
+ let container;
+
+ beforeEach(() => {
+ container = document.createElement('div');
+ container.id = 'safe-alert-test';
+ document.body.appendChild(container);
+ });
+
+ afterEach(() => {
+ container.remove();
+ });
+
+ it('preserves assertive alert semantics by default', () => {
+ const alert = createSafeAlertElement('Important', 'error');
+ expect(alert.getAttribute('role')).toBe('alert');
+ expect(alert.getAttribute('aria-atomic')).toBe('true');
+ });
+
+ it('inserts passive alerts without ever appending a live child', () => {
+ const originalAppendChild = container.appendChild.bind(container);
+ let roleAtInsertion;
+ let atomicAtInsertion;
+ vi.spyOn(container, 'appendChild').mockImplementation((child) => {
+ roleAtInsertion = child.getAttribute('role');
+ atomicAtInsertion = child.getAttribute('aria-atomic');
+ return originalAppendChild(child);
+ });
+
+ showSafeAlert(
+ 'safe-alert-test',
+ 'Passive copy',
+ 'error',
+ { announce: false }
+ );
+
+ expect(roleAtInsertion).toBeNull();
+ expect(atomicAtInsertion).toBeNull();
+ expect(container.firstElementChild.getAttribute('role')).toBeNull();
+ expect(container.textContent).toContain('Passive copy');
+ });
+
+ it('tolerates a null options argument and keeps default semantics', () => {
+ const alert = createSafeAlertElement('Important', 'error', null);
+ expect(alert.getAttribute('role')).toBe('alert');
+ });
+});
+
describe('escapeHtml fuzz / property tests', () => {
// The most critical security invariant: after escapeHtml, the result
// should never contain raw <, >, or unescaped quotes that could break
diff --git a/tests/js/utils/form-validation.test.js b/tests/js/utils/form-validation.test.js
index c00ac8a649..9adc37f458 100644
--- a/tests/js/utils/form-validation.test.js
+++ b/tests/js/utils/form-validation.test.js
@@ -180,6 +180,28 @@ describe('FormValidator', () => {
expect(input.getAttribute('aria-invalid')).toBe('true');
const errorEl = document.getElementById('test-field-error');
expect(errorEl.textContent).toBe('Custom error');
+ expect(errorEl.getAttribute('aria-live')).toBe('polite');
+ });
+
+ it('can render a passive inline copy when another live region announces it', () => {
+ validator.addValidation(input, () => null);
+ validator.showError(input, 'Custom error', { announce: false });
+
+ const errorEl = document.getElementById('test-field-error');
+ expect(errorEl.textContent).toBe('Custom error');
+ expect(errorEl.getAttribute('aria-live')).toBeNull();
+
+ // A later ordinary validation error must restore the default
+ // polite announcement behavior.
+ validator.addValidation(input, () => 'Validated error');
+ validator.validateField(input);
+ expect(errorEl.textContent).toBe('Validated error');
+ expect(errorEl.getAttribute('aria-live')).toBe('polite');
+ // The default showError path also restores polite semantics.
+ validator.showError(input, 'Passive again', { announce: false });
+ validator.showError(input, 'Ordinary error');
+ expect(errorEl.textContent).toBe('Ordinary error');
+ expect(errorEl.getAttribute('aria-live')).toBe('polite');
});
it('accepts selector string', () => {