Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0: Only audit nodes that have changed #8

Merged
merged 3 commits into from
Nov 30, 2019
Merged

2.0.0: Only audit nodes that have changed #8

merged 3 commits into from
Nov 30, 2019

Conversation

jul-sh
Copy link
Collaborator

@jul-sh jul-sh commented Nov 29, 2019

Previously agnostic-axe would audit the whole observed node (usually the document) if a part of it changed. For larger pages this would be quite an intense operation, so audits were debounced for performance.

This version now only audits the individual parts that have changed. Each node passed by the MutationObserver is audited individually. This means we have smaller chunks of work that better fit into the browsers idle period. In addition, less content has to be audited.

To make this happen, this adds the AuditQueue class, which keeps a queue of pending audits and executes them during idle periods. Debouncing options have been removed. Audits are run as soon as the browser has idle time.

Comment on lines +38 to +42
this._mutationObserver = new window.MutationObserver(mutationRecords => {
mutationRecords.forEach(mutationRecord => {
this._auditNode(mutationRecord.target)
})
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Audit each mutated node individually

if (!targetNode) {
throw new Error('AxeObserver.observe requires a targetNode')
}

const scheduleAudit = debounce(
() => requestIdleCallback(() => this._auditTargetNode(targetNode)),
Copy link
Collaborator Author

@jul-sh jul-sh Nov 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the debounced function fired, we also scheduled the whole node audit via requestIdleCallback. While the audit was started during an idle period, it would often take several hundred ms to run. Hence the requestIdleCallback wasn't that useful, since the work would continue way past the actual idle period.

In the new version, smaller chunks of work are used. They get executed for only as long as the idle period lasts.

@jul-sh jul-sh merged commit f5d9c60 into master Nov 30, 2019
@jul-sh jul-sh deleted the audit-queue branch November 30, 2019 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant