Skip to content

Conversation

@mattscepter
Copy link
Collaborator

<< Describe the changes >>

Closes:

Copy link

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 reorders operations in the getSource function to remove Percy data attributes from the source HTML before truncation, preventing these unwanted attributes from appearing in the final output if truncation occurs at a point that would otherwise preserve them.

Changes:

  • Modified the order of operations to apply regex filtering before truncation instead of after

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const regex = /\s*data-percy-[^=]+="[^"]*"/g;
htmlString = htmlString.replace(regex, '');
const regex = /\s*data-percy-[^=]+="[^"]*"/g; // Remove unwanted attributes
source = source.replace(regex, '');
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

This will throw a TypeError if source is null or undefined. The replace operation should be performed after ensuring source has a value, or use optional chaining: source = (source || '').replace(regex, '')

Suggested change
source = source.replace(regex, '');
source = (source || '').replace(regex, '');

Copilot uses AI. Check for mistakes.
Copy link

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

htmlString = htmlString.replace(regex, '');
const regex = /\s*data-percy-[^=]+="[^"]*"/g; // Remove unwanted attributes
source = (source || '').replace(regex, '');
const htmlString = truncate(source || '');
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The parameter passed to truncate is source || '', but this is redundant since source was already ensured to be a string on line 179 where it was assigned the result of (source || '').replace(regex, ''). If source was falsy before line 179, it's now an empty string, so the || '' fallback in line 180 is unnecessary.

Suggested change
const htmlString = truncate(source || '');
const htmlString = truncate(source);

Copilot uses AI. Check for mistakes.
@Abhi3685 Abhi3685 merged commit 13fbd82 into main Feb 3, 2026
10 of 11 checks passed
@Abhi3685 Abhi3685 deleted the AXE-2796-html-generation-fix branch February 3, 2026 05:08
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.

3 participants