Skip to content

fix(performanceTimer): work in frames #4834

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

WilcoFiers
Copy link
Contributor

Turns out our performanceTimer errors when running in iframes. I also added some detail to gather so we could see what rule is being gathered.

@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 11:28
@WilcoFiers WilcoFiers requested a review from a team as a code owner July 22, 2025 11:28
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where the performanceTimer fails to work correctly in iframe environments and improves logging detail for rule gathering performance. The changes rename performance markers from "axe" to "audit" and enhance the gather performance log to include rule ID and node count information.

  • Renamed performance markers from mark_axe_start to mark_audit_start to fix iframe compatibility
  • Enhanced gather performance logging to include rule ID and node count for better debugging visibility

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/core/utils/performance-timer.js Updates performance marker name from 'mark_axe_start' to 'mark_audit_start' to resolve iframe issues
lib/core/base/rule.js Improves gather performance logging to include rule ID and node count with template literal formatting

Comment on lines +93 to +95
const { startTime } =
window.performance.getEntriesByName('mark_axe_start')[0] ||
window.performance.getEntriesByName('mark_audit_start')[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error is kinda making me wonder if we should rethink not having tests for this. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree; I think tests would be a good idea (especially since performanceTimer is a documented part of our API).

Comment on lines +93 to +95
const { startTime } =
window.performance.getEntriesByName('mark_axe_start')[0] ||
window.performance.getEntriesByName('mark_audit_start')[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree; I think tests would be a good idea (especially since performanceTimer is a documented part of our API).

@@ -90,11 +90,12 @@ const performanceTimer = (() => {
) {
// only output measures that were started after axe started, otherwise
// we get measures made by the page before axe ran (which is confusing)
const axeStart =
window.performance.getEntriesByName('mark_axe_start')[0];
const { startTime } =
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: A few lines up, this call is defensive about the possibility of window.performance not existing at all; should it also be a bit more defensive about the possibility of the mark_*_start events not being available (eg, assert with a meaningful message that start or auditStart must be called first)?

@@ -90,11 +90,12 @@ const performanceTimer = (() => {
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The actual functionality here feels unclear from the name/comment. For L81:

/**
 * @member {Function} logMeasures Logs previously captured measures in chronological order.
 * Starts from the most recent start()/auditStart() call.
 * @param {String|undefined} measureName If provided, will only log up to the first matching measure.
 */

const axeStart =
window.performance.getEntriesByName('mark_axe_start')[0];
const { startTime } =
window.performance.getEntriesByName('mark_axe_start')[0] ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this actually does the right thing in the event that you're in an environment with more than one mark, since we never seem to clear marks/measures out from previous runs. I think what you'd actually want here is "grab the most recent (not 0th) of each type of mark, and if both exist, use the one with later start_time)".

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.

2 participants