-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
this._mutationObserver = new window.MutationObserver(mutationRecords => { | ||
mutationRecords.forEach(mutationRecord => { | ||
this._auditNode(mutationRecord.target) | ||
}) | ||
}) |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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.
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.